Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  newbie question (sort of)  (Read 2909 times)
0 Members and 1 Guest are viewing this topic.
Offline verence

Senior Newbie




let there be rok.


« Posted 2003-12-21 01:52:44 »

hi there,

this is my first post here, so hi there Smiley.

i'm working with java for some years (server & normal gui apps), did some c++ gaming stuff (mostly 3d, using opengl, irrlicht).

since i want to learn java2d and game programming (2d) in java in general, i started with a very simple experiment: a scrolling background. the render loop looks like this:

1  
2  
3  
4  
5  
6  
7  
Graphics g;
for (int i = 0; i < 1000; i++) {                  
    g = (Graphics) strategy.getDrawGraphics();    
    g.drawImage(img, 0, 0, 640, 480, i, 0, i + 640, 480, null);    
    g.dispose();                              
    strategy.show();
}


it runs very slow. i use a java.awt.Window with a size of 640x480. what am i wrong about?

the second thing i want to ask:
what is (in general) a good way or technique to do these image stuff (scrolling and drawing sprites)? i do not want to use a third-party api like gage cos i want to learn how it works Smiley.

ok, cu,
verence
Offline GergisKhan

Junior Member




&quot;C8 H10 N4 O2&quot;


« Reply #1 - Posted 2003-12-21 20:54:57 »

Hi there, and welcome!

(to those who've been wondering: recent turmoil in my personal life, including moving to a new state and such, prevented my posting till recently.)

One thing of note is that you're using an AWT window, and that will tend to cause some slowdown.  There are some game loops you should look at in the 'Shared Code' forum that may be of use.  See:


http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=share;action=display;num=1036252001

gK

"Go.  Teach them not to mess with us."
          -- Cao Cao, Dynasty Warriors 3
Offline nonnus29

Senior Member




Giving Java a second chance after ludumdare fiasco


« Reply #2 - Posted 2003-12-21 23:04:21 »

This is a good resource too:

Its probably the same thing actually

Welcome back Gerghis!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline verence

Senior Newbie




let there be rok.


« Reply #3 - Posted 2003-12-22 12:21:24 »

Quote
This is a good resource too:
Its probably the same thing actually

actually i'm doing nearly the same in my little experiment (i took a look around here before i did post Wink). i was just wondering about scrolling a big background image around, which seemed a bit slow to me. hm, maybe i should use tiles for the background also. i was maybe expecting too much concerning speed Smiley. i did a small j'n'r game ages ago in pascal on a 386dx40 in 320x200 and the background scrolling was very fast, but that was done by directly modifying the linear vga memory (mode13, $0a000 and y*320+x, these things i won't forget for a lifetime Smiley).

as a start i wanted to create a similar game using my native tongue, because j'n'r games are so damn addictive Smiley.

greets
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #4 - Posted 2003-12-22 12:45:55 »

Whats the size of your background image (kb)? Reducing the size of the image file or tweaking the Image loading could help.

Kommi
Offline verence

Senior Newbie




let there be rok.


« Reply #5 - Posted 2003-12-22 13:31:49 »

Quote
Whats the size of your background image (kb)? Reducing the size of the image file or tweaking the Image loading could help.

it's a 30kb jpeg. but doesn't java convert it into it's own data format when it's loaded? and what do you mean by "tweaking the image loading"? i use getResourceAsStream() and a MediaTracker, but the loading time does not matter (display a fancy progress bar and the player is content Smiley).

greets
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Reply #6 - Posted 2003-12-22 19:10:46 »

Try http://wiki.java.net/bin/view/Games/LoadingSpritesWithImageIO for better image loading. Also see if you can make the image file size smaller. There was a difference for me displaying a few 20 kb tiles and a few 10 kb tiles 85 frames a second. Also g.darwImage() is the way to draw it but the type of image you have (volatile, automatic, buffered) and weather your app is windowed or fullscreen makes all the difference.
Other things to think about: if your game is in a window then you cannot do page flipping or blitting, so your game will have performance problems.

Kommi
Offline Jeff

JGO Coder




Got any cats?


« Reply #7 - Posted 2003-12-23 01:11:57 »

Well if you are running with the Sun VM, try it with -Xcompile and see if that helps. if so then what you are seeing is the initial uncompiled code and aren't running it long enough to see the compiled execution.  (-Xcompile forces it to compile right away)

Also, I see you are using absolute sizes, not your image size, in your BLT.  If you are trying to scale each time you BLT that will slow you down a lot.  Pre-scale the image into a new image thats the right size and do an unscaled BLT on each update.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline DD.Jarod

Senior Newbie




Sry for my bad english :-)


« Reply #8 - Posted 2003-12-26 12:24:16 »

