Sign in to follow this  
raptorstrike

whats going on?

Recommended Posts

ok im totally new to OGL and i know that i added an extra triagle in a matrix with an offset value of 1,0,1 and that im rotating it around but i dont know why the entire tryangle is moving around am i accidently rotating the martix as well? as you can guess this isnt a problem but i would like to know what is going on just for future refrence. heres the code
void RenderScene() 
{
    int i=0;    

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    // Clear The Screen And The Depth Buffer
    glLoadIdentity();                                      // Reset The matrix
    
        //       Position      View       Up Vector
    gluLookAt(0, 0, 6,     0, 0, 0,     0, 1, 0);          // This determines where the camera's position and view is

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // Here we create a static variable that will count forever.  This is used for the rotation degree
    static float rotY = 0;

    // Pass in our current rotation value to glRotatef() for rotation around the Y axis (0, 1, 0)
    glRotatef(rotY, 0, 1, 0);

    // Increase the rotation by 2 degrees
    rotY += 2;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // Below we say that we want to draw triangles
    glBegin (GL_TRIANGLES);                                // This is our BEGIN to draw

        glColor3ub(255, 0, 0);                             // Make the top vertex RED
        glVertex3f(0, 1, 0);                               // Here is the top point of the triangle

        glColor3ub(0, 255, 0);                             // Make the left vertex GREEN
        glVertex3f(-1, 0, 0);                              // Here is the left point of the triangle

        glColor3ub(0, 0, 255);                             // Make the right vertex BLUE
        glVertex3f(1, 0, 0);                               // Here is the right point of the triangle
    glEnd();                                               // This is the END of drawing
    
    glPushMatrix();//i edited this whole block
    
    glTranslatef(1,0,1);
    glRotatef(rotY, 0, 1, 0);
    glBegin(GL_TRIANGLES);
    
    glColor3ub(255,255,255);
    glVertex3f(0,1,0);
    glColor3ub(0,0,0);
    glVertex3f(-1,0,0);
    glColor3ub(125,127,127);
    glVertex3f(1,0,0);
    glPopMatrix();
    glEnd();  //<----------------until here
    

    SDL_GL_SwapBuffers();                                  // Swap the backbuffers to the foreground

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // Call our new function to count and calculate the frames for each second.
    // This needs to be called every time the screen renders so we get a correct frame rate.
    // Because of its static variables inside, we don't need any globals or outside variables.
    CalculateFrameRate();

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

}


every thing done prior to this block wasnt done by me im just editing a tutorial for educational perposes ps the tutorial im using is the FPS tutorial on game tutorials .com

Share this post


Link to post
Share on other sites
try this out ...


void RenderScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
static float yRot = 0;
glRotatef(yRot, 0, 1, 0);
yRot += 2;
glBegin (GL_TRIANGLES);
glColor3ub(255, 0, 0); glVertex3f(0, 1, 0);
glColor3ub(0, 255, 0); glVertex3f(-1, 0, 0);
glColor3ub(0, 0, 255); glVertex3f(1, 0, 0);
glEnd();
glLoadIdentity();
glTranslatef(1, 0, 1);
glRotatef(yRot, 0, 1, 0);
glBegin(GL_TRIANGLES);
glColor3ub(255, 255, 255); glVertex3f(0,1,0);
glColor3ub(0, 0, 0); glVertex3f(-1,0,0);
glColor3ub(125,127,127); glVertex3f(1,0,0);
glEnd();
SDL_GL_SwapBuffers();
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this