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
    Senior Member Regular Contributor nickels's Avatar
    Join Date
    Feb 2000
    Location
    Colorado
    Posts
    284

    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
    Member 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

Similar Threads

  1. OpenGL newbie, depth problem.
    By Airdeth in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 06-10-2018, 02:03 AM
  2. OpenGL 3.1 texture coords - newbie problem[SOLVED]
    By Oz1571 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-06-2009, 11:31 PM
  3. gluOrtho2D and OpenGL 3.1 newbie problem
    By Oz1571 in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-05-2009, 11:15 PM
  4. Simple Newbie Problem
    By Emrah Bozkurt in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-27-2003, 04:30 PM
  5. Newbie Problem
    By Mjollnir in forum OpenGL: macOS
    Replies: 3
    Last Post: 05-29-2003, 10:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean