Code: Select all
#include <GL>
#include <GL>
#include <SDL>
#define window_width 700
#define window_height 700
//keydown booleans
bool key[321];
//process pending events
bool events()
{
SDL_Event event;
if( SDL_PollEvent(&event) )
{
switch( event.type )
{
case SDL_KEYDOWN : key[ event.key.keysym.sym ]=true ; break;
case SDL_KEYUP : key[ event.key.keysym.sym ]=false; break;
case SDL_QUIT : return false; break;
}
}
return true;
}
void recursingRender(float x, float y, int depth, float radius, float color)
{
if(depth > 0)
{
depth--;
recursingRender(x+radius, y+radius, depth, radius/2, color/1.6);
recursingRender(x+radius, y-radius, depth, radius/2, color/1.6);
recursingRender(x-radius, y+radius, depth, radius/2, color/1.6);
recursingRender(x-radius, y-radius, depth, radius/2, color/1.6);
}
//draw entire swastika
for(int i=0; i<4; i++)
{
//for crazy color shimmer +((float)random()/(float)0x7fffffff)*color
glColor3f(color,color,color);
glLineWidth(1);
glBegin(GL_LINE_STRIP);
glVertex2f(x, y);
glVertex2f(x, y+radius);
glVertex2f(x, y+radius);
glVertex2f(x+radius, y+radius);
glEnd();
glRotatef(90, 0, 0, 1);
}
}
void main_loop_function()
{
while( events() )
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0, -5); //for when angle isn't 45
//glTranslatef(0,0, -7); // for when it is 45
recursingRender(0,0,7,1,1);
SDL_GL_SwapBuffers();
//check keypresses
if( key[SDLK_RETURN ] ){ break; }
}
}
//initialze OpenGL perspective matrix
void GL_Setup(int width, int height)
{
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
//glEnable( GL_DEPTH_TEST );
//^^^ enabling this takes away transparency n blending
gluPerspective( 45, (float)width/height, 0.1, 100 );
glMatrixMode( GL_MODELVIEW );
glEnable(GL_LINE_SMOOTH);
}
int main()
{
//initialize SDL with best video mode
SDL_Init(SDL_INIT_VIDEO);
const SDL_VideoInfo* info = SDL_GetVideoInfo();
int vidFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER;
if(info->hw_available)
{
vidFlags |= SDL_HWSURFACE;
} else {
vidFlags |= SDL_SWSURFACE;
}
int bpp = info->vfmt->BitsPerPixel;
SDL_SetVideoMode(window_width, window_height, bpp, vidFlags);
GL_Setup(window_width, window_height);
main_loop_function();
}