Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: 2D Effects with OpenGL

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    5

    2D Effects with OpenGL

    Is it possible to calculate some 2D Effects with OpenGL. I know how to draw a single frame, but i don't know which buffer to fill with the effect and how i can draw it to screen fast.

  2. #2
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Italy
    Posts
    77

    Re: 2D Effects with OpenGL

    I have got bad news.
    It's impossible to draw directly to buffers.
    The only way to go is glCopyPixels, which is painful. It's not designed for high fill-rate apps. Plus, you'll mess up Z-buffer data.
    I think you should consider to reinvent your effects in 3D. Something simple would be to render a texture with your effect, and billboard the effect in a QUAD.
    Some of the best effects I've seen combine 3D geometry and billboarding tecniques. Add some neat alpha blending, and you'll get cool visual effects.
    --
    Paolo M.

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2000
    Location
    Calgary,Canada
    Posts
    8

    Re: 2D Effects with OpenGL

    2d effects are quite simple to do in OpenGL, although it is very much oriented to do 3d ops. The gl(u)Ortho(2D) function removes any perspective you will get while doing 3d.

    Its all in how you set up your transformations, and drawing your vertices. Either you can draw everything using glVertex2(3)f(), while disable depth buffering, or you can use the glOrtho calls.

    OpenGL is streamlined for 3d, but that doesn't mean you can't mold it to do your anything you want.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2000
    Posts
    5

    Re: 2D Effects with OpenGL

    I tried it with 2 triangles (or a quad) with a texture, but i had problem with filling the texture used by gluBitmap.
    Is my code wrong ?

  5. #5
    Intern Contributor
    Join Date
    Feb 2000
    Location
    Italy
    Posts
    77

    Re: 2D Effects with OpenGL

    Yes, you do not use glBitmap for texturing.
    I assume that you want to do procedural texture maps... at least this is what I can guess from your post.
    There is alredy some thread around these forums, on the topic, but I will sum up the concept here.

    You have an array in memory holding pixel data for a texture, in whatever format you like. It should be arranged as a linear vector, not a multi-dimensional array:
    GLfloat texmapBuffer[32*32*4];
    This could be a 32x32 map, containg RGBA data (4 components).

    The application should roughly work like this:
    - activate a texture object for the map, with glBindTexture
    - set the texture data calling glTexImage2D
    - ENTER MAIN LOOP
    - reactivate the texture object for the map
    - store the calculated texture pixels in the texture map buffer
    - update actual texture data, by calling glTexSubImage2D; this is preferred to reusing glTexImage for performance reasons
    - render object with texture coordinates
    - iterate the process...

    Greetz
    --
    Paolo M.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •