All pastes #818502 Raw Edit

Someone

public text v1 · immutable
·published 2007-12-16 10:11 UTC
rendered paste body
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <sys/timeb.h>

static GLfloat *pixels;
int height = 250;
int width = 250;
int debug = 1;
float m = 0;
void fill_array(GLfloat *p) {
        int x, y, i =0;
	float dif = sin(rand());
	m+= 0.10;
        for(x = 0; x < width; x++) {
                for(y = 0; y < height; y++) {
                        float temp = 1.0;
                        p[i++] = fabs( sin(m) );
                        p[i++] = fabs( sin(m) );
                        p[i++] = fabs( sin(m) );

                        p[i++] = x;
                        p[i++] = y;
                        p[i++] = 0.0;
                }
        }
}

void idle(void) {
	fill_array(pixels);
	if(debug) {
		int i, x, y;
	        for(i = 0, x = 0, y=0; i < (height * width); i++, x+=6 )
	                printf("%d, %d : %f %f %f\n", (int) pixels[x+3], (int) pixels[x+4], pixels[x], pixels[x+1], pixels[x+2]);
		debug = 0;
	}

        glutPostRedisplay();
}

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();
	
	pixels = malloc((height * width * 6) * sizeof(GLfloat) + 1 );
	glInterleavedArrays (GL_C3F_V3F, 0, pixels);
	gluOrtho2D (0.0, (GLdouble) width, 0.0, (GLdouble) height);
	fill_array(pixels);
}
void reshape(int h, int w) {
	glViewport(0, 0, w, h);
   	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
	height = h;
	width = w;
	pixels = malloc((height * width * 6) * sizeof(GLfloat) + 1 );
	fill_array(pixels);
	glInterleavedArrays (GL_C3F_V3F, 0, pixels);
	glutPostRedisplay();
}

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