ZFGC

Resources => Coding => Topic started by: Starforsaken101 on June 04, 2009, 09:58:34 pm

Title: OpenGL Help
Post by: Starforsaken101 on June 04, 2009, 09:58:34 pm
Hey guys,

So I'm writing a program in C++ with OpenGL (GLUT) and I require assistance since I'm still new to all of this.

I'm basically drawing 2D squares, right? So I draw my little points and it fills out a green or gray square, depending on what I need. However, I would like this square to kind of display on a slant/diagonally (almost looking like a diamond). This really only needs a slight rotation.

How does one rotate a square without it having like, rotating all the time? I just need to turn it a little and it should be fine.
Title: Re: OpenGL Help
Post by: TheDarkJay on June 04, 2009, 10:14:15 pm
Code: [Select]
glPushMatrix();
        glRotatef(theta, 0.0f, 0.0f, 1.0f);
        glBegin(GL_QUADS);
                glColor3f(1.0f, 0.0f, 0.0f);   glVertex2f(-0.8f, -0.8f);
                glColor3f(0.0f, 1.0f, 0.0f);   glVertex2f(-0.8f, 0.8f);
                glColor3f(0.0f, 0.0f, 1.0f);   glVertex2f(0.8f, 0.8f);
                glColor3f(0.0f, 0.0f, 1.0f);   glVertex2f(0.8f, -0.8f);
        glEnd();
glPopMatrix();

where theta is whatever the angle you want to rotate it by is (in Radians, obviously). So long as theta is constant, it will not be rotated any more. It should only 'spin' if you change constantly increment theta.
Title: Re: OpenGL Help
Post by: Infinitus on June 04, 2009, 10:44:48 pm
I have plenty of stock opengl 2D rendering code if you want to look through it, it has most things like scaling/rotation/etc.
Title: Re: OpenGL Help
Post by: Starforsaken101 on June 05, 2009, 01:13:51 am
Code: [Select]
glPushMatrix();
        glRotatef(theta, 0.0f, 0.0f, 1.0f);
        glBegin(GL_QUADS);
                glColor3f(1.0f, 0.0f, 0.0f);   glVertex2f(-0.8f, -0.8f);
                glColor3f(0.0f, 1.0f, 0.0f);   glVertex2f(-0.8f, 0.8f);
                glColor3f(0.0f, 0.0f, 1.0f);   glVertex2f(0.8f, 0.8f);
                glColor3f(0.0f, 0.0f, 1.0f);   glVertex2f(0.8f, -0.8f);
        glEnd();
glPopMatrix();

That is totally awesome! Thanks. I was under the impression that glRotatef rotated it constantly but I guess that's just due to the source code my prof wrote. Thanks!

where theta is whatever the angle you want to rotate it by is (in Radians, obviously). So long as theta is constant, it will not be rotated any more. It should only 'spin' if you change constantly increment theta.

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved