Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
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  
  Weird transparency problem  (Read 1749 times)
0 Members and 1 Guest are viewing this topic.
Inquisitor
Guest
« Posted 2004-05-20 19:36:46 »

Hello all. I'm doing a 2d-game with LWJGL. I'm drawing 64x45 tiles in the level and I wanted to draw only the ones that have changed. First I used pbuffer to achieve this but it was too slow and clumsy way to do it. So now i'm simply not using glClear(GL_COLOR_BUFFER_BIT) at all which works great... in windowed mode. In fullscreen mode with V-sync disabled I'm getting horrible flickering with black lines. In fullscreen mode with V-sync enabled the flickering goes away but the tiles are transparent and I see the main menu background image through the tiles - even though I do glClear(GL_COLOR_BUFFER_BIT) before changing to level's rendering. So the tiles for some reason are about 50% translucent.

Because I'm not rendering the tiles all the tme i have to update the tiles which are under mouse cursor all the time. But in fullscreen mode it either doesn't work correctly - if I move the mouse too quickly it leaves a trace (these ghost cursors are transparent too even though they shouldnt be).

The weirdest thing is that when my game was running and I got a notice from Windows Messenger saying that someone logged in (a pop-up window), all those problems did go away and it worked just like it was supposed to (until I restarted the game of course).

I'm not using depth-buffer at all (setting it to 0 bits size upon display creation).

I have Windows XP, Radeon 8500 (catalyst 4.5, newest) and LWJGL 0.9a.

Anyone have any ideas what might be happening here?
Offline princec

JGO Kernel


Medals: 360
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #1 - Posted 2004-05-20 21:06:18 »

Always draw the whole scene every frame.
Always make sure you call Window.update() every frame, no matter what. Which means you must always render every frame, too, as Window.update() swaps the buffers, and if you've failed to draw anything in a buffer it'll just appear with whatever was last in it.


Cas Smiley

Inquisitor
Guest
« Reply #2 - Posted 2004-05-20 22:32:25 »

So even though I could get rid of the transparency effects/flickering on my comp, this method would be a 'loose cannon/unsupported' way?
I guess I'll switch to constant rendering then, but I'm gonna use a buffer because it's slow to draw all those 2880 images (they're displayed all the time and most of them are static).
I'm new to opengl and pbuffers are actually the only way I know how this is done. What way would you suggest to render to an offscreen buffer or texture?

This was so easy with java2d and bufferedimages..
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tom
« Reply #3 - Posted 2004-05-20 23:00:29 »

Quote
So the tiles for some reason are about 50% translucent

Sounds like you need to disable blending.

Quote
I'm not using depth-buffer at all (setting it to 0 bytes size upon display creation).

This is not the correct way of disabeling the z buffer. The docs says that you will get mininum 0 bits, you may get more. Instead use "glDisable(GL11.GL_DEPTH_TEST);" to disable the depth test.

Quote
but I'm gonna use a buffer because it's slow to draw all those 2880 images

It depends on how you draw your images Wink Can't see why there would be a performance problem if you do it correctly.

OpenGL is not the same as java2d! Doing the same java2d optimizations in opengl is not the way to go. Try to rethink the problem and come up with another solution. I'm sure we can give you some suggestions if you give a good description of exactly what you are trying to accomplish.

Inquisitor
Guest
« Reply #4 - Posted 2004-05-21 00:39:21 »

Quote

Sounds like you need to disable blending.

Tried it already. All I got is black box around the cursor.

Quote

This is not the correct way of disabeling the z buffer. The docs says that you will get mininum 0 bits, you may get more. Instead use "glDisable(GL11.GL_DEPTH_TEST);" to disable the depth test.

No luck here either.. thanks for the info though.

Quote

It depends on how you draw your images Wink Can't see why there would be a performance problem if you do it correctly.


I'm sure this ain't the fastest way to do it but I thought it'd be fine if I jsut could render the entities i need to (most of the entities dont need to be rendered most of the time).
Now i'm getting ~80fps on my 1200mhz TB without sounds/multiplayer (rendering every tile evrey tick) and I want the game to run on older machines too. It's actually a remake of an old dos game called Minebombers. Currently I'm storing all the game images in one texture and just drawing them as textured quads.

Entity:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
      public final void render()
      {
            if(!changed)
                  return;
            if(!visible)
                  return;
           
            GL11.glPushMatrix();
                  GL11.glTranslatef(position.x,position.y,0);
                  GL11.glBegin(GL11.GL_QUADS);
                        GL11.glTexCoord2f(getTexture().OFFX, getTexture().OFFY);
                        GL11.glVertex3f(0, 0, 0);
                        GL11.glTexCoord2f(getTexture().OFFX+getTexture().OFFW, getTexture().OFFY);
                        GL11.glVertex3f(size.x, 0, 0);
                        GL11.glTexCoord2f(getTexture().OFFX+getTexture().OFFW, getTexture().OFFY+getTexture().OFFH);
                        GL11.glVertex3f(size.x, size.y, 0);
                        GL11.glTexCoord2f(getTexture().OFFX, getTexture().OFFY+getTexture().OFFH);
                        GL11.glVertex3f(0, size.y, 0);
                  GL11.glEnd();
            GL11.glPopMatrix();
            changed = false;
      }


Level:
1  
2  
3  
4  
5  
6  
            GLTextureManager.getManager().bind("gameimages");
            GL11.glPushMatrix();
                  for(int y=0; y < size.h; y++)
                   for(int x=0; x < size.w; x++)
                         entities[x][y].render();
            GL11.glPopMatrix();


