Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: Newbie OpenGL Problem

  1. #1
    Junior Member Newbie
    Join Date
    Sep 2003
    Location
    Sanok / Poland
    Posts
    5

    Newbie OpenGL Problem

    Hi,

    I just started programming in OpenGL. And I decided to write a short little program which has two colored squares and rotates only one of them. This is for Win98 by the way. The thing is, as I am just a beginner, I don't know how to make only one polygon rotate! Here is the code I am using:

    void Display()
    {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glRotatef(1.0, 1.0, 1.0, 0.0);
    glBegin(GL_QUADS);
    glColor3f(1.0, 0.0, 0.0);
    glVertex3f(-2.0, 2.0, 0.0);
    glVertex3f(0.0, 2.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(-2.0, 0.0, 0.0);

    glColor3f(0.0, 1.0, 0.0);
    glVertex3f(0.0, 0.0, 0.0);
    glVertex3f(2.0, 0.0, 0.0);
    glVertex3f(2.0, -2.0, 0.0);
    glVertex3f(0.0, -2.0, 0.0);
    glEnd();

    glFlush();
    SwapBuffers(hDC);

    return;
    }

    This will make both polygons rotate, but I only want the second one to. Someone suggested putting a glLoadIdentity() before the rotate function, but this only produced a GPF on my system. I am using Borland C++ 4.5 on Win98. Hopefully, someone can shed light on a newbie and show me how to make only polygon rotate.

    MuadDib8@home.com

  2. #2
    Member Regular Contributor nickels's Avatar
    Join Date
    Feb 2000
    Location
    Colorado
    Posts
    282

    Re: Newbie OpenGL Problem

    If you only want to rotate object 2:

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    --set up whatever projection you will use
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    draw_object1();
    glRotateToYourHeartsDesire();
    draw_object2();

    I don't know why you got a GPF, but Make sure you set the matrix mode.

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2003
    Location
    Sanok / Poland
    Posts
    5

    Re: Newbie OpenGL Problem

    Nope, no good.
    Putting glLoadIdentity in my code causes an 10H exception in module nv30gl.dll

  4. #4
    Intern Contributor
    Join Date
    Feb 2000
    Location
    France
    Posts
    55

    Re: Newbie OpenGL Problem

    You MUST put a glLoadIdentity(). What do you think glRotatef will modify, if you don't set the matrix before ? If you get an error, either your driver is bad, or your program as errors. As nickels said, make sure you set the matrix mode. If you don't set glMartixMode(), nobody can tell what is going to happen. And for transforming objects, call glMatrixMode(GL_MODELVIEW);
    Also notice that if you put glRotate before the 2 cubes without glLoadIdentity between the first and the second cube, both will rotate. If you wanna rotate only the first, load the identity matrix, call glRotate, draw your cube, then reload the identity and draw the second. If you want to rotate the second, call glLoadIdentity() at first, draw the cube, call glRotatef and then draw the second cube.

    Antoche

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •