Hello Guest, please login or register.
Did you miss your activation email?
Login with username, password and session length.

Pages: [1]   Go Down

Author Topic: OpenGL Help  (Read 1101 times)

0 Members and 1 Guest are viewing this topic.

Starforsaken101

Wake the Beast
OpenGL Help
« on: June 04, 2009, 09:58:34 pm »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2577
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.
Logged
  • Starforsaken101's DeviantART
Re: OpenGL Help
« Reply #1 on: June 04, 2009, 10:14:15 pm »
  • (y)(;>.<;)(y)
  • *
  • Reputation: +0/-0
  • Offline Offline
  • Gender: Male
  • Posts: 3293
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.
« Last Edit: June 04, 2009, 10:20:32 pm by TheDarkJay »
Logged
Re: OpenGL Help
« Reply #2 on: June 04, 2009, 10:44:48 pm »
  • *
  • Reputation: +3/-0
  • Offline Offline
  • Gender: Male
  • Posts: 6629
I have plenty of stock opengl 2D rendering code if you want to look through it, it has most things like scaling/rotation/etc.
Logged

Starforsaken101

Wake the Beast
Re: OpenGL Help
« Reply #3 on: June 05, 2009, 01:13:51 am »
  • www.mouffers.com
  • *
  • Reputation: +69/-0
  • Offline Offline
  • Gender: Female
  • Posts: 2577
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.
Logged
  • Starforsaken101's DeviantART
Pages: [1]   Go Up

 


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



Page created in 0.025 seconds with 46 queries.

anything