|
silly openGl texture question |
Pavel Hilser
Member #5,788
April 2005
|
I have started to make a 2d top view game. Wall, monsters, etc. My problem - when creating the shadows, i draw them directly to the level - and thats bad, cause i can't do 2 lightsources at once. So the question - how should I change the drawing code to draw on some "memory-bitmap" as used in allegro and not directly on the video screen ? My code is from the tutorials, nothing special..
_____________________________________ |
Mr. Big
Member #6,196
September 2005
|
You need to render your lights and shadows on a texture using FBOs, and call 'glBlendEquationEXT(GL_MAX_EXT)', which would make your lights and shadows accumulate in a realistic way, e.g. red, green and blue lights will mix into white. But even then, simply blending your shadowmap with the level won't do the job, because then, even the most dark spot won't be completely dark because it'll be a blend of black and whatever is underneath it. Maybe you can use 'glBlendEquationEXT' with another parameter to fix that (what you need is to multiply the level pixel by the lightmap pixel), I don't remember how it's called, though. [EDIT] Silly me! Oh, and here's an example of how to render stuff on a texture:
Hope this helps! |
Pavel Hilser
Member #5,788
April 2005
|
Ok, don't know if its what you showed - I reprogrammed my program, that it draw the shadows, then copy it to a buffer texture, draw all my stuff and put the shadow texture on the level. Ok so far. All working fine. BUT my fps drops from 150 to 50 and when I use multiple sources (5 monsters that are casting shadows), the game is not playable - 4 fps. My problem is, that I handle a lot of data ------- for(each monster) - clear video but erasing©ing over and over the shadow bitmap (using blending) is not usable .. So is there a way to draw directly to a texture ? _____________________________________ |
Mr. Big
Member #6,196
September 2005
|
Sorry it took me so long to reply. I won't be surprised if it's the third option, 'cause the example code is pretty bad. First you need to get a valid OpenGL ID for your framebuffer. GLuint framebuffer; glGenFramebuffersEXT(1, &framebuffer); Then, in the main loop, you render your shadows on the texture: glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer); glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, your_lightmap, 0); make_viewport_same_size_as_lightmap(); draw_some_shadows(); Note that in the shadow-drawing function, you need to do everything you would usually do when you draw to the screen. (Clear the color buffer ect.) Then, you need to switch back to the ordinary screen and draw your scene with the lightmaps. glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); make_viewport_the_way_it_was(); render_scene();
And one last thing, don't be surprised if your FPS is 150 with one lightsource and 50 with two. |
Fladimir da Gorf
Member #1,565
October 2001
|
But beware that especially NVidia doesn't seem to like supporting framebuffer objects... OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
Bob
Free Market Evangelist
September 2000
|
Quote: But beware that especially NVidia doesn't seem to like supporting framebuffer objects... What gave you that impression? FBOs are fully supported on all GeForce FX, GeForce 6 and GeForce 7 series of GPUs. -- |
Mr. Big
Member #6,196
September 2005
|
I have a GeForce 5700 LE and they don't do me any trouble. |
Pavel Hilser
Member #5,788
April 2005
|
Mr.Big: thanx for the explanation - I really missunderstood your code (BTW I have 5700 too _____________________________________ |
Fladimir da Gorf
Member #1,565
October 2001
|
Quote: What gave you that impression? FBOs are fully supported on all GeForce FX, GeForce 6 and GeForce 7 series of GPUs. I read it from an another thread here. Buf if they are, that's great! OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori) |
|