Jump to content
  • Advertisement
Sign in to follow this  
KISS-GL

Dynamic Background Texture

This topic is 4826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, for a 2d-game im writing i need to render to the background image ( to draw an infinite number of dead bodies :)). So I wrote a small test program which loads a green 512x512 bitmap and generates a texture from it. This texture is drawn into the Backbuffer (as textured quad) and a line is drawn over it at a random angle. Then the content of the Backbuffer is written back to the backgroundtexture with glCopyTexImage2D. It does work as expected( the texture is drawn to ), except one thing. The problem is, that the drawn points get bigger which each time the texture is captured. It seems something doesnt really fit, but i cant explain this effect. Heres the critical code : int DrawGLScene(GLvoid) // Here's where we do all the drawing { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear screen and depth buffer glLoadIdentity(); // Reset the current modelview matrix if (glGetError() != GL_NO_ERROR) MessageBox(NULL,"Some Error occured","SHIT",MB_OK); glTranslatef(0.0f,0.0f,-2.41799f); glBindTexture(GL_TEXTURE_2D, backgroundTexture); glBegin(GL_QUADS); // Start Drawing A Textured Quad glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f); // Bottom Left glTexCoord2f(1.0f, 0.0f); glVertex2f( 1.0f, -1.0f); // Bottom Right glTexCoord2f(1.0f, 1.0f); glVertex2f( 1.0f, 1.0f); // Top Right glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f, 1.0f); // Top Left glEnd(); float randVal = rand()/32768.; // This will draw a black line from the center to the border // in a random angle glColor3f(0.0f,0.0f,0.0f); glBegin(GL_LINES); glVertex3f(0.0f,0.0f,0.0f); glVertex3f(cos(randVal*2*M_PI),sin(randVal*2*M_PI),0.0f); glEnd(); glColor3f(1.0f,1.0f,1.0f); glBindTexture(GL_TEXTURE_2D,backgroundTexture); // Bind the texture glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8,0 , 0, 512, 512, 0); glTranslatef(0.0f,0.0f,2.4179f); return true; // Keep going } Can somebody check this out and tell me whats going wrong. The backgroundImage is just a unicolored bitmap(green in my case). The Windowsize is also 512x512 pixels( client area ). Im still quite new to OpenGL. Thanx, Marc

Share this post


Link to post
Share on other sites
Advertisement
How is your glFrustum/gluPerspective/glOrtho call setup? Do the pixels of the texture match the window pixels exactly? If part of your texture is outside the viewing volume, a zooming effect can occur. And what's with the magic:
glTranslatef(0.0f,0.0f,-2.41799f);


If it is used to match the quad with a perspective viewing volume, switch to an orthogonal viewing volume (-1, 1, -1, 1) instead. When doing 2D, you should always use glOrtho...

Tom

Share this post


Link to post
Share on other sites
Hey,

@dimebolt :
thanks for your reply. After switching to orthogonal viewing the texture
is rendered(mostly) correct and the zoom-in effect got lost.
But theres still something going wrong :
The Texture is getting darkened each time it is captured and redrawn.
After some time, the whole texture is black. It has to do with
the Texture Filter i think. If i use GL_LINEAR the older lines seem to fade away. If i use GL_NEAREST the lines are good, but the texture is still darkened.

I uploaded the Project to :

This Place( Click on Dynamic Texture ... )

Any ideas ?

Marc

Edit : Made a HTML link

[Edited by - KISS-GL on September 25, 2005 8:48:11 AM]

Share this post


Link to post
Share on other sites
Ok, problem got solved.
The code I posted above produces bad results on the Notebook i used.
It has an SIS 650 onboard GPU(shared Mem).
On my other System( GeForce FX 5700LE ) everything works fine. :)
Maybe the bad behaviour can be solved by another display driver ?!
Anyhow, thanks 2 all

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!