|
From: Joe V. <jo...@ve...> - 2003-04-09 06:15:21
|
> So I guess a similar effect in OpenGL would be to use replace
> the pixel drawing with a function similar to the following:
>
> void drawDot(GLint x, GLint y, GLfloat red, GLfloat green, GLfloat blue)
> // Draw a color dot at (x,y)
> {
> glColor3f(red, green, blue);
> glBegin(GL_POINTS);
> glVertex2i(x, y);
> glEnd();
> }
>
> My first thought is that it would be slower to draw pixels directly to a
> screen, rather than bitmaps. But I'm new to OpenGl, so my knowledge is
> limited.
>
> The code that advances the sonar screen and make the waterfall effect is
> the hard part. I think it sort of does a cut and paste. It cuts part
> of the screen, moves it down and blits it back. Is there a way to do
> the same thing in OpenGL?
No, using GL_POINTS is totally not the way to go. Let me explain:
You can copy SDL surfaces to OpenGL textures every frame. So, you could do the exact same sonar code where you're using a temp surface and then the two final surfaces, and instead of blitting them to the screen (which is the last step in what the old code does) just send them to the textures for two quads which are positioned where you want the waterfall displays.
Does this make sense how I'm explaining it? I recently switched to gentoo linux (gentoo.org) and am only now getting around to re-installing Anjuta, but I'll try to make up a short little bit of example code:
// So, the init code is something like this:
int waterfall1_opengltex;
SDL_Surface *waterfall1_sdltex[1];
glGenTextures(1, &waterfall1_opengltex);
// And then every loop you'd do something like this:
while (loop)
{
// ... do stuff to update the SDL surface waterfall1_sdltex
glBindTexture(GL_TEXTURE_2D, waterfall1_opengltex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, waterfall1_sdltex[0]->w, waterfall1_sdltex[0]->h, GL_BGR, GL_UNSIGNED_BYTE, waterfall1_sdltex[0]->pixels );
// And then draw our output quad
glBegin(GL_QUADS);
glVertex3f(0,0,0); glNormal3f(0,0);
glVertex3f(10,0,0); glNormal3f(1,0);
glVertex3f(10,10,0); glNormal3f(1,1);
glVertex3f(0,10,0); glNormal3f(0,1);
glEnd();
}
Or something like this. I haven't actually tested this, but I think this is definitely the way to do it.
Joe Venzon
|