Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Bleeding when translating objects

This topic is 5643 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

I am fairly new to the rigours of OpenGL and I'm trying to make a simple pong game. As such I have a static camera using the gluLookAt function, and I'm trying to translate the paddles using the glTranslatef() function across the x plane. This seems to work great except for the fact that the object is appearing to bleed across the screen and where the object was previously the paddle seems to remain. I'll include the various rendering parts of my game here (it's fairly heavily objectised) The initialisaiton of OpenGL (this game uses SDL for the window creation)
void CPong::SetupOpenGL(int Width, int Height)
   float ratio = (float) Width / (float) Height;
    // Our shading model--Gouraud (smooth). 

    glShadeModel( GL_SMOOTH );

    // Culling. 

    glCullFace( GL_BACK );
    glFrontFace( GL_CCW );
    glEnable( GL_CULL_FACE );

    // Set the clear color. 

    glClearColor( 0, 0, 0, 0 );

    // Make our viewport the whole window

    // We could make the view smaller inside

    // Our window if we wanted too.

    // The glViewport takes (x, y, width, height)

    // This basically means, what our our drawing boundries    

    glViewport( 0, 0, Width, Height );

    // Change to the projection matrix and set

    // our viewing volume.

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity( );

    gluPerspective( 60.0, ratio, 1.0f, 4000.0f );
The main game loop:
	// Preparing a new camera destroys

	// all previous transformations on the Modelview matrix

	glMatrixMode(GL_MODELVIEW); // Just in case

	glLoadIdentity();			// Bye bye previous transforms

    // Give OpenGL our position,           then view,             then up vector

    gluLookAt(0.0f, 0.0f, 1500.0f,     0.0f, 0.0f, 0.0f,         0.0f, 1.0f, 0.0f);
    glClearColor( 0, 0, 0, 0 );

    //humanplayer->SetX(humanplayer->GetX() + 2);

    //aiplayer->SetX(aiplayer->GetX() + 5);

    return true;
Code in the mesh object
	// Save off the current state of the matrix stack. At this point, the 

	// camera should have already been prepared.


    // Translate the object to it's current position

    glTranslatef(x, y, z);



	// Restore the matrix stack

The actual rendering (supports a display list)
  // Send our triangle data to the pipeline.

  glBegin( GL_TRIANGLES );

  // Since we know how many objects our model has, go through each of them.

  for(int i = 0; i < NumSubMeshes; i++)
    // Make sure we have valid objects just in case. (size() is in the vector class)

    if(SubMeshList.size() <= 0) 
    CSubMesh *subMesh = &SubMeshList[i];
    // Check to see if this object has a texture map, if so bind the texture to it.

    if (subMesh->HasTexture)
        // Turn on texture mapping and turn off colour


        // Reset the color to normal again

        glColor3ub(255, 255, 255);
        // Bind the texture map to the object by it's materialID

        // TODO

        //glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]);

        // Turn off texture mapping and turn on color


        // Reset the color to normal again

        glColor3ub(255, 255, 255);
    // Go through all of the faces (polygons) of the object and draw them

    for(int j = 0; j < subMesh->NumOfFaces; j++)
      // Go through each corner of the triangle and draw it.

      for(int whichVertex = 0; whichVertex < 3; whichVertex++)
        //GSpace::Face face = subCMesh.Faces[j];

        // Get the index for each point of the face

        int index = subMesh->Faces[j].vertIndex[whichVertex];

        // Give OpenGL the normal for this vertex.

        // TODO: do the vector calculations for the normals

        // glNormal3f(subMesh->Normals[index].x, subMesh->Normals[index].y, subMesh->Normals[index].z);

        // If the submesh has a texture associated with it, give it texture coordinates

        if (subMesh->HasTexture)
                // TODO: do proper texture coordinate stuff

                glTexCoord2f(subMesh->TexVertices[1 * i], subMesh->TexVertices[i]);
                if (MaterialList.size() > 0 && subMesh->MaterialID >= 0)
                    MaterialInfo *info = &MaterialList[i];
                    unsigned char *color = info->colour;
                    glColor3ub(color[0], color[1], color[2]);

        // Pass in the current vertex of the object (Corner of current face)

        glVertex3f(subMesh->Vertices[index].x, subMesh->Vertices[index].y, subMesh->Vertices[index].z);
  glEnd( );
Sorry for the long post

Share this post

Link to post
Share on other sites

You just solved my problem

Original post by MazyNoc
Do you ever clear the screen? ( glClear(arg); )

Share this post

Link to post
Share on other sites

  • 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!