943,834 Members | Top Members by Rank

Ad:
Jan 9th, 2009
0

help with OPenGl

Expand Post »
i am writing a code that will rotate the polygon but it seem as if it is not working any help?

#include<iostream>
#include<Gl/glut.h>
#include<cstdlib>
using namespace std;

GLfloat fPent = 0.0; // for rotating pentagon;
GLfloat fSqr = 0.0; // for rotating square;

void handleKeyPress(unsigned char key, int x, int y)
{
		if(key == 26)
			exit(1);
}


 int InitGL(GLvoid)
{
	
	glShadeModel(GL_SMOOTH);//Enable smootheness
	glClearColor(0.0,0.0,0.0,0.5);//Clear any color to black
	glClearDepth(1.0f);//we clear depth.
	glEnable(GL_DEPTH_BUFFER_BIT);//we turn on depthness
	glDepthFunc(GL_LEQUAL);//the type of test we will use for depth test
	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); // 
	glEnable(GL_COLOR_BUFFER_BIT);//we enable color buffer.
	
	return true;
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)	
{
	if(height == 0)
		height = 1;

	glViewport(0, 0, width, height);	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
	
}

void disp()
{
	 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth to what we set it before;
	 glMatrixMode(GL_MODELVIEW);
	 glLoadIdentity();

	glTranslatef(-1.0,0.0f,-6.0f);
	glRotatef(fPent,1.0f,0.0f,0.0f);

	glBegin(GL_TRIANGLES);					// Start Drawing A Triangle
		glColor3f(1.0f,0.0f,0.0f);			// Set Top Point Of Triangle To Red
		glVertex3f( 0.0f, 1.0f, 0.0f);			// First Point Of The Triangle
		glColor3f(0.0f,1.0f,0.0f);			// Set Left Point Of Triangle To Green
		glVertex3f(-1.0f,-1.0f, 0.0f);			// Second Point Of The Triangle
		glColor3f(0.0f,0.0f,1.0f);			// Set Right Point Of Triangle To Blue
		glVertex3f( 1.0f,-1.0f, 0.0f);			// Third Point Of The Triangle
	glEnd();

		glLoadIdentity();

		glTranslatef(1.0f,0.0f,1.0f);
		glRotatef(fSqr,1.0f,0.0f,0.0f);

	glBegin(GL_QUADS);
	
		glColor3f(0.0f,0.0f,0.0f);
	glVertex3f(-1.0f, 1.0f, -10.0f);	
		glColor3f(0.0f,1.0f,0.0f);
	glVertex3f( 1.0f, 1.0f, -10.0f);	
		glColor3f(0.0f,0.0f,1.0f);
	glVertex3f( 1.0f,-1.0f, -10.0f);	
		glColor3f(0.6f,0.4f,1.0f);
	glVertex3f(-1.0f,-1.0f, -10.0f);	
		glEnd();

		

		glutSwapBuffers();
		
		fPent += 1.0;
		fSqr -= 0.4;
		

		glFlush();
		
}


int main(int argc,char**argv)
{
		glutInit(&argc,argv);
		glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);
		glutInitWindowSize(500,500);
		glutInitWindowPosition(300,100);
		glutCreateWindow("My first polygons with colors and rotations");
		glEnable(GL_DEPTH_TEST);
		glutDisplayFunc(disp);
		glutKeyboardFunc(handleKeyPress);
		glutReshapeFunc(ReSizeGLScene);

		glutMainLoop();

		return 0;
}
Similar Threads
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,862 posts
since Dec 2008
Jan 14th, 2009
0

Re: help with OPenGl

you never redisplay the scene, for that kind of animation to work you have to redisplay for every frame.
Reputation Points: 73
Solved Threads: 22
Posting Pro in Training
sciwizeh is offline Offline
423 posts
since Jun 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Game Development Forum Timeline: C++ on NT
Next Thread in Game Development Forum Timeline: please help with texture mapping on OpenGl.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC