PDA

View Full Version : Wow, I didn't know this would come out like it did...



grady
05-22-2001, 05:49 PM
I was just trying to get a little cheesy motion blur effect and out came this surreal trippin thingy http://www.opengl.org/discussion_boards/ubb/smile.gif check it out.



#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

void TimerFunc(int value);
void RenderScene(void);
void ChangeSize(GLsizei w, GLsizei h);

GLfloat i=0;

int main()
{
glutInitDisplayMode(GL_DOUBLE | GLUT_RGB);
glutCreateWindow("hello");
glutReshapeFunc(ChangeSize);
glutDisplayFunc(RenderScene);
glutTimerFunc(40, TimerFunc, 1);
glutMainLoop();
return 0;
}

void TimerFunc(int value)
{
i++;
if(i==360) i=0;
glutPostRedisplay();
glutTimerFunc(40, TimerFunc, 1);
}

void RenderScene(void)
{
int k;
GLubyte Alpha=255;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(0.0f, 0.0f, -100.0f);
glRotatef(i, 1.0, 0.0, 0.0);
glRotatef(360-i, 0.0, 1.0, 0.0);
glRotatef(i, 0.0, 0.0, 1.0);

glColor4ub(255,0,0,Alpha);

for(k=0; k<4; k++)
{
glRotatef(i+0.3, 1.0, 0.0, 0.0);
glRotatef(360-i+0.3, 0.0, 1.0, 0.0);
glRotatef(i+0.3, 0.0, 0.0, 1.0);
glBegin(GL_QUADS);
glVertex3f(20.0f, 20.0f, 0.0f);
glColor4ub(0,255,0,Alpha);
glVertex3f(-20.0f, 20.0f, 0.0f);
glColor4ub(0,0,255,Alpha);
glVertex3f(-20.0f, -20.0f, 0.0f);
glColor4ub(255,255,255,Alpha);
glVertex3f(20.0f, -20.0f, 0.0f);
glEnd();
Alpha-=60;
}

glLoadIdentity();

glutSwapBuffers();
}

void ChangeSize(GLsizei w, GLsizei h)
{
if(h==0) h=1;
glViewport(0,0,w,h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

GLfloat aspect = GLfloat(w)/GLfloat(h);

gluPerspective(45, aspect, 1.0, 1000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}



[This message has been edited by grady (edited 05-23-2001).]

bsperlin
05-23-2001, 04:46 AM
I just ran it and it looked good! If I can steal some time in the next few days I'll put it stereo and watch it! Thanks!
Barry

grady
05-23-2001, 08:36 AM
I'm going to make each succesive plane transparent tonight if i can find my blue book. http://www.opengl.org/discussion_boards/ubb/biggrin.gif

grady
05-23-2001, 11:34 AM
Ok i edited the original. It blends now. It looks a little more intereseting. http://www.opengl.org/discussion_boards/ubb/smile.gif