Jump to content
  • Advertisement
Sign in to follow this  
rockinruler

OpenGL Code to draw triangle won't work !

This topic is 3026 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!