| | |
help with OPenGl
Please support our Game Development advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
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;
} you never redisplay the scene, for that kind of animation to work you have to redisplay for every frame.
My site, random PM's from people I haven't hear from before will be DELETED
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
"If people are good only because they fear punishment, and hope for reward, then we are a sorry lot indeed.",
"If we knew what it was we were doing, it would not be called research, would it? "-Albert Einstein
![]() |
Similar Threads
- Using OpenGL in Visual C++: Part I (Game Development)
- I need a solution for a opengl thing (C++)
- Randomize number with OpenGL (C++)
- Need advice using openGl with win XP (C++)
- OpenGl project and windows XP (Game Development)
Other Threads in the Game Development Forum
- Previous Thread: C++ on NT
- Next Thread: please help with texture mapping on OpenGl.
Views: 787 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for Game Development
3d advertising ai algorithm ban c++ cambridge camera censorship china competition console development engine fov fpx game gamedevelopment gameprogramming gamer games gaming gauntanamo government graphics idaho in-gameadvertisement intel intellectualproperty l-systems laracroft larrabee lindenmayer live manhunt math mathematics matrix mercenaries microsoft mmorpg modded modern-warfare msn multicore naked news nintendo obama opengl palin physics pirate playstation politics processor projection ps3 rpg search selection software sony spooks spy stephenhawking stocks studio technology terrorism tombraider uk videogame web wii world-of-warcraft xbox xbox-live xbox360






