#include <iostream>
#include <stdlib.h>
#include <GL/glut.h>
void initRendering()
{
glEnable(GL_DEPTH_TEST);
}
void handleKey(unsigned char key, int x, int y)
{
switch(key)
case 27:
exit(0);
}
void handleResize(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,(double)w/(double)h,1,200);
}
void drawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_TRIANGLES);
glVertex3f(5,5,-5);
glVertex3f(10,5,-5);
glVertex3f(7.5,10,-5);
glutSwapBuffers();
}
int main(int argc,char** argv)
{
using namespace std;
glutInit(&argc, argv);
glutInitWindowSize(500,500);
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
glutCreateWindow("OpenGL window");
initRendering();
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKey);
glutReshapeFunc(handleResize);
glutMainLoop();
return 19;
}
Code to draw triangle won't work !
Hi,
I'm just starting with OpenGL, and have appreciable knowledge in C++
I've written a very simple program to draw a triangle which isn't working.
Please kindly tell me what is wrong
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement