All pastes #817018 Raw Edit

Untitled

public text v1 · immutable
·published 2007-12-15 04:22 UTC
rendered paste body
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>
static GLint *vertices;
static GLfloat *colors;
int height = 250;
int width = 250;

void display(void)
{
	glClear (GL_COLOR_BUFFER_BIT);
	glPushMatrix();
	glDrawArrays(GL_POINTS, 0, height * width);
	glPopMatrix();
	glutSwapBuffers();
}

void init (void) 
{
    	glClearColor (0.0, 0.0, 0.0, 0.0);
  	glMatrixMode(GL_PROJECTION);
  	glLoadIdentity();
	
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_VERTEX_ARRAY);
	vertices = malloc((height * width * 2) * sizeof(GLint) + 1);
	colors = malloc((height * width * 3) * sizeof(GLfloat) + 1);
	
	glColorPointer (3, GL_FLOAT, 0, colors);
	glVertexPointer (2, GL_INT, 0, vertices);
	
	gluOrtho2D (0.0, (GLdouble) 250, 0.0, (GLdouble) 250);
	int x, y, i;
	for(x = 0, i = 0, y=0; x < height * width * 2; x+=2, i++) {
		if((i/2)%250 == 0) y++;
                vertices[x] = i%250;
                vertices[x+1] = y;
        }
}
void reshape(int h, int w) {
   	glViewport (0, 0, (GLsizei) w, (GLsizei) h);
   	glMatrixMode (GL_PROJECTION);
   	glLoadIdentity ();
   	gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
	height = h;
	width = w;
        vertices = malloc((height * width * 2) * sizeof(GLint) + 1);
	int x, i, y;
        for(x = 0, i = 0, y=0; x < height * width * 2; x+=2, i++) {
                if((i/2)%250 == 0) y++;
                vertices[x] = i%250;
                vertices[x+1] = y;
        }
	colors = malloc((height * width * 3) * sizeof(GLfloat) + 1);
}
void idle(void) {
	int x, y, i;
        for(x = 0; x < height * width * 3 ; x+=3) {
                colors[x] = rand()/(float)RAND_MAX;
                colors[x+1] = rand()/(float)RAND_MAX;
                colors[x+2] = rand()/(float)RAND_MAX;
        }
	glutPostRedisplay();																        
}

int main(int argc, char** argv)
{
	srand(time(0));
    	glutInit(&argc, argv);
    	glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
    	glutInitWindowSize (height, width); 
    	glutInitWindowPosition (100, 100);
    	glutCreateWindow ("hello");
    	init ();
    	glutDisplayFunc(display);
	glutIdleFunc(idle);
	glutReshapeFunc(reshape); 
    	glutMainLoop();
    	return 0; 
}