#include #include #include #include #include float WIDTH = 1024; float HEIGHT = 768; float RWIDTH = 1024; float RHEIGHT = 768; #define GWIDTH 1024 #define GHEIGHT 768 SDL_Event event; int glSetupView(); double rot = 0; int sinwave[GWIDTH]; int coswave[GWIDTH]; int tanwave[GWIDTH]; int interpol(double a); int radius = 0; int buildarrays() { int x; for(x=0;x!=GWIDTH;x++) { sinwave[x] = interpol(sin((x/57.3))); coswave[x] = interpol(cos((x/57.3))); tanwave[x] = interpol(tan((x/57.3))); } } int glPutPixel(int xpos,int ypos,int r,int g,int b) { 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(); */ } double sin1(int a) { return(sin(a)); } float rand1(int seed) { int i; srand(seed); i = rand() % 10; // printf("%f\n",(float)i/10.0f); return (float)i/10.0; } int interpol(double a) { return(((a+1) /2) * 255); } int getItem(int* array,int index) { int i; if(index < GWIDTH) return array[index]; for(i=1;i*GWIDTH < index;i++); return array[(i*(GWIDTH-1))-index]; } 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(); } if(event.type == SDL_KEYDOWN) { if(event.key.keysym.sym == SDLK_UP) radius+=40; else if (event.key.keysym.sym == SDLK_DOWN) radius-=40; } } 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<=0;i++) { glRotatef(rot,1.0f,1.0f,1.0f); glPutPixel(i, interpol( sin( (i-x)/57.3) + rand1(i) // rand1(time(NULL)) ) + radius , 255,255,255 ); } x++; rot+=.01; SDL_GL_SwapBuffers(); } return 0; } int glSetupView() { 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 ); 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[]) { buildarrays(); SDL_Init(SDL_INIT_VIDEO); glSetupView(); /* main loop */ loop(); SDL_Quit(); }