All pastes #818621 Raw Edit

Something

public text v1 · immutable
·published 2007-12-16 12:26 UTC
rendered paste body
#include <GL/gl.h>
#include <SDL/SDL.h>

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

static GLfloat *pixels;
int height = 250;
int width = 250;
float m = 0;

void fill_array(GLfloat *p) {
        int x, y, i =0;
	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 display(void)
{
	glClear (GL_COLOR_BUFFER_BIT);
	glPushMatrix();
	glDrawArrays(GL_POINTS, 0, height * width);
	glPopMatrix();
	SDL_GL_SwapBuffers( );
	fill_array(pixels);
}

void init (void) 
{
    	glClearColor (0.0, 0.0, 0.0, 0.0);
	glViewport( 0, 0, width, height );
  	glMatrixMode(GL_PROJECTION);
  	glLoadIdentity();
	pixels = malloc((height * width * 6) * sizeof(GLfloat) + 1 );
	glInterleavedArrays (GL_C3F_V3F, 0, pixels);
	fill_array(pixels);
}

void reshape(int h, int w) {
	glViewport(0, 0, w, h);
   	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();
	height = h;
	width = w;
	pixels = malloc((height * width * 6) * sizeof(GLfloat) + 1 );
	fill_array(pixels);
	glInterleavedArrays (GL_C3F_V3F, 0, pixels);
}

void process(void) {
	SDL_Event event;
	while(SDL_PollEvent(&event)) {
		switch(event.type) {
			case SDL_VIDEORESIZE: 
				reshape(event.resize.h, event.resize.w);
				break;
			case SDL_QUIT:
				SDL_Quit();
				exit(0);
		}
	}
}

int main(int argc, char** argv)
{
	if(argc > 2) {
		height = atoi(argv[1]);
		width = atoi(argv[2]);
	}

	const SDL_VideoInfo *info = NULL;
	int flags;

	if(SDL_Init(SDL_INIT_VIDEO) < 0) {
		SDL_Quit();
		return 0;
	}
	
	if(!(info = SDL_GetVideoInfo())) {
		SDL_Quit();
		return 0;
	}

	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
	SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
	
	flags = SDL_RESIZABLE | SDL_OPENGL;

	SDL_SetVideoMode(width, height, info->vfmt->BitsPerPixel, flags);

    	init ();
	for(;;) {
		process();
		display();
	}
    	return 0; 
}