PDA

View Full Version : openGL right for per-pixel 2D ?



elenzil
06-13-2005, 03:28 PM
Howdy.

I'm an experienced 3d programmer and now have an idea for a pretty application doing per-pixel calculations in a purely 2D setting.

Stuff similar to music visualizers.

Is openGL a good place to do this ?
(if not, what is?)

Where could i look for windows examples ?

thanks in advance,
orion

Korval
06-13-2005, 05:27 PM
Define "a purely 2D setting".

If this means that you're not allowed to use any 3D graphics hardware, then OpenGL is not going to be helpful to you.

If it means that you're not rendering in perspective 3D, then OpenGL can draw orthographics 3D just fine. And if you only use 1 z-value, it's no different from 2D.

elenzil
06-15-2005, 10:16 AM
thanks for the reply.

by purely 2D i just mean without any appearance of 3D. using modern graphics hardware is fine.

effectively i just want to set pixels in the frame buffer as fast as possible. how i do that is an open question.

the obvious approach is to draw the pixels to a texture each frame and render that on a screen-aligned quad, but i'm wondering if there's a faster way if i want one texel to be exactly one pixel.

(i'll probably go with the texture route anyhow since it can be wrapped on geometry, but i thought openGL might let you just write straight to the frameBuffer)

Korval
06-15-2005, 10:30 AM
The best way to do 2D through OpenGL is to do it all through OpenGL. I don't mean just displaying a finished image. I mean generating that image in OpenGL.

If you're just wanting to display some image you loaded off of disk, that's fine. But if you're doing some 2D rendering (sprite graphics, line drawing, whatever), you should be using OpenGL to do that rendering.

killerseven
06-15-2005, 12:01 PM
OpenGL doesnt give you direct access to the framebuffer, but the method you describe (updating a texture) is fine.

Depending on your application and your target hardware it might be worth looking into pixel shaders.

If you can write your code to run on the GPU you will see massive speed benefits, but this will also limit your target audience.

VikingCoder
06-15-2005, 01:10 PM
Or you could use SDL, which allows exactly the kind of access you're talking about in a cross-platform compatible kind of way.

http://www.libsdl.org/index.php

elenzil
06-20-2005, 03:12 PM
Huh - SDL might be the ticket.

I'm a bit aesthetically underwhelmed by some of the demos there, but maybe it's because i haven't compiled most them yet.

I might be able to use GPUs to do the actual math via texture look-ups and such, but for starters i'm just going to do the crunch in CPU and dump it to a texture (or the frame buffer, if SDL allows that)

Many thanks all.

orion

Zengar
06-20-2005, 04:04 PM
Doing a 2d-look is very simple in OpenGL - you just fix your camera above the scene and do your lighting with several tiled textures. I tried it out some time ago - great quality, very simple and lighting fast! As said above, it will limit your target audiency thought...
BTW, already baldurs gate 2 was rendered using OpenGL for images! They rendered textured squads to represent the world and the characters.