Screenshot:
http://koti.mbnet.fi/mc3712/mb1.gif
Offline elias

Senior Member





« Reply #5 - Posted 2004-05-21 04:42:45 »

Did you try a profiler to check what really is the most expensive operation? I'm guessing that either:

1. the if(!visible) check doesn't work and you draw a lot more than you think.
2. the glPush/Pop and glBegin/End/Vertex/TexCoord is the culprit and you need to convert the rendering to something more effective. First try using absolute coordinates in the glVertex calls so you can avoid glPush/Pop/Translate. Like this:

glVertex3f(0, 0, 0)

becomes

glVertex3f(position.x, position.y, 0);

and so on. If that doesn't help, and the coordinates are constant, I'd use vertex arrays to render the tiles. to avoid the explicit Begin/End/Vertex/TexCoord calls.

- elias

Offline princec

JGO Kernel


Medals: 360
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2004-05-21 07:51:26 »

Should definitely use vertex arrays.

Cas Smiley

Offline Orangy Tang

JGO Kernel


Medals: 56
Projects: 11


Monkey for a head


« Reply #7 - Posted 2004-05-21 08:05:23 »

Depth testing comes disabled by default, so you shouldn't have to worry about that. Also, is your ~80fps actually 85 and locked to your refresh rate perchance?

[ TriangularPixels.com - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #8 - Posted 2004-05-21 08:42:29 »

I would just use a text routine and alternate that a bit.

Display lists are ok... that automated translate (as part of the display list) is also great... and the print method will just spit out complete lines (instead of Strings). Since each line is put into a ByteBuffer the overhead will be ok-ish. Well, after all it's just like writing 45 lines of text on the screen.

I don't say that that would be the fastest way, but it's of corse faster than the slowest way - intermediate rendering (the thing you do right now) and additionally it wouldn't be much work. Oh and compatibility won't be an issue Wink

弾幕 ☆ @mahonnaiseblog
Inquisitor
Guest
« Reply #9 - Posted 2004-05-21 09:04:20 »

Quote

the if(!visible) check doesn't work and you draw a lot more than you think

Actually it isn't even used and I should've removed it.

Quote
Also, is your ~80fps actually 85 and locked to your refresh rate perchance?

Nope no vsync and getting ~1000 fps in menu.

Here's a snip from -XProf:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
         Stub + native   Method                        
 28.0%     0  +  4995    org.lwjgl.opengl.Window.swapBuffers
 27.9%     0  +  4976    org.lwjgl.opengl.GL11.glBegin
  6.6%     0  +  1184    org.lwjgl.opengl.GL11.glPushMatrix
  5.9%     0  +  1053    Music.FmodAPI.NativeFmodJNI.FSOUND_Update
  5.5%     0  +   972    org.lwjgl.opengl.GL11.glTranslatef
  5.2%     0  +   920    org.lwjgl.opengl.GL11.glVertex3f
  4.1%     0  +   733    org.lwjgl.opengl.GL11.glTexCoord2f
  1.8%     0  +   315    org.lwjgl.opengl.GL11.glPopMatrix
  1.2%     0  +   215    org.lwjgl.opengl.GL11.glBindTexture

I guess I'll try vertex arrays then, thanks everyone.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nnevatie

Junior Member




It is slightly better to be simple than correct.


« Reply #10 - Posted 2004-05-29 10:38:47 »

Quote

I guess I'll try vertex arrays then, thanks everyone.


Since the game does not scroll its screen, I'd recommend using the simple and compatible display lists. You should only update the list when the actual contents of the level change, e.g. when the player makes a hole in the wall, etc.. Also, you should consider, if it would be wise to store the tiles in the display lists in rows or columns. That way, you'd have a single row/column of tiles in a single list -> less frequent updates of lists. Will this become MB2, BTW? Wink



Awards:
- Nobel Prize in Physics for inventing his Doomsday Machine
- Nobel Peace Prize for not using it

http://www.g0dmode.com -- a collection of things not real
Inquisitor
Guest
« Reply #11 - Posted 2004-05-29 14:44:14 »

Quote

Will this become MB2, BTW? Wink


Nope, just a remake of original with network game (completely free). I haven't actually asked yet if the Skitso guys like about the idea of making a remake (since they are making MB2 at the moment - http://koti.mbnet.fi/pacbros/skitsoproductions/MBII.html), but i doubt they'd have anything against it (especially since I have a big MB2 ad. as a quit screen Smiley).

And thanks for the display list suggestion I'll try it too. Though i've been to lazy to try vertex arrays yet either.
Inquisitor
Guest
« Reply #12 - Posted 2004-06-01 21:50:02 »

I tried to use vertex arrays but for some reason nothing showed up. I probably screwed something up with ByteBuffers since I ain't very used to them yet.

But then I removed glTranslate() and push/pop matrix from entity's render code, tried display lists and now I'm getting ~500 fps. Now that was an improvement I really wasn't expecting Shocked I guess i'll still try vertex arrays just for the comparison anyways.
Offline nnevatie

Junior Member




It is slightly better to be simple than correct.


« Reply #13 - Posted 2004-06-02 01:34:21 »

Quote
But then I removed glTranslate() and push/pop matrix from entity's render code, tried display lists and now I'm getting ~500 fps. Now that was an improvement I really wasn't expecting Shocked I guess i'll still try vertex arrays just for the comparison anyways.


Nice. I bet the vertex arrays provide only a few extra fps...

Awards:
- Nobel Prize in Physics for inventing his Doomsday Machine
- Nobel Peace Prize for not using it

http://www.g0dmode.com -- a collection of things not real
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.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

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

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

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!