PDA

View Full Version : Trailing problem



zadeh79
08-20-2006, 09:32 PM
The charachter I am drawing is leaving a trail across the screen. I need to somehow get rid of the previous charachter rendered without clearing the entire screen (otherwise I have to load the background texture again). Perhaps a useful note - I have drawn the charachter slightly closer to the camera than the background


www.geocities.com/zadeh1979/trail (http://www.geocities.com/zadeh1979/trail)

Zengar
08-21-2006, 03:51 AM
Why do you have to load the texture again? Can't you just load it one time as discussed in your other thread? Texture images are stored within texture objects.

Usually, one redraws the whole scene on each frame.

p.s. Don't crosspost please...

RigidBody
08-21-2006, 04:23 AM
believe it or not, it's not a good idea to use a full-screen texture. especially not in your case, because your background texture mainly consists of a repeating grass pattern. btw, this was discussed some months ago (http://www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=2;t=020175;p=1#0000 11) in case you don't remember...

it would be much wiser to first draw a full-screen quad with a small grass texture, which is repeated by choosing the appropriate texture coordinates.

then draw the house on top of the grass quad, with an offset into the camera direction, then the player etc.

Jan
08-21-2006, 10:26 AM
Well, when doing 2D you can disable the depth-buffer completely and solve the correct ordering by just drawing them in the right order, you don't need any z-offset.

zadeh79
08-21-2006, 08:18 PM
"Why do you have to load the texture again? Can't you just load it one time as discussed in your other thread? Texture images are stored within texture objects.
Usually, one redraws the whole scene on each frame."

What I meant was that I have to keep redrawing the texture to the screen. I know the loading process takes up much time in the loop. I can get around this by loading the texture once and just redrawing on every loop. Unfortunately, redrawing seems to take up a lot of time as well.


void RenderScene(void)
{


if (m == 1)

{


GLuint texture = 0;

glbmp_t bitmap;

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glbmp_LoadBitmap("grass2.bmp", 1, &bitmap);

//generate and bind the OpenGL texture
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);


//copy data from bitmap into texture
glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmap.width, bitmap.height,
0, GL_RGB, GL_UNSIGNED_BYTE, bitmap.rgb_data);


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


glViewport(0, 0, 1024, 1024);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);


glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(85.0, 1.0, -5.0, 0.0);


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

gluLookAt(.50 , .52 , -.60, 0.50 , 0.52 , 0.0, 0.0, 10.0, 0.0);


glClear(GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT);


glShadeModel(GL_SMOOTH);



glFrontFace(GL_CCW);


glBegin(GL_QUAD_STRIP);

glTexCoord2f(1.0, 0.0);
glVertex3f(1.0f, 0.0f, 0.0f);

glTexCoord2f(1.0, 1.0);
glVertex3f(1.0f, 1.0f, 0.0f);

glTexCoord2f(0.0, 0.0);
glVertex3f(0.0f, 0.0f, 0.0f);

glTexCoord2f(0.0, 1.0);
glVertex3f(0.0f, 1.0f, 0.0f);

glEnd();


glDeleteTextures(1, &texture);
glbmp_FreeBitmap(&bitmap);


m = 0;


glNewList(1, GL_COMPILE);


glPolygonMode(GL_FRONT, GL_FILL);


glPushAttrib(GL_CURRENT_BIT);


//HEAD OF MAIN CHARACHTER
glColor3f(1.0, .92, .92);
glBegin(GL_POLYGON);
glVertex3f(.47f, .48f , -0.042f);
glVertex3f(.47f, .50f , -0.042f);
glVertex3f(.485f, .50f , -0.042f);
glVertex3f(.485f, .49f , -0.042f);
glVertex3f(.489f, .49f , -0.042f);
glVertex3f(.489f, .488f , -0.0420f);
glVertex3f(.485f, .488f , -0.0420f);
glVertex3f(.485f, .478f , -0.0420f);
glEnd();


