#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#include <GLUT/glut.h>
const int kWindowWidth = 1024;
const int kWindowHeight = 724;
void InitGL(GLvoid);
void DrawGLScene(void);
GLvoid ReSizeGLScene (int Width, int Height){};
GLfloat rTri = 1.0f; //variable for rotating triangle
GLfloat rQuad; //variable for rotating square
int main (int argc , char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); //Sets up display mode
glutInitWindowSize (kWindowWidth, kWindowHeight); //Sets window size
glutInitWindowPosition (0,0); //Sets the position
glutCreateWindow ("GLUT OpenGL Learning"); //Creates the window
//glutCreateWindow (argv[0]);
InitGL();
glutDisplayFunc(DrawGLScene);
glutReshapeFunc(ReSizeGLScene);
glutMainLoop(); //The main loop
return 0;
}
void DrawGLScene(void) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glTranslatef(0.0f,0.0f,0.0f); //Sets the postion
glRotatef(rTri,0.0f,1.0f,0.0f); //Rotate the triangle
glBegin(GL_TRIANGLES); //Start drawing the triangle
glColor3f (0.0, 0.0, 4.0); //Set the color
glVertex3f( 0.0f, 0.5f, 0.0f); // Top
glColor3f (1.0, 0.0, 0.0); //Set the color
glVertex3f(-0.5f,-0.5f, 0.0f); // Bottom Left
glColor3f (0.0, 1.0, 0.0); //Set the color
glVertex3f( 0.5f,-0.5f, 0.0f); // Bottom Right
glEnd(); // Finished Drawing The Triangle
glLoadIdentity(); //Reset view
glTranslatef(0.5f,0.0f,0.0f); // Move Right 3 Units
glRotatef( rQuad, 1.0f, 0.0f, 0.0f );
glBegin(GL_QUADS); // Draw A Quad
glColor3f (1.0, 0.0, 0.0); //Set the color
glVertex3f(-0.1f,0.1f, 0.0f); // Top Left
glColor3f (0.0, 1.0, 0.0); //Set the color
glVertex3f( 0.1f, 0.1f, 0.0f); // Top Right
glColor3f (3.0, 0.0, 0.0); //Set the color
glVertex3f( 0.1f,-0.1f, 0.0f); // Bottom Right
glColor3f (0.0, 0.0, 4.0); //Set the color
glVertex3f(-0.1f,-0.1f, 0.0f); // Bottom Left
glEnd(); // Done Drawing The Quad
rTri+= 0.2f; //Increase the variable for rotating
rQuad-= 0.15f;
glFlush (); //Clear the buffer
}
void InitGL(GLvoid)
{
glClearColor (0.0, 3.0, 0.0, 0.0); //Clear screen Green
glShadeModel (GL_SMOOTH); //Set the shader to allow smooth colour blending
glClearDepth( 1.0f ); // Depth buffer setup
glEnable( GL_DEPTH_TEST ); // Enable depth testing
glDepthFunc( GL_LEQUAL ); // Type of depth test to do
// Really nice perspective calculations
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
}
🔒 Locked
rotating 2d objects
Advertisement
Original Post
I am havind some trouble about how to rotate objects with NEHE tutorials using project builder on my mac. I can't get it to rotate any for some reason. Well here is my code can someone help me out? Thanks
I'll try that and see if it works.
Thanks
Thanks
I found my problem. Pretty stupid one. The tutorial only rotates it 2 degrees. So I could not see any change. And since it only painted it once it would not add up. I'll make a little timer function that repaints the screen every second or so. Or is there a way it is supposed to repaint it? Well thanks for your help. Bye for now
hello again i made a few updates in your code
ok all your objects are rotating
PS:"pleas rate me :P"
#include <OpenGL/gl.h>#include <OpenGL/glu.h>#include <GLUT/glut.h>const int kWindowWidth = 1024;const int kWindowHeight = 724;void spining(void);void InitGL(GLvoid);void DrawGLScene(void);GLvoid ReSizeGLScene (int Width, int Height){};GLfloat rTri = 1.0f; //variable for rotating triangleGLfloat rQuad; //variable for rotating squareint main (int argc , char** argv){glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); //Sets up display modeglutInitWindowSize (kWindowWidth, kWindowHeight); //Sets window sizeglutInitWindowPosition (0,0); //Sets the positionglutCreateWindow ("GLUT OpenGL Learning"); //Creates the window//glutCreateWindow (argv[0]);InitGL();glutIdleFunc(spining); glutDisplayFunc(DrawGLScene);glutReshapeFunc(ReSizeGLScene); glutMainLoop(); //The main loop return 0;}void DrawGLScene(void) // Here's Where We Do All The Drawing{ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer glLoadIdentity(); // Reset The View glTranslatef(0.0f,0.0f,0.0f); //Sets the postion glRotatef(rTri,0.0f,1.0f,0.0f); //Rotate the triangle glBegin(GL_TRIANGLES); //Start drawing the triangle glColor3f (0.0, 0.0, 4.0); //Set the color glVertex3f( 0.0f, 0.5f, 0.0f); // Top glColor3f (1.0, 0.0, 0.0); //Set the color glVertex3f(-0.5f,-0.5f, 0.0f); // Bottom Left glColor3f (0.0, 1.0, 0.0); //Set the color glVertex3f( 0.5f,-0.5f, 0.0f); // Bottom Right glEnd(); // Finished Drawing The Triangle glLoadIdentity(); //Reset view glTranslatef(0.5f,0.0f,0.0f); // Move Right 3 UnitsglRotatef( rQuad, 1.0f, 0.0f, 0.0f ); glBegin(GL_QUADS); // Draw A Quad glColor3f (1.0, 0.0, 0.0); //Set the color glVertex3f(-0.1f,0.1f, 0.0f); // Top Left glColor3f (0.0, 1.0, 0.0); //Set the color glVertex3f( 0.1f, 0.1f, 0.0f); // Top Right glColor3f (3.0, 0.0, 0.0); //Set the color glVertex3f( 0.1f,-0.1f, 0.0f); // Bottom Right glColor3f (0.0, 0.0, 4.0); //Set the color glVertex3f(-0.1f,-0.1f, 0.0f); // Bottom Left glEnd(); // Done Drawing The Quad glutSwapBuffers(); // glFlush (); //Clear the buffer }void spining(){ rTri+= 0.2f; //Increase the variable for rotating rQuad-= 0.15f; glutPostRedisplay();}void InitGL(GLvoid){ glClearColor (0.0, 3.0, 0.0, 0.0); //Clear screen GreenglShadeModel (GL_SMOOTH); //Set the shader to allow smooth colour blendingglClearDepth( 1.0f ); // Depth buffer setupglEnable( GL_DEPTH_TEST ); // Enable depth testingglDepthFunc( GL_LEQUAL ); // Type of depth test to do // Really nice perspective calculationsglHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );} ok all your objects are rotating
PS:"pleas rate me :P"
Thanks I'll try that. I had them roatating but not constantly just at load time to what angle I wanted.
Thanks again I'd be lost without your guys help
Thanks again I'd be lost without your guys help
Sorry but I am having probelms with texture mapping. I can't find a place that I can load a bmp file for using as a texture. I looked at the one at nehe but it uses the glaux and I am trying to stay away from using that. I also tried downloading the macox/cocoa conversion but it didn't make any sense to me :S. Any one have a place with tutorials? I would really appreciate it. Oh ya is there a way to change the text of a opengl window after it is created! googled it and could not find an answer.
THANKS
[Edited by - vbuser1338 on January 17, 2005 7:48:57 PM]
THANKS
[Edited by - vbuser1338 on January 17, 2005 7:48:57 PM]
SetWindowText(windowHandle,"blah")
Check NeHe for the TGA-loading tutorial.
Check NeHe for the TGA-loading tutorial.
Are you sure it is SetWindowText()?? I had my framework in and the headers but I still get something like undefined function meaning its not delcared anywhere. Do you need the glaux header for that? Becuase I am not using that.
Thanks
Thanks
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement