Mixing 2D and 3D problem

Hello, I’m trying to program worms/liero like 2D game for school project in C++ and i wanted to combine 2D and 3D elements of OpenGL together. By 2D i mean glDrawPixels for drawing destroyable landscape and by 3D normal textured squares by glVertex and such. I encountered very interesting problem because on my PC everything was fine, but when i sent testing version to few my friends some said that it’s ok, but some didn’t saw any landscape at all. (mostly the ones with newer computers) It took me a long time, but eventually I figured out that OpenGL stops rendering any glDrawPixels in exact time when i try to render textured 3D vectors… (even raster fonts) Maybe there is some options that needs to be set to safely combine these two rendering approaches, I don’t really know. I was wondering if somebody know where the problem can be and maybe encountered the same problem.

but there is simple workaround: don’t use glDrawPixels. Instead draw full screen textured quad (with your landscape). You may want to mask out depth buffer writes during this, to make it ‘background’. It should be faster, and more reliable than glDrawPixels

I assume You didn’t forget about glRasterPos before glDrawPixels

No i didn’t forget glRasterPos. I know about this option, but this landscapes are big (2048x800 and more). I can’t do textures big as this. (there is limit 512x512 in OpenGL and they should be also square i think) There is option to slice this big picture to more smaller ones that can be stored like textures and than during rendering “bring them together” but it would be much harder than this glDrawPixels approach especially when i need to quickly edit this pixels because its destructible landscape. I think its much easier to have this pixels in classic array, edit them there and then render it. (i don’t know how can edit texture pixels) And yes it is very strange thats why i’m asking if someone else encountered this problem. If i will have time i try to do some code example to try out, it would be best. But it’s possible that all that will try that code will be lucky ones with computers where does it works fine…

On my laptop (with ancient ATI Mobility Radeon 7500 (R100 chipset)) GL_MAX_TEXTURE_SIZE is 2048,
GF9800GT reports 8192, I do not have any other cards to test.

If You want to know your limit call:

GLint  texSize;
glGetIntegerv( GL_MAX_TEXTURE_SIZE, &texSize );
", (int)texSize );

And they don’t have to be square (test if extension string contains GL_ARB_texture_rectangle, and (newer hardware) GL_ARB_texture_non_power_of_two)

You should be able to render your terrain(2048x800) as 2048x1024 with GL_ARB_texture_rectangle.

If You want to render to texture, use FBO (framebuffer object)
example setup code here:


Textured squads was my first approach but i had some problems there with big textures. (didn’t show them) I liked that with glDrawPixels you i can have landspace as big as i want and doesn’t worry about maximum size of textures. But i will try to look at that textured squads approach again… But thanks for help!

“You should be able to render your terrain(2048x800) as 2048x1024 with GL_ARB_texture_rectangle.”
No, to clarify :

  • 2048x800 is doable with GL_ARB_texture_rectangle
  • 2048x1024 is doable with standard texturing, without extension.

The “rectangle” is a misnomer, as there is nothing that forces square textures, only a constraint about power-of-two for each dimension.

  • 2048x800 is doable with GL_ARB_texture_rectangle

I didn’t know about that.
One more question: what’s the difference between GL_ARB_texture_rectangle, and GL_ARB_texture_non_power_of_two?

I just found the answer:

  1. In GL_ARB_texture_non_power_of_two, You can use normalized texture coordinates ([0;1]x[0;1]), and with GL_ARB_texture_rectangle You have to use coordinates from [0;width]x[0;height]

2 Mip-map filtering is not allowed in GL_ARB_texture_rectangle, but works in GL_ARB_texture_non_power_of_two