//EYE OF MAIN CHARACHTER
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(.480f , .490f , -0.0420f);
glVertex3f(.485f , .499f , -0.0420f);
glVertex3f(.485f , .490f , -0.0420f);
glEnd();


//MOUTH OF MAIN CHARACHTER
glColor3f(0.65, 0.0, 0.0);
glBegin(GL_POLYGON);
glVertex3f(.482f , .480f , -0.0420f);
glVertex3f(.482f , .482f , -0.0420f);
glVertex3f(.485f , .482f , -0.0420f);
glVertex3f(.485f , .480f , -0.0420f);
glEnd();


//HAIR OF MAIN CHARACHTER
glColor3f(0.65, 0.50, 0.0);
glBegin(GL_POLYGON);
glVertex3f(.469f , .497f , -0.0420f);
glVertex3f(.472f , .501f , -0.0420f);
glVertex3f(.485f , .501f , -0.0420f);
glVertex3f(.485f , .497f , -0.0420f);
glVertex3f(.47f , .492f , -0.0420f);
glEnd();


//EAR OF MAIN CHARACHTER
glColor3f(1.00, 0.75, 0.75);
glBegin(GL_POLYGON);
glVertex3f(.473f , .487f , -0.0420f);
glVertex3f(.471f , .492f , -0.0420f);
glVertex3f(.478f , .487f , -0.0420f);
glEnd();


//BODY OF MAIN CHARACHTER
glColor3f(.40, 0.40, 0.40);
glBegin(GL_POLYGON);
glVertex3f(.470f , .455f , -0.0420f);
glVertex3f(.470f , .479f , -0.0420f);
glVertex3f(.485f , .479f , -0.0420f);
glVertex3f(.485f , .455f , -0.0420f);
glEnd();


//LEGS OF MAIN CHARACHTER

if (l == 0)
{
glColor3f(.40, 0.40, 0.40);
glBegin(GL_POLYGON);
glVertex3f(.471f , .445f , -0.0420f);
glVertex3f(.471f , .455f , -0.0420f);
glVertex3f(.484f , .455f , -0.0420f);
glVertex3f(.484f , .445f , -0.0420f);
glEnd();
}


if(l == 1)
{
glColor3f(.40, 0.40, 0.40);
glBegin(GL_POLYGON);
glVertex3f(.468f , .443f , -0.0420f);
glVertex3f(.473f , .455f , -0.0420f);
glVertex3f(.477f , .453f , -0.0420f);
glVertex3f(.471f , .443f, -0.0420f);
glEnd();
}


glPopAttrib();


glEndList();

}


glPushMatrix;
glTranslatef(s , a , 0);
//glScalef(.75, .75, 0);
glCallList(1);
glPopMatrix;


glutSwapBuffers();


}



Note that the m == 1 condition will make all texture and charachter work to be processed once, on the first time through the loop. For whatever reason this does not seem to speed the process up.

Zengar
08-22-2006, 12:46 AM
oO

Were you actually listening to what we where telling you? And did you look into some tutorials. Once more: remove the texture creation and list creation code from the rendering loop!

Create a setup function that loads the texture and creates the list. Call this setup function in your main bfore you initialize the main loop. In the rendering loop you just draw the texture (basically, you begin with the glViewport part then you skip all the list creation and finally call the list.

Look at Nehe demos that use texturing. And read the post carefully. Once more: do not reate/load textures, lists whatever in your rendering loop if you can do it in a setup state.

zadeh79
08-22-2006, 05:19 PM
I learned a lot from everyones suggestions, but this problem appeared to not be related to my poor programming etiquite. I solved the problem by copying parts of the screen with glcopypixels and rendering to where the characther should be drawn. Then I render the charachter over this. In this way, I preserve the underlying texture without having to re-render it. This probably sounds like an unorthodox solution, but it works great, and it's fast too.

Jan
08-23-2006, 01:12 AM
If you MUST go with your head through the wall, just go ahead. But the way Zengar explained in much detail is the best possible solution in every aspect.

As a beginner it's ok to try out what you want. But my advice is to listen to what experienced people tell you, they might know what they are talking about.

Jan.