All pastes #607837 Raw Edit

opengl sineffect

public cpp v1 · immutable
·published 2007-07-07 22:34 UTC
rendered paste body
#include <SDL/SDL.h>#include <GL/gl.h>#include <GL/glu.h>#include <math.h>float WIDTH = 1024;float HEIGHT = 768;float RWIDTH = 1024;float RHEIGHT = 768;#define GWIDTH 1024#define GHEIGHT 768SDL_Event event;int glSetupView();double rot = 0;int glPutPixel(int xpos,int ypos,int r,int g,int b){	glRotatef(rot,0.0f,0.0f,1.0f);	glBegin(GL_QUADS);		glColor3f(r / 255,g / 255,b / 255);		glVertex2i(xpos,ypos);		glVertex2i(xpos+10,ypos);		glVertex2i(xpos+10,ypos+10);		glVertex2i(xpos,ypos+10);	glEnd();			/*	glBegin(GL_POINTS);		glColor3f(r / 255,g / 255,b / 255);		glVertex2i(xpos,ypos);	glEnd();	*/}int interpol(double a){	return(((a+1) /2) * 255);}int loop(){	static int a = 0;	static int x =0;	while(1) 	{	while(SDL_PollEvent(&event)) 	{		if(event.type == SDL_QUIT) return 0;		if(event.type == SDL_VIDEORESIZE) {			a = 1;			WIDTH = event.resize.w;			HEIGHT = event.resize.h;			RWIDTH = event.resize.w;			RHEIGHT = event.resize.w*.75;		}else if(a == 1) {			a = 0;			glSetupView();		}	}	{		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		glClearColor(0.0f,0.0f,0.0f,0.0f);		glLoadIdentity();		for(int i=-GWIDTH/2;i!=GWIDTH/2;i++) {			glPutPixel(i,interpol(sin((i-x)/57.3)),255,255,255);		}		x++;		rot+=.001;		SDL_GL_SwapBuffers();	}	}	return 0;}int glSetupView(){	SDL_SetVideoMode(WIDTH,HEIGHT,32,SDL_OPENGL | SDL_RESIZABLE);	glViewport(0,0,WIDTH,HEIGHT);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	glOrtho(-GWIDTH/2,GWIDTH/2,-GHEIGHT/2,GHEIGHT/2,		-100000.0f,100000.0f);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	glPointSize(1.0f);	return 0;}int main(int argc,char * argv[]){	SDL_Init(SDL_INIT_VIDEO);	glSetupView();/* main loop */	loop();	SDL_Quit();}