Sign in to follow this  
rockinruler

OpenGL Code to draw triangle won't work !

Recommended Posts

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
#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;
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this