Page 1 of 1
My new Swastafractal
Posted: Sat Nov 10, 2007 10:18 pm
by JS Lemming
So the other day in lunch we somehow got onto the subject of the old swastafractal I made years ago. I don't know if I ever posted it on these boards. But anyway, I long since lost it and it was written in blitz anyway so I didn't miss it.
I had some spare time today so I thought I'd make a new one. This time with openGL so I can actually see if setting it up for linux is a pain or not. It's not.
So anyway this is the kinda cool output:
I noticed some funky looking shapes in the background so I passed it through a filter and now you can see all the random ass integral signs. Weird.
And finally just to add some seasoning, cranked the color:
What do you think?
PS: Here's the code if you like that kind of stuff.
Click here to see the hidden message (It might contain spoilers)
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();
}
Posted: Sat Nov 10, 2007 11:18 pm
by Falco Girgis
Whoah, that's pretty badass. I really need to get into OpenGL. Badly...
Posted: Sun Nov 11, 2007 12:05 am
by JS Lemming
Thanks. OpenGl is great. There's just something "right" about it. I don't know how to describe it.
Posted: Sun Nov 11, 2007 10:00 am
by Falco Girgis
How easy would it be to use it for things I'm doing with the Dreamcast?
Use it for 2D sprite rendering, but with the additional features of a polygon. Is it hard? I know that Direct3D has its own additional 2D library, but I've heard getting the same functionality out of OpenGL is pretty easy.
Posted: Sun Nov 11, 2007 2:51 pm
by JS Lemming
I'd say very easy. As far as I can tell you just disable some stuff that 3D uses and then bind a texture to a rectangle polygon. But keep in mind I've only read to chapter 2 in the
Red Book so I have a lot to learn.
Posted: Sun Nov 11, 2007 11:09 pm
by Falco Girgis
Okay, I just got the OpenGL SuperBible today. I've been dicking around quite a bit. The only problem is that they use GLUT to interface with OpenGL rather than SDL.
After much thought, I've decided that I'd MUCH rather roll with SDL. I finally figured out how to do all their GLUT bullcrap in SDL. Oh, then I compiled your swastika fractal demo and screwed around with it for awhile.
Since I'm rewriting the engine on DS, I'm trying to get it platform independent. I want to be able to edit something, and then compile it, and have the identical thing running on DC and PC.
I agree, OpenGL is badass.
EDIT: I have a Dream. Look in the Dead Sky forum.
Posted: Mon Nov 12, 2007 12:25 am
by JS Lemming
Yeah I agree, SDL owns Glut so far as I can tell. Plus I know some SDL so that kinda nudged my decision making.
Posted: Mon Nov 12, 2007 12:53 am
by Arce
Since I'm rewriting the engine on DS, I'm trying to get it platform independent. I want to be able to edit something, and then compile it, and have the identical thing running on DC and PC.
Wow, that's gotta be pretty fucking epic...Rewriting a Dreamcast game for a console with about 1/10th the specs...Seriously, good luck with that.
Or maybe you meant DeadSky?
PS: I have every Ebook known to man. That OpenGL book he speaks of...*raises hand*