Quote
Other things to think about: if your game is in a window then you cannot do page flipping or blitting, so your game will have performance problems.


Sure about that?
If u make a BufferStrategy with BufferCapabilities like this for pageblitting:
1  
2  
3  
BufferCaps = new BufferCapabilities(new ImageCapabilities(true),
                                                                                                                                                                                                              new ImageCapabilities(true),
                                                                                                                                                                                                              null);

flipContents - the contents of the back buffer after page-flipping, null if page flipping is not used

this works with windowed frames or what else u use, exclusiv fullscreen is just needed if u use a pageflipping strategy for flipContents.
Offline Jeff

JGO Coder




Got any cats?


« Reply #9 - Posted 2003-12-28 02:41:01 »

Frame flipping is almost the same for windows or full screen in Java and you can do it with either.

If you flip frames for a window, then flipping is done with an (unsynchronized on Win32) BLT to the screen.  If you flip frames in full screen then its done with video page flipping and may be scan synchronized depending on video driver settings and behavior.

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Jeff

JGO Coder




Got any cats?


« Reply #10 - Posted 2003-12-28 02:43:13 »

Btw. the word "you" is spelled with 3 letters.

In general "kewl-dewd-speak" just annoys people here as its childish and hard to read.  

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline kevglass

JGO Kernel


Medals: 122
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #11 - Posted 2003-12-28 08:06:04 »

*Meow* Smiley

u doodz need 2 lern 2 spk dood. lol.

Kev

PS. Obviously I do too.

Offline DD.Jarod

Senior Newbie




Sry for my bad english :-)


« Reply #12 - Posted 2003-12-28 12:06:44 »

K, I will stop writing as if I am chat with friends in a MMORPG, will be more simply to read for the normal ones :-)

Quote
If you flip frames for a window, then flipping is done with an (unsynchronized on Win32) BLT to the screen.  If you flip frames in full screen then its done with video page flipping [...]

if you make your bufferstrategy with
createBufferStrategy(2)
then it will be done like that, but furthermore you can create the bufferstrategy with
createBufferStrategy(2, BufferCapabilities)
then you can select between page flipping and page blitting.

If we are already at Hardwarefeatures, which methods from Graphics2D (got with createGraphics from a BufferedImage which was got with createCompatibleImage) are Hardwareaccelerated?
All of them or only drawImage(). And if only drawImage is accelerated, what happens if I call (e.g.) drawLine()?
Is the line drawn on the BufferedImage in the VRAM, or is the (BufferedImage in) VRAM copied to SystemRAM, the line drawn and the result copied back to VRAM?

And what happens if I call setRGB() from the BufferedImage?


I hope my grammar is understandably ... to read some english text and to write some is a a larger difference than I thought **
Offline Jeff

JGO Coder




Got any cats?


« Reply #13 - Posted 2003-12-28 19:07:16 »

Quote
*Meow* Smiley

u doodz need 2 lern 2 spk dood. lol.
.


D3wd, u rok!  U r 2 l33t!

I can speak it too.  I can also speak baby-talk.  Doesn't mean its appropriate here.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline Jeff

JGO Coder




Got any cats?


« Reply #14 - Posted 2003-12-28 19:17:02 »

Quote
K, I will stop writing as if I am chat with friends in a MMORPG, will be more simply to read for the normal ones :-)

if you make your bufferstrategy with
createBufferStrategy(2)
then it will be done like that, but furthermore you can create the bufferstrategy with
createBufferStrategy(2, BufferCapabilities)
then you can select between page flipping and page blitting.


You can force fullscreen to BLT, but I don't know why you would want to.

You cannot make windowed do anything but BLT because thats the nature of windows on a Win32 box, they are BLTd.  There is no hardware windowing support on WIntel graphics cards.

In general the code picks the best method for your situation, so let it unless you have a really strong reason to want to defeat it.

Quote

If we are already at Hardwarefeatures, which methods from Graphics2D (got with createGraphics from a BufferedImage which was got with createCompatibleImage) are Hardwareaccelerated?


I believe this depends on the abilities of your graphics card and driver.  If you post questions like this to the Java 2D category you can get answers from people like Dmitri who actually work on that code inside of the JDK.

And your english grammer is just fine Smiley

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline DD.Jarod

Senior Newbie




Sry for my bad english :-)


« Reply #15 - Posted 2003-12-28 20:31:48 »

Quote
You can force fullscreen to BLT, but I don't know why you would want to


mh .. good question, I think the only reason would be to test the approximately FPS the programm has if it's started under linux, without reboot to it and test.

For the ones which are interessted in my questions about the acceleration of Graphics2D methods I copied it to the Java2D forum, topic is named:
Which methods from Graphics2D are HW-accelerated?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (25 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (43 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!