Results 1 to 7 of 7

Thread: Mixing 2D and 3D problem

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2010
    Location
    Prague - Czech
    Posts
    3

    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.

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Location
    Poland
    Posts
    111

    Re: Mixing 2D and 3D problem

    Strange,
    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

    edit:
    I assume You didn't forget about glRasterPos before glDrawPixels

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2010
    Location
    Prague - Czech
    Posts
    3

    Re: Mixing 2D and 3D problem

    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...

  4. #4
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Location
    Poland
    Posts
    111

    Re: Mixing 2D and 3D problem

    512x512?
    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:
    Code :
    GLint  texSize;
    glGetIntegerv( GL_MAX_TEXTURE_SIZE, &texSize );
    printf( "GL_MAX_TEXTURE_SIZE %d\n", (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:

    http://www.gamedev.net/reference/art...rticle2331.asp

  5. #5
    Junior Member Newbie
    Join Date
    Jan 2010
    Location
    Prague - Czech
    Posts
    3

    Re: Mixing 2D and 3D problem

    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!

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Mixing 2D and 3D problem

    "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.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Aug 2009
    Location
    Poland
    Posts
    111

    Re: Mixing 2D and 3D problem

    - 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?

    edit:
    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

    (http://www.opengl.org/registry/specs..._rectangle.txt)
    (http://www.opengl.org/registry/specs...wer_of_two.txt)

Similar Threads

  1. RE mixing GDI with OpenGL
    By remdul in forum OpenGL: Windows
    Replies: 1
    Last Post: 08-30-2011, 06:44 PM
  2. Mixing 2d and 3d
    By Mitikoro in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-31-2008, 03:01 AM
  3. Mixing 32 and 16 bit indices in a VBO
    By knackered in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 02-04-2008, 07:19 AM
  4. mixing float and double (precision problem)
    By Jens B in forum OpenGL: Advanced Coding
    Replies: 7
    Last Post: 07-19-2004, 09:39 AM
  5. Mixing VAR and VertexProgram Problem
    By Sancho in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 06-15-2003, 11:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean