View Full Version : 2D Effects with OpenGL
03-03-2000, 04:24 AM
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.
03-03-2000, 05:48 AM
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.
03-04-2000, 03:52 PM
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.
03-07-2000, 07:46 AM
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 ?
03-09-2000, 05:18 AM
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:
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...
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.