Need help to check this simple program

I am a newbie to OpenGL.

I made a simple program with glut.
The program was compiled successfully under
my debian OS with gcc.
While, when I ran it, I got nothing but a blank window.
What’s wrong with my code?

Any advise?
thx in advance.

here is my code:

 
 
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>

static GLint vertices[] = {
		25,25,
		100,325,
		175,25,
		175,325,
		250,25,
		325,325};

static GLfloat colors[] = {
		1.0,0.2,0.2,
		0.2,0.2,1.0,
		0.8,1.0,0.2,
		0.75,0.75,0.75,
		0.35,0.35,0.35,
		0.5,0.5,0.5};

void init(void)
{
	glClearColor(0.0,0.0,0.0,0.0);
	glShadeModel(GL_FLAT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0,400.0,0.0,400.0,-1.0,1.0);
}

void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_POLYGON);
	//	glEnableClientState(GL_COLOR_ARRAY);
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);

	//	glColorPointer(3,GL_FLOAT,0,colors);
		glVertexPointer(2,GL_INT,0,vertices);
		glColorPointer(3,GL_FLOAT,0,colors);
	glEnd();
	//glColor3f(1.0,1.0,1.0);
	//glBegin(GL_POLYGON);
	//	glVertex3f(0.25,0.25,0.0);
	//	glVertex3f(0.75,0.25,0.0);
	//	glVertex3f(0.75,0.75,0.0);
	//	glVertex3f(0.25,0.75,0.0);
	//glEnd();
	
	glFlush();
}

void reshape(int w , int h)
{
	glViewport(0,0,(GLsizei)w,(GLsizei)h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(-500,500,-500,500,-1,1);
}

int main(int argc, char** argv)
{
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
	glutInitWindowSize(500,500);
	glutInitWindowPosition(100,100);
	glutCreateWindow("Example");
	init();
	glutDisplayFunc(display);
	//glutReshapeFunc(reshape);
	glutMainLoop();
	return 0;
}
 

i answered your question in the beginners’ forum.
you shouldn’t cross-post…

I am sorry.

Originally posted by RigidBody:
i answered your question in the beginners’ forum.
you shouldn’t cross-post…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.