#include "nebulus.h" GLfloat glthreads_time, glthreads_speed = 20.0f, old_glthreads_speed = 20.0f; gboolean glthreads_first = TRUE; glcoord target_position, target_velocity, target_impulse; particle particle_glthreads[PARTICULE_COUNT]; double hypot(double a, double b) { double t; if (a < 0) a = -a; if (b < 0) b = -b; if (a > b) { t = a; a = b; b = t; } if (b == 0) return(0.); a /= b; return (b * sqrt(1. + a*a)); } void ortho_glthreads(void) { glViewport(0, 0, point_general->WIDTH, point_general->HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, point_general->WIDTH, 0, point_general->HEIGHT, -1, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void perspective_glthreads(void) { glViewport(0, 0, point_general->WIDTH, point_general->HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(90.0f, (GLfloat)640/480, 0.1f, 1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void birth_glthreads(GLint i) { GLfloat angle = (GLfloat)(rand() % 36000) / 100.0f; particle_glthreads[i].currentAge = 0; particle_glthreads[i].maximumAge = rand() % ( particle_glthreads[i].ageRangeMaximum - particle_glthreads[i].ageRangeMinimum + 1) + particle_glthreads[i].ageRangeMinimum; particle_glthreads[i].position = *particle_glthreads[i].target_position; particle_glthreads[i].position.x = particle_glthreads[i].position.x + (GLfloat)(rand() % 100 - 50)*0.002f; particle_glthreads[i].position.y = particle_glthreads[i].position.y + (GLfloat)(rand() % 100 - 50)*0.002f; particle_glthreads[i].position.z = particle_glthreads[i].position.z + (GLfloat)(rand() % 100 - 50)*0.002f; particle_glthreads[i].velocity = *particle_glthreads[i].target_velocity; particle_glthreads[i].velocity.x = particle_glthreads[i].velocity.x + 0.0005f * (GLfloat)cos(angle); particle_glthreads[i].velocity.y = particle_glthreads[i].velocity.y + 0.0005f * (GLfloat)sin(angle); particle_glthreads[i].velocity.z = particle_glthreads[i].velocity.z + 0.0005f * (GLfloat)cos(angle); particle_glthreads[i].impulse = *particle_glthreads[i].target_impulse; particle_glthreads[i].impulse.x += (GLfloat)(rand()%13-6)/4444.0f; particle_glthreads[i].impulse.y += (GLfloat)(rand()%13-6)/4444.0f; particle_glthreads[i].impulse.z += (GLfloat)(rand()%13-6)/4444.0f; } void precalculate_glthreads(void) { int x, y, c, i, j = 0, l = 0; GLfloat k; target_velocity.x = 0.0f; target_velocity.y = -0.002f; target_velocity.z = 0.0f; target_impulse.x = 0.0f; target_impulse.y = 0.0f; target_impulse.z = 0.0f; target_position.x = 0.0f; target_position.y = 1.0f; target_position.z = 0.0f; glthreads_time = 0.0f; for (i = 0; i < PARTICULE_COUNT; i++) { particle_glthreads[i].target_position = &target_position; particle_glthreads[i].target_velocity = &target_velocity; particle_glthreads[i].target_impulse = &target_impulse; particle_glthreads[i].ageRangeMinimum = 1000; particle_glthreads[i].ageRangeMaximum = 2000; particle_glthreads[i].color.x = 1.0f; particle_glthreads[i].color.y = 0.68f; particle_glthreads[i].color.z = 0.32f; birth_glthreads(i); } for (y = 0; y < SIZE_GLTHREADS; y++) { for (x = 0; x < SIZE_GLTHREADS; x++) { buffer_glthreads[j] = buffer_glthreads[j+1] = buffer_glthreads[j+2] = (j^x*y); j += 3; } } for (y = 0; y < SIZE_PARTICULE; y++) { for (x = 0; x < SIZE_PARTICULE; x++) { k = (GLfloat)(1.0f - hypot(x - SIZE_PARTICULE / 2, y - SIZE_PARTICULE / 2) * 2 / SIZE_PARTICULE); if (k < 0) k = 0; c = (GLint)(255.f * k * k); buffer_particule[l] = buffer_particule[l+1] = buffer_particule[l+2] = c; l += 3; } } glthreads_first = FALSE; } void drawglthreads(void) { int i; GLfloat particle_glsize = 0.16f, time_scale = 0.005f; ortho_glthreads(); glMatrixMode(GL_TEXTURE); glPushMatrix(); glTranslatef((GLfloat)glthreads_time*-0.0001f, 0.0f, 0.0f); glRotatef((GLfloat)glthreads_time*-0.01f, 1.0f, 0.0f, 0.0f); glRotatef((GLfloat)glthreads_time*-0.02f, 0.0f, 1.0f, 0.0f); glRotatef((GLfloat)glthreads_time*-0.03f, 0.0f, 0.0f, 1.0f); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, glthreads); glColor4f(0.5f, 0.5f, 1.0f, (GLfloat)glthreads_speed*0.01f); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2i(0, 0); glTexCoord2i(1, 0); glVertex2i(point_general->WIDTH, 0); glTexCoord2i(1, 1); glVertex2i(point_general->WIDTH, point_general->HEIGHT); glTexCoord2i(0, 1); glVertex2i(0, point_general->HEIGHT); glEnd(); glPopMatrix(); glMatrixMode(GL_MODELVIEW); target_position.x = 2.0f * cosf((GLfloat)glthreads_time * time_scale); target_position.y = sinf((GLfloat)glthreads_time * time_scale) + 0.8f; target_position.z = cosf((GLfloat)glthreads_time * (time_scale / 2.0f)) - 1.0f; target_impulse.x = 0.005f * sinf((GLfloat)glthreads_time * time_scale); target_impulse.y = 0.005f * -cosf((GLfloat)glthreads_time * time_scale); target_impulse.z = 0.005f * (sinf((GLfloat)glthreads_time * (time_scale / 2.0f))); perspective_glthreads(); glTranslatef(0.0f, 0.0f, -2.75f); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE); glEnable(GL_TEXTURE_2D); use_particule_texture(); for (i = 0; i < PARTICULE_COUNT; i++) { particle_glthreads[i].currentAge += glthreads_speed; if (particle_glthreads[i].currentAge > particle_glthreads[i].maximumAge) birth_glthreads(i); particle_glthreads[i].position.x += (particle_glthreads[i].velocity.x + particle_glthreads[i].impulse.x) * (GLfloat)glthreads_speed; particle_glthreads[i].position.y += (particle_glthreads[i].velocity.y + particle_glthreads[i].impulse.y) * (GLfloat)glthreads_speed; particle_glthreads[i].position.z += (particle_glthreads[i].velocity.z + particle_glthreads[i].impulse.z) * (GLfloat)glthreads_speed; particle_glthreads[i].impulse.x -= (GLfloat)glthreads_speed * (particle_glthreads[i].impulse.x/512); particle_glthreads[i].impulse.y -= (GLfloat)glthreads_speed * (particle_glthreads[i].impulse.y/512); particle_glthreads[i].impulse.z -= (GLfloat)glthreads_speed * (particle_glthreads[i].impulse.z/512); glColor4f(particle_glthreads[i].color.x-0.16f, particle_glthreads[i].color.y-0.16f, particle_glthreads[i].color.z-0.16f, (1.0f - (GLfloat)particle_glthreads[i].currentAge / (GLfloat)particle_glthreads[i].maximumAge) * 0.1f * (GLfloat)glthreads_speed); glBegin(GL_QUADS); glTexCoord2d(0, 0); glVertex3f(particle_glthreads[i].position.x - particle_glsize, particle_glthreads[i].position.y - particle_glsize, particle_glthreads[i].position.z); glTexCoord2d(1, 0); glVertex3f(particle_glthreads[i].position.x + particle_glsize, particle_glthreads[i].position.y - particle_glsize, particle_glthreads[i].position.z); glTexCoord2d(1, 1); glVertex3f(particle_glthreads[i].position.x + particle_glsize, particle_glthreads[i].position.y + particle_glsize, particle_glthreads[i].position.z); glTexCoord2d(0,1); glVertex3f(particle_glthreads[i].position.x - particle_glsize, particle_glthreads[i].position.y + particle_glsize, particle_glthreads[i].position.z); glEnd(); } ortho_glthreads(); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_DEPTH_TEST); glDisable(GL_TEXTURE_2D); glBegin(GL_QUADS); glColor4f(0.0f, 0.0f, 0.0f, 0.1f*(GLfloat)glthreads_speed); glVertex2d(0, 0); glVertex2d(point_general->WIDTH, 0); glColor4f(0.0f, 0.0f, 0.0f, 0.0); glVertex2d(point_general->WIDTH, point_general->HEIGHT / 6); glVertex2d(0, point_general->HEIGHT / 6); glVertex2d(0, point_general->HEIGHT / 1.2f); glVertex2d(point_general->WIDTH, point_general->HEIGHT / 1.2f); glColor4f(0.0f, 0.0f, 0.0f, 0.1f*(GLfloat)glthreads_speed); glVertex2d(point_general->WIDTH, point_general->HEIGHT); glVertex2d(0, point_general->HEIGHT); glEnd(); } void render_glthreads(void) { glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClear(GL_DEPTH_BUFFER_BIT); glViewport(0, 0, point_general->WIDTH, point_general->HEIGHT); glDisable(GL_BLEND); glDisable(GL_NORMALIZE); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); } void draw_glthreads(void) { glthreads_speed = old_glthreads_speed; glthreads_speed = reduce_vsync(glthreads_speed); glthreads_time += glthreads_speed; render_glthreads(); use_glthreads_texture(); drawglthreads(); }