Code to draw triangle won't work !

Started by
1 comment, last by rockinruler 14 years ago
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;
}
Advertisement
call glEnd() to close your glBegin()
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
That and also the z coords needed change
Ty anyway

This topic is closed to new replies.

Advertisement