New version of the lensflare editor.
Now supports import and export to ".lensflare" files.
- If you press 'e' it will export the current lensflare to lf0.lensflare.
- If you press'i' it will import the file lf0.lensflare
In the file, each effect(line) has the next structure:
{is_used?, size, velocity, color r, color g, color b}
Colors are useless right now.
Here the code:
Code:
/*
Raydium - CQFD Corp.
http://raydium.org/
Released under both BSD license and Lesser GPL library license.
See "license.txt" file.
*/
// This file is a default skeleton. Replace all [ ... ] sections with yours.
// Have fun !
#include "raydium/index.c"
#define RAYDIUM_MAX_LENS_FLARE 5
float raydium_lensflare_pos[RAYDIUM_MAX_LENS_FLARE][3];
int raydium_lensflare_type[RAYDIUM_MAX_LENS_FLARE];
float raydium_lensflare_color[RAYDIUM_MAX_LENS_FLARE][3];
int raydium_lensflare_use[RAYDIUM_MAX_LENS_FLARE];
float raydium_lensflare_time_to_full[RAYDIUM_MAX_LENS_FLARE];
int raydium_lensflare_texture[6];
float raydium_lensflare_time_shown[RAYDIUM_MAX_LENS_FLARE];
int mode=0; //0=camera, 1=editor
#define RAYDIUM_MAX_FX 10
int raydium_lensflare_fx[RAYDIUM_MAX_LENS_FLARE][RAYDIUM_MAX_FX];
float raydium_lensflare_fxcolor[RAYDIUM_MAX_LENS_FLARE][RAYDIUM_MAX_FX][3];
float raydium_lensflare_fxvelocity[RAYDIUM_MAX_LENS_FLARE][RAYDIUM_MAX_FX];
float raydium_lensflare_fxsize[RAYDIUM_MAX_LENS_FLARE][RAYDIUM_MAX_FX];
void gui_feed(void);
void gui_create(void);
void raydium_lensflare_reset(int id)
{
int a=id;
int b;
memset(raydium_lensflare_pos[a],0,3);
memset(raydium_lensflare_color[a],0,3);
raydium_lensflare_type[a]=0;
raydium_lensflare_use[a]=0;
raydium_lensflare_time_to_full[a]=0.5f;
raydium_lensflare_time_shown[a]=0.0f;
for(b=0;b<RAYDIUM_MAX_FX;b++)
{
raydium_lensflare_fx[a][b]=1;
raydium_lensflare_fxcolor[a][b][0]=1;
raydium_lensflare_fxcolor[a][b][1]=1;
raydium_lensflare_fxcolor[a][b][2]=1;
raydium_lensflare_fxvelocity[a][b]=1;
}
}
void raydium_lensflare_import(int id, char *filename)
{
FILE *fp;
int version=0;
int ret;
char var[RAYDIUM_MAX_NAME_LEN];
char val_s[RAYDIUM_MAX_NAME_LEN];
GLfloat val_f[5];
int size;
if(id<0 || id>RAYDIUM_MAX_LENS_FLARE)
{
return;;
}
if((fp=raydium_file_fopen(filename,"r")))
{
raydium_log("reading lensflare file: %s",filename);
while( (ret=raydium_parser_read(var,val_s,val_f,&size,fp))!=RAYDIUM_PARSER_TYPE_EOF)
{
//get data
//version
if(ret==RAYDIUM_PARSER_TYPE_FLOAT && size==1 && strcmp(var,"version")==0)
{
version=(int)val_f[0];
raydium_log("version: %d",version);
if(version!=1)
{
raydium_lensflare_reset(id);
break;
}
}
//anamorphic
if(ret==RAYDIUM_PARSER_TYPE_FLOAT && strcmp(var,"anamorphic")==0)
{
raydium_log("there are %f elements here?????",size);
raydium_lensflare_fx[id][0]=(int)val_f[0];
raydium_lensflare_fxsize[id][0]=val_f[1];
raydium_lensflare_fxvelocity[id][0]=val_f[2];
raydium_lensflare_fxcolor[id][0][0]=val_f[3];
raydium_lensflare_fxcolor[id][0][1]=val_f[4];
raydium_lensflare_fxcolor[id][0][2]=val_f[5];
}
//rays
if(ret==RAYDIUM_PARSER_TYPE_FLOAT && strcmp(var,"rays")==0)
{
raydium_log("there are %f elements here?????",size);
raydium_lensflare_fx[id][1]=(int)val_f[0];
raydium_lensflare_fxsize[id][1]=val_f[1];
raydium_lensflare_fxvelocity[id][1]=val_f[2];
raydium_lensflare_fxcolor[id][1][0]=val_f[3];
raydium_lensflare_fxcolor[id][1][1]=val_f[4];
raydium_lensflare_fxcolor[id][1][2]=val_f[5];
}
//halo
if(ret==RAYDIUM_PARSER_TYPE_FLOAT && strcmp(var,"halo")==0)
{
raydium_log("there are %f elements here?????",size);
raydium_lensflare_fx[id][2]=(int)val_f[0];
raydium_lensflare_fxsize[id][2]=val_f[1];
raydium_lensflare_fxvelocity[id][2]=val_f[2];
raydium_lensflare_fxcolor[id][2][0]=val_f[3];
raydium_lensflare_fxcolor[id][2][1]=val_f[4];
raydium_lensflare_fxcolor[id][2][2]=val_f[5];
}
//star streak
if(ret==RAYDIUM_PARSER_TYPE_FLOAT && strcmp(var,"streak")==0)
{
raydium_log("there are %f elements here?????",size);
raydium_lensflare_fx[id][3]=(int)val_f[0];
raydium_lensflare_fxsize[id][3]=val_f[1];
raydium_lensflare_fxvelocity[id][3]=val_f[2];
raydium_lensflare_fxcolor[id][3][0]=val_f[3];
raydium_lensflare_fxcolor[id][3][1]=val_f[4];
raydium_lensflare_fxcolor[id][3][2]=val_f[5];
}
//red dot
if(ret==RAYDIUM_PARSER_TYPE_FLOAT && strcmp(var,"reddot")==0)
{
raydium_log("there are %f elements here?????",size);
raydium_lensflare_fx[id][4]=(int)val_f[0];
raydium_lensflare_fxsize[id][4]=val_f[1];
raydium_lensflare_fxvelocity[id][4]=val_f[2];
raydium_lensflare_fxcolor[id][4][0]=val_f[3];
raydium_lensflare_fxcolor[id][4][1]=val_f[4];
raydium_lensflare_fxcolor[id][4][2]=val_f[5];
}
//glow
if(ret==RAYDIUM_PARSER_TYPE_FLOAT && strcmp(var,"glow")==0)
{
raydium_log("there are %f elements here?????",size);
raydium_lensflare_fx[id][5]=(int)val_f[0];
raydium_lensflare_fxsize[id][5]=val_f[1];
raydium_lensflare_fxvelocity[id][5]=val_f[2];
raydium_lensflare_fxcolor[id][5][0]=val_f[3];
raydium_lensflare_fxcolor[id][5][1]=val_f[4];
raydium_lensflare_fxcolor[id][5][2]=val_f[5];
}
//blueglow
if(ret==RAYDIUM_PARSER_TYPE_FLOAT && strcmp(var,"blueglow")==0)
{
raydium_log("there are %f elements here?????",size);
raydium_lensflare_fx[id][6]=(int)val_f[0];
raydium_lensflare_fxsize[id][6]=val_f[1];
raydium_lensflare_fxvelocity[id][6]=val_f[2];
raydium_lensflare_fxcolor[id][6][0]=val_f[3];
raydium_lensflare_fxcolor[id][6][1]=val_f[4];
raydium_lensflare_fxcolor[id][6][2]=val_f[5];
}
}
fclose(fp);
gui_feed();
}
/*
{
//anamorphic
fprintf(file,"anamorphic.size=%f\n",raydium_lensflare_fxsize[0]);
fprintf(file,"anamorphic.velocity=%f\n",raydium_lensflare_fxvelocity[0]);
fprintf(file,"anamoprhic.color={%f,%f,%f}\n",raydium_lensflare_fxcolor[0][0],raydium_lensflare_fxcolor[0][1],raydium_lensflare_fxcolor[0][2]);
//Rays
fprintf(file,"rays.use=%d\n",raydium_lensflare_fx[1]);
fprintf(file,"rays.size=%f\n",raydium_lensflare_fxsize[1]);
fprintf(file,"rays.velocity=%f\n",raydium_lensflare_fxvelocity[1]);
fprintf(file,"rays.color={%f,%f,%f}\n",raydium_lensflare_fxcolor[1][0],raydium_lensflare_fxcolor[1][1],raydium_lensflare_fxcolor[1][2]);
//Halo
fprintf(file,"halo.use=%d\n",raydium_lensflare_fx[2]);
fprintf(file,"halo.size=%f\n",raydium_lensflare_fxsize[2]);
fprintf(file,"halo.velocity=%f\n",raydium_lensflare_fxvelocity[2]);
fprintf(file,"halo.color={%f,%f,%f}\n",raydium_lensflare_fxcolor[2][0],raydium_lensflare_fxcolor[2][1],raydium_lensflare_fxcolor[2][2]);
//Star Streak
fprintf(file,"streak.use=%d\n",raydium_lensflare_fx[3]);
fprintf(file,"streak.size=%f\n",raydium_lensflare_fxsize[3]);
fprintf(file,"streak.velocity=%f\n",raydium_lensflare_fxvelocity[3]);
fprintf(file,"streak.color={%f,%f,%f}\n",raydium_lensflare_fxcolor[3][0],raydium_lensflare_fxcolor[3][1],raydium_lensflare_fxcolor[3][2]);
//red dot
fprintf(file,"reddot.use=%d\n",raydium_lensflare_fx[4]);
fprintf(file,"reddot.size=%f\n",raydium_lensflare_fxsize[4]);
fprintf(file,"reddot.velocity=%f\n",raydium_lensflare_fxvelocity[4]);
fprintf(file,"reddot.color={%f,%f,%f}\n",raydium_lensflare_fxcolor[4][0],raydium_lensflare_fxcolor[4][1],raydium_lensflare_fxcolor[4][2]);
//Glow
fprintf(file,"glow.use=%d\n",raydium_lensflare_fx[5]);
fprintf(file,"glow.size=%f\n",raydium_lensflare_fxsize[5]);
fprintf(file,"glow.velocity=%f\n",raydium_lensflare_fxvelocity[5]);
fprintf(file,"glow.color={%f,%f,%f}\n",raydium_lensflare_fxcolor[5][0],raydium_lensflare_fxcolor[5][1],raydium_lensflare_fxcolor[5][2]);
//Blue Glow
fprintf(file,"blueglow.use=%d\n",raydium_lensflare_fx[6]);
fprintf(file,"blueglow.size=%f\n",raydium_lensflare_fxsize[6]);
fprintf(file,"blueglow.velocity=%f\n",raydium_lensflare_fxvelocity[6]);
fprintf(file,"blueglow.color={%f,%f,%f}\n",raydium_lensflare_fxcolor[6][0],raydium_lensflare_fxcolor[6][1],raydium_lensflare_fxcolor[6][2]);
//more will come?
fclose(file);
}*/
}
void raydium_lensflare_export(int id,char *filename,int overwrite)
{
FILE *file;
//check file
if(raydium_file_readable(filename) && !overwrite)
{
raydium_log("ERROR: File already exists!!!");
return;
}
if(raydium_file_readable(filename) && overwrite)
{
raydium_log("WARNING: Overwriting file");
}
if((file=raydium_file_fopen(filename,"w")))
{
fprintf(file,"Lensflare definition\n");
fprintf(file,"version=1\n");
fprintf(file,"id=%d\n",id);
//anamorphic
fprintf(file,"anamorphic={ %f, %f, %f, %f, %f, %f}\n",(float)raydium_lensflare_fx[id][0],raydium_lensflare_fxsize[id][0],raydium_lensflare_fxvelocity[id][0],raydium_lensflare_fxcolor[id][0][0],raydium_lensflare_fxcolor[id][0][1],raydium_lensflare_fxcolor[id][0][2]);
//Rays
fprintf(file,"rays={ %f, %f, %f, %f, %f, %f}\n",(float)raydium_lensflare_fx[id][1],raydium_lensflare_fxsize[id][1],raydium_lensflare_fxvelocity[id][1],raydium_lensflare_fxcolor[id][1][0],raydium_lensflare_fxcolor[id][1][1],raydium_lensflare_fxcolor[id][1][2]);
//Halo
fprintf(file,"halo={ %f, %f, %f, %f, %f, %f}\n",(float)raydium_lensflare_fx[id][2],raydium_lensflare_fxsize[id][2],raydium_lensflare_fxvelocity[id][2],raydium_lensflare_fxcolor[id][2][0],raydium_lensflare_fxcolor[id][2][1],raydium_lensflare_fxcolor[id][2][2]);
//Star Streak
fprintf(file,"streak={ %f, %f, %f, %f, %f, %f}\n",(float)raydium_lensflare_fx[id][3],raydium_lensflare_fxsize[id][3],raydium_lensflare_fxvelocity[id][3],raydium_lensflare_fxcolor[id][3][0],raydium_lensflare_fxcolor[id][3][1],raydium_lensflare_fxcolor[id][3][2]);
//red dot
fprintf(file,"reddot={ %f, %f, %f, %f, %f, %f}\n",(float)raydium_lensflare_fx[id][4],raydium_lensflare_fxsize[id][4],raydium_lensflare_fxvelocity[id][4],raydium_lensflare_fxcolor[id][4][0],raydium_lensflare_fxcolor[id][4][1],raydium_lensflare_fxcolor[id][4][2]);
//Glow
fprintf(file,"glow={ %f, %f, %f, %f, %f, %f}\n",(float)raydium_lensflare_fx[id][5],raydium_lensflare_fxsize[id][5],raydium_lensflare_fxvelocity[id][5],raydium_lensflare_fxcolor[id][5][0],raydium_lensflare_fxcolor[id][5][1],raydium_lensflare_fxcolor[id][5][2]);
//Blue Glow
fprintf(file,"blueglow={ %f, %f, %f, %f, %f, %f}\n",(float)raydium_lensflare_fx[id][6],raydium_lensflare_fxsize[id][6],raydium_lensflare_fxvelocity[id][6],raydium_lensflare_fxcolor[id][6][0],raydium_lensflare_fxcolor[id][6][1],raydium_lensflare_fxcolor[id][6][2]);
//more will come?
fclose(file);
}
//save data
//end
}
int raydium_point_is_occluded(float x, float y, float z)
{
//code from nehe
GLint viewport[4]; // Space For Viewport Data
GLdouble mvmatrix[16], projmatrix[16]; // Space For Transform Matrix
GLdouble winx, winy, winz; // Space For Returned Projected Coords
GLdouble flareZ; // Here We Will Store The Transformed Flare Z
GLfloat bufferZ; // Here We Will Store The Read Z From The Buffer
glGetIntegerv (GL_VIEWPORT, viewport); // Get Actual Viewport
glGetDoublev (GL_MODELVIEW_MATRIX, mvmatrix); // Get Actual Model View Matrix
glGetDoublev (GL_PROJECTION_MATRIX, projmatrix); // Get Actual Projection Matrix
// This Asks OGL To Guess The 2D Position Of A 3D Point Inside The Viewport
gluProject(x, y, z, mvmatrix, projmatrix, viewport, &winx, &winy, &winz);
//flareZ=raydium_math_point_unproject_3D(x,y,z,&winx,&winy);
flareZ = winz;
// We Read Back One Pixel From The Depth Buffer (Exactly Where Our Flare Should Be Drawn)
glReadPixels(winx, winy,1,1,GL_DEPTH_COMPONENT, GL_FLOAT, &bufferZ);
// If The Buffer Z Is Lower Than Our Flare Guessed Z Then Don't Draw
// This Means There Is Something In Front Of Our Flare
if (bufferZ < flareZ)
return 1;
else
return 0;
}
void raydium_lensflare_init(void)
{
int a,b;
for(a=0;a<RAYDIUM_MAX_LENS_FLARE;a++)
{
memset(raydium_lensflare_pos[a],0,3);
memset(raydium_lensflare_color[a],0,3);
raydium_lensflare_type[a]=0;
raydium_lensflare_use[a]=0;
raydium_lensflare_time_to_full[a]=0.5f;
raydium_lensflare_time_shown[a]=0.0f;
for(b=0;b<RAYDIUM_MAX_FX;b++)
{
raydium_lensflare_fx[a][b]=1;
raydium_lensflare_fxcolor[a][b][0]=1;
raydium_lensflare_fxcolor[a][b][1]=1;
raydium_lensflare_fxcolor[a][b][2]=1;
raydium_lensflare_fxvelocity[a][b]=1;
}
}
//prepare textures
raydium_lensflare_texture[0]=raydium_texture_load("lensflare1.tga");
raydium_lensflare_texture[1]=raydium_texture_load("lensflare2.tga");
raydium_lensflare_texture[2]=raydium_texture_load("lensflare-streaks.tga");
raydium_lensflare_texture[3]=raydium_texture_load("lensflare-halo.tga");
raydium_lensflare_texture[4]=raydium_texture_load("lensflare-rays.tga");
raydium_lensflare_texture[5]=raydium_texture_load("lensflare-anamorphic.tga");
//setting then to blend
raydium_texture_blended[raydium_lensflare_texture[0]]=1;
raydium_texture_blended[raydium_lensflare_texture[1]]=1;
raydium_texture_blended[raydium_lensflare_texture[2]]=1;
raydium_texture_blended[raydium_lensflare_texture[3]]=1;
raydium_texture_blended[raydium_lensflare_texture[4]]=1;
raydium_texture_blended[raydium_lensflare_texture[5]]=1;
//setting texture to be HDR'able
raydium_hdr_texture(raydium_lensflare_texture[0],1);
raydium_hdr_texture(raydium_lensflare_texture[1],1);
raydium_hdr_texture(raydium_lensflare_texture[2],1);
raydium_hdr_texture(raydium_lensflare_texture[3],1);
raydium_hdr_texture(raydium_lensflare_texture[4],1);
raydium_hdr_texture(raydium_lensflare_texture[5],1);
}
void raydium_lensflare_on(int a)
{
raydium_lensflare_use[a]=1;
}
void raydium_lensflare_off(int a)
{
raydium_lensflare_use[a]=0;
}
void raydium_lensflare_move_3f(int a, float x, float y, float z)
{
raydium_lensflare_pos[a][0]=x;
raydium_lensflare_pos[a][1]=y;
raydium_lensflare_pos[a][2]=z;
}
void raydium_lensflare_move_relative_3f(int a, float x, float y, float z)
{
raydium_lensflare_pos[a][0]+=x;
raydium_lensflare_pos[a][1]+=y;
raydium_lensflare_pos[a][2]+=z;
}
void raydium_lensflare_color_set(int a, float r, float g, float b)
{
raydium_lensflare_color[a][0]=r;
raydium_lensflare_color[a][1]=g;
raydium_lensflare_color[a][2]=b;
}
void raydium_lensflare_type_set(int a, int type)
{
raydium_lensflare_type[a]=type;
}
void raydium_osd_draw_quad(int tex,float x1,float y1,float x2, float y2, float anglerads)
{
float tx,ty;
raydium_osd_start();
tx=x1+((x2-x1)/2.0f);
ty=y1+((y2-y1)/2.0f);
raydium_texture_current_set(tex);
raydium_rendering_internal_prepare_texture_render(tex);
glColor4fv(raydium_osd_color);
glTranslatef(tx,ty,0);
glRotatef(anglerads,0,0,1);
glBegin(GL_QUADS);
glTexCoord2f(0,0);glVertex3f(tx-x1,ty-y1,0);
glTexCoord2f(1,0);glVertex3f(tx-x2,ty-y1,0);
glTexCoord2f(1,1);glVertex3f(tx-x2,ty-y2,0);
glTexCoord2f(0,1);glVertex3f(tx-x1,ty-y2,0);
glEnd();
glRotatef(-anglerads,0,0,1);
glTranslatef(-tx,-ty,0);
raydium_rendering_internal_restore_render_state();
raydium_osd_stop();
}
void raydium_lensflare_draw(int a)
{
float cx,cy; //center of screen
float vx,vy; //effect normalised vector
float phase,phase2,phase5,phase10;
float posx,posy;
float lf[3];
float dist;
float size;
float mulpos;
float turn;
float oldcolor[4];
static float pt;
float anam; //anamorphic proportion
static float giro=0;
giro+=4*raydium_frame_time;
phase=cosf(giro);
phase2=cosf(giro/2.0f);
phase5=cosf(giro/5.0f);
phase10=cosf(giro/10.0f);
if(raydium_lensflare_use[a])
{
//get 2dproyection of the point
lf[0]=raydium_lensflare_pos[a][0];
lf[1]=raydium_lensflare_pos[a][1];
lf[2]=raydium_lensflare_pos[a][2];
if(raydium_math_point_unproject_3D(lf[0],lf[1],lf[2],&posx,&posy))
{
if(!raydium_point_is_occluded(lf[0],lf[1],lf[2]))
{
//storing OSD color
memcpy(oldcolor,(char *)raydium_osd_color,4*sizeof(float));
pt+=raydium_frame_time*7.0f;
if(pt>=1)pt=1.0f;
//center of screen
cx=50;
cy=50;
//geting vector
vx=((float)posx-(float)cx);
vy=((float)posy-(float)cy);
//normalising
dist=sqrt((vx*vx)+(vy*vy));
vx=vx/dist;
vy=vy/dist;
//vx,vy are now normalized
glBlendFunc(GL_ONE, GL_ONE);
if(raydium_lensflare_fx[a][5])
{
//Glow
size=(float)(40.0f*(1.0f-(dist/75.0f)));
size=raydium_lensflare_fxsize[a][5]*size*pt;
mulpos=dist;
turn=raydium_lensflare_fxvelocity[a][5]*(-giro);
raydium_osd_color_rgba(1,1,0.9,1);
raydium_osd_draw_quad(raydium_lensflare_texture[0],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
}
if(raydium_lensflare_fx[a][1])
{
//Rays1
size=(float)(60.0f*(1.0f-(dist/75.0f)));
size=raydium_lensflare_fxsize[a][1]*size*pt;
mulpos=dist;
turn=raydium_lensflare_fxvelocity[a][1]*giro*0.5f;
raydium_osd_color_rgba(1,1,1,0.2);
raydium_osd_draw_quad(raydium_lensflare_texture[4],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
//Rays2
size=(float)(60.0f*(1.0f-(dist/75.0f)));
size=raydium_lensflare_fxsize[a][1]*size*pt;
mulpos=dist;
turn=raydium_lensflare_fxvelocity[a][1]*(-giro)*0.5f;
raydium_osd_color_rgba(1,1,1,0.2);
raydium_osd_draw_quad(raydium_lensflare_texture[4],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
//Rays3
size=(float)(60.0f*(1.0f-(dist/75.0f)));
size=raydium_lensflare_fxsize[a][1]*size*pt;
mulpos=dist;
turn=raydium_lensflare_fxvelocity[a][1]*giro*0.6f;
raydium_osd_color_rgba(1,1,1,0.2);
raydium_osd_draw_quad(raydium_lensflare_texture[4],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
//Rays4
size=(float)(60.0f*(1.0f-(dist/75.0f)));
size=raydium_lensflare_fxsize[a][1]*size*pt;
mulpos=dist;
turn=raydium_lensflare_fxvelocity[a][1]*(-giro)*0.6f;
raydium_osd_color_rgba(1,1,1,0.2);
raydium_osd_draw_quad(raydium_lensflare_texture[4],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
}
if(raydium_lensflare_fx[a][3])
{
//Star Streaks
size=(float)(80.0f*(1.0f-(dist/75.0f)));
size=raydium_lensflare_fxsize[a][3]*size*pt;
mulpos=dist;
turn=raydium_lensflare_fxvelocity[a][3]*giro/5.0f;
raydium_osd_color_rgba(1,1,0.4,1);
raydium_osd_draw_quad(raydium_lensflare_texture[2],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
}
if(raydium_lensflare_fx[a][2])
{
//Halo
size=(float)(2.0f*phase2/dist)+(50.0f*(1.0f-(dist/75.0f)));
size=raydium_lensflare_fxsize[a][2]*size*pt;
mulpos=dist;
turn=raydium_lensflare_fxvelocity[a][2]*giro;
raydium_osd_color_rgba(0.25f,0.25f,0.125f,0.5f);
raydium_osd_draw_quad(raydium_lensflare_texture[3],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
}
if(raydium_lensflare_fx[a][6])
{
//blue glow
size=(float)(75.0f*(0.0f+(dist/75.0f)));
size=raydium_lensflare_fxsize[a][6]*size*pt;
mulpos=-dist;
turn=raydium_lensflare_fxvelocity[a][6]*giro;
raydium_osd_color_rgba(0,0,0.5,0.4);
raydium_osd_draw_quad(raydium_lensflare_texture[0],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
//blue glow-halo
size=(float)(75.0f*(0.0f+(dist/75.0f)));
size=fmodf(size,75);
size=raydium_lensflare_fxsize[a][6]*size*pt;
mulpos=-dist;
turn=raydium_lensflare_fxvelocity[a][6]*(-giro);
raydium_osd_color_rgba(0,0,0.5f-(size/75.0f),0.4);
raydium_osd_draw_quad(raydium_lensflare_texture[3],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
}
if(raydium_lensflare_fx[a][4])
{
//red glow
size=(float)(10.0f*(0.0f+(dist/75.0f)));
size=raydium_lensflare_fxsize[a][4]*size*pt;
mulpos=-dist*1.53f;
turn=raydium_lensflare_fxvelocity[a][4]*360.0f*(vx*vy);
raydium_osd_color_rgba(0.5,0,0,0.3);
raydium_osd_draw_quad(raydium_lensflare_texture[0],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
//red star
size=(float)(20.0f*(0.0f+(dist/75.0f)));
size=raydium_lensflare_fxsize[a][4]*size*pt;
mulpos=-dist*1.53f;
turn=raydium_lensflare_fxvelocity[a][4]*giro*(float)vx*(float)vy*2;
raydium_osd_color_rgba(0.3,0,0,0.3);
raydium_osd_draw_quad(raydium_lensflare_texture[1],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
//red star
size=(float)(20.0f*(0.0f+(dist/75.0f)));
size=raydium_lensflare_fxsize[a][4]*size*pt;
mulpos=-dist*1.53f;
turn=raydium_lensflare_fxvelocity[a][4]*(-giro)*(float)vx*(float)vy*3;
raydium_osd_color_rgba(0.3,0,0,0.3);
raydium_osd_draw_quad(raydium_lensflare_texture[1],cx+(vx*mulpos)-size,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size,cy+(vy*mulpos)+size,turn);
}
if(raydium_lensflare_fx[a][0])
{
//anamorphic1
size=1.2f;
size=size*pt;
mulpos=dist;
anam=raydium_lensflare_fxsize[a][0]*(25.0f+50.0f*(0.0f+(dist/50.0f)));
turn=0;
raydium_osd_color_rgba(0.7f,0.7f,0.7f,0.7f);
raydium_osd_draw_quad(raydium_lensflare_texture[5],cx+(vx*mulpos)-size*anam,cy+(vy*mulpos)-size,cx+(vx*mulpos)+size*anam,cy+(vy*mulpos)+size,turn);
//anamorphic2
size=1.1f;
size=size*pt;
mulpos=dist;
anam=raydium_lensflare_fxsize[a][0]*((raydium_lensflare_fxvelocity[a][0]*phase+24.0f+50.0f*(0.0f+(dist/50.0f))));
turn=0;
raydium_osd_color_rgba(0.7f,0.7f,0.7f,0.7f);
raydium_osd_draw_quad(raydium_lensflare_texture[5],cx+(vx*mulpos)+size*anam,cy+(vy*mulpos)+size,cx+(vx*mulpos)-size*anam,cy+(vy*mulpos)-size,turn);
}
//restoring blend function
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
//restoring color
memcpy(raydium_osd_color,oldcolor,4*sizeof(float));
}
else
{
raydium_lensflare_time_shown[a]=0.0f;
pt=0;
}
}
}
}
void show_texts()
{
raydium_osd_color_rgba(0,0,0,1);
raydium_osd_printf(12,95,16,0.5,"font2.tga","Press [SPACE] to switch between camera and edition modes.");
raydium_osd_printf(12,5,14,0.5,"font2.tga","Press [s] to place the lensflare in the camera position.");
}
void gui_feed(void)
{
char str[RAYDIUM_MAX_NAME_LEN];
//anamorphic streak
raydium_gui_write_name("window","fx1",str,raydium_lensflare_fx[0][0]);
raydium_gui_write_name("window","fx1v",str,raydium_lensflare_fxvelocity[0][0]*100.0f);
raydium_gui_write_name("window","fx1s",str,raydium_lensflare_fxsize[0][0]*100.0f);
//rays
raydium_gui_write_name("window","fx2",str,raydium_lensflare_fx[0][1]);
raydium_gui_write_name("window","fx2v",str,raydium_lensflare_fxvelocity[0][1]*100.0f);
raydium_gui_write_name("window","fx2s",str,raydium_lensflare_fxsize[0][1]*100.0f);
//halo
raydium_gui_write_name("window","fx3",str,raydium_lensflare_fx[0][2]);
raydium_gui_write_name("window","fx3v",str,raydium_lensflare_fxvelocity[0][2]*100.0f);
raydium_gui_write_name("window","fx3s",str,raydium_lensflare_fxsize[0][2]*100.0f);
//star
raydium_gui_write_name("window","fx4",str,raydium_lensflare_fx[0][3]);
raydium_gui_write_name("window","fx4v",str,raydium_lensflare_fxvelocity[0][3]*100.0f);
raydium_gui_write_name("window","fx4s",str,raydium_lensflare_fxsize[0][3]*100.0f);
//red dot
raydium_gui_write_name("window","fx5",str,raydium_lensflare_fx[0][4]);
raydium_gui_write_name("window","fx5v",str,raydium_lensflare_fxvelocity[0][4]*100.0f);
raydium_gui_write_name("window","fx5s",str,raydium_lensflare_fxsize[0][4]*100.0f);
//main glow
raydium_gui_write_name("window","fx6",str,raydium_lensflare_fx[0][5]);
raydium_gui_write_name("window","fx6v",str,raydium_lensflare_fxvelocity[0][5]*100.0f);
raydium_gui_write_name("window","fx6s",str,raydium_lensflare_fxsize[0][5]*100.0f);
//blue glow
raydium_gui_write_name("window","fx7",str,raydium_lensflare_fx[0][6]);
raydium_gui_write_name("window","fx7v",str,raydium_lensflare_fxvelocity[0][6]*100.0f);
raydium_gui_write_name("window","fx7s",str,raydium_lensflare_fxsize[0][6]*100.0f);
}
void gui_process(void)
{
char str[RAYDIUM_MAX_NAME_LEN];
//anamorphic streak
raydium_lensflare_fx[0][0]=raydium_gui_read_name("window","fx1",str);
raydium_lensflare_fxvelocity[0][0]=raydium_gui_read_name("window","fx1v",str)/100.0f;
raydium_lensflare_fxsize[0][0]=raydium_gui_read_name("window","fx1s",str)/100.0f;
//rays
raydium_lensflare_fx[0][1]=raydium_gui_read_name("window","fx2",str);
raydium_lensflare_fxvelocity[0][1]=raydium_gui_read_name("window","fx2v",str)/100.0f;
raydium_lensflare_fxsize[0][1]=raydium_gui_read_name("window","fx2s",str)/100.0f;
//main halo
raydium_lensflare_fx[0][2]=raydium_gui_read_name("window","fx3",str);
raydium_lensflare_fxvelocity[0][2]=raydium_gui_read_name("window","fx3v",str)/100.0f;
raydium_lensflare_fxsize[0][2]=raydium_gui_read_name("window","fx3s",str)/100.0f;
//star
raydium_lensflare_fx[0][3]=raydium_gui_read_name("window","fx4",str);
raydium_lensflare_fxvelocity[0][3]=raydium_gui_read_name("window","fx4v",str)/100.0f;
raydium_lensflare_fxsize[0][3]=raydium_gui_read_name("window","fx4s",str)/100.0f;
//red dot
raydium_lensflare_fx[0][4]=raydium_gui_read_name("window","fx5",str);
raydium_lensflare_fxvelocity[0][4]=raydium_gui_read_name("window","fx5v",str)/100.0f;
raydium_lensflare_fxsize[0][4]=raydium_gui_read_name("window","fx5s",str)/100.0f;
//main glow
raydium_lensflare_fx[0][5]=raydium_gui_read_name("window","fx6",str);
raydium_lensflare_fxvelocity[0][5]=raydium_gui_read_name("window","fx6v",str)/100.0f;
raydium_lensflare_fxsize[0][5]=raydium_gui_read_name("window","fx6s",str)/100.0f;
//blue glow
raydium_lensflare_fx[0][6]=raydium_gui_read_name("window","fx7",str);
raydium_lensflare_fxvelocity[0][6]=raydium_gui_read_name("window","fx7v",str)/100.0f;
raydium_lensflare_fxsize[0][6]=raydium_gui_read_name("window","fx7s",str)/100.0f;
}
void display(void)
{
float *pos;
gui_process();
raydium_joy_key_emul();
if(raydium_key_last==1027)
exit(0);
if(raydium_key_last==1) raydium_capture_frame_auto();
if(mode==0)//camera
{
raydium_mouse_hide();
raydium_osd_cursor_set("",0,0);
raydium_gui_hide();
}
else
if(mode==1)//editor
{
raydium_mouse_show();
raydium_osd_cursor_set("BOXmania_cursor.tga",4,6);
raydium_gui_show();
}
if(raydium_key_last==1000+'s')
{
pos=raydium_camera_get_data();
raydium_lensflare_move_3f(0,pos[0],pos[1],pos[2]);
}
if(raydium_key_last==1000+'e')
{
raydium_lensflare_export(0,"lf0.lensflare",1);
}
if(raydium_key_last==1000+'i')
{
raydium_lensflare_import(0,"lf0.lensflare");
}
/* RENDER PIPELINE */
raydium_clear_frame();
raydium_camera_freemove(!mode);
//space input here to prevent camera movements
if(raydium_key_last==1000+' ') //space to switch modes
{
raydium_mouse_move(raydium_window_tx/2.0f,raydium_window_ty/2.0f);
mode=mode?0:1;
}
raydium_ode_draw_all(0);
raydium_lensflare_draw(0);
show_texts();
/* FINISH FRAME */
raydium_rendering_finish();
}
void gui_init(void)
{
if(raydium_gui_isvisible())
return;
raydium_gui_show();
raydium_osd_cursor_set("BOXmania_cursor.tga",4,6);
}
void gui_create(void)
{
int handle;
raydium_gui_theme_load("lensflare.gui");
//anamorphic block
handle=raydium_gui_window_create("window",1,1,98,98);
raydium_gui_widget_sizes(0,0,20);
raydium_gui_label_create("Title",handle,25,90,"Anamorphic Streak",0,0,0);
raydium_gui_widget_sizes(3,3,16);
raydium_gui_check_create("fx1",handle, 2,86, "Active",100.0f*raydium_lensflare_fx[0][0]);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx1l1",handle,10,84,"Velocity",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx1v",handle,20,83,0,500,100*raydium_lensflare_fxsize[0][0]);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx1l2",handle,10,81,"Size:",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx1s",handle,20,80,0,500,100);
//rays
raydium_gui_widget_sizes(0,0,20);
raydium_gui_label_create("Title2",handle,25,75,"Rays",0,0,0);
raydium_gui_widget_sizes(3,3,16);
raydium_gui_check_create("fx2",handle, 2,71, "Active",raydium_lensflare_fx[0][1]);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx2l1",handle,10,69,"Velocity",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx2v",handle,20,68,0,500,100);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx2l2",handle,10,66,"Size:",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx2s",handle,20,65,0,500,100);
//main halo
raydium_gui_widget_sizes(0,0,20);
raydium_gui_label_create("Title3",handle,25,60,"Main Halo",0,0,0);
raydium_gui_widget_sizes(3,3,16);
raydium_gui_check_create("fx3",handle, 2,56, "Active",raydium_lensflare_fx[0][2]);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx3l1",handle,10,53,"Velocity",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx3v",handle,20,52,0,500,100);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx3l2",handle,10,50,"Size:",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx3s",handle,20,49,0,500,100);
//star
raydium_gui_widget_sizes(0,0,20);
raydium_gui_label_create("Title4",handle,25,45,"Star",0,0,0);
raydium_gui_widget_sizes(3,3,16);
raydium_gui_check_create("fx4",handle, 2,40, "Active",raydium_lensflare_fx[0][3]);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx4l1",handle,10,37,"Velocity",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx4v",handle,20,36,0,500,100);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx4l2",handle,10,34,"Size:",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx4s",handle,20,33,0,500,100);
//red dot
raydium_gui_widget_sizes(0,0,20);
raydium_gui_label_create("Title5",handle,25,28,"Red dot",0,0,0);
raydium_gui_widget_sizes(3,3,16);
raydium_gui_check_create("fx5",handle, 2,24, "Active",raydium_lensflare_fx[0][4]);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx5l1",handle,10,21,"Velocity",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx5v",handle,20,20,0,500,100);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx5l2",handle,10,18,"Size:",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx5s",handle,20,17,0,500,100);
//main glow
raydium_gui_widget_sizes(0,0,20);
raydium_gui_label_create("Title6",handle,75,28,"Main Glow",0,0,0);
raydium_gui_widget_sizes(3,3,16);
raydium_gui_check_create("fx6",handle, 52,24, "Active",raydium_lensflare_fx[0][5]);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx6l1",handle,60,21,"Velocity",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx6v",handle,70,20,0,500,100);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx6l2",handle,60,18,"Size:",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx6s",handle,70,17,0,500,100);
//blue glow
raydium_gui_widget_sizes(0,0,20);
raydium_gui_label_create("Title7",handle,75,45,"Blue Glow",0,0,0);
raydium_gui_widget_sizes(3,3,16);
raydium_gui_check_create("fx7",handle, 52,40, "Active",raydium_lensflare_fx[0][6]);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx7l1",handle,60,37,"Velocity",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx7v",handle,70,36,0,500,100);
raydium_gui_widget_sizes(0,0,16);
raydium_gui_label_create("fx7l2",handle,60,34,"Size:",0,0,0);
raydium_gui_widget_sizes(20,2,0);
raydium_gui_track_create("fx7s",handle,70,33,0,500,100);
gui_init();
}
int main(int argc, char **argv)
{
int a;
raydium_init_args(argc,argv);
raydium_window_create(800,600,RAYDIUM_RENDERING_WINDOW,"Lensflare Editor");
raydium_texture_filter_change(RAYDIUM_TEXTURE_FILTER_TRILINEAR);
raydium_window_view_perspective(60,0.01,2500); // fov 60 + near and far planes
raydium_fog_disable();
raydium_light_enable();
raydium_light_on(0);
raydium_light_conf_7f(0,50,150,200,1000000,1,0.9,0.7); // id, pos, intensity and color (RGB)
raydium_background_color_change(1,0.9,0.7,1);
raydium_sky_box_cache();
raydium_ode_ground_set_name("cocorobix.tri");
raydium_lensflare_init();
raydium_lensflare_on(0);
//raydium_lensflare_on(1);
raydium_lensflare_color_set(0,1,1,1);
//raydium_lensflare_color_set(1,1,1,1);
raydium_lensflare_move_3f(0,-32.57,13.68,12.74);
//raydium_lensflare_move_3f(1,-20.57,19.68,13.74);
raydium_hdr_enable();
//gui
gui_create();
raydium_hdr_settings_eye(0.31415f,0.5f);
a=raydium_ode_object_create("WATURE");
raydium_ode_object_box_add("corps",a,0.2,1.2,0.6,0.4,RAYDIUM_ODE_STANDARD,0,"clio.tri");
raydium_callback(&display);
return(0);
}
// EOF
And this is an example of common car lensflare:
Code:
Lensflare definition
version=1
id=0
anamorphic={ 1.000000, 0.780000, 4.970000, 1.000000, 1.000000, 1.000000}
rays={ 1.000000, 0.380000, 2.310000, 1.000000, 1.000000, 1.000000}
halo={ 0.000000, 1.410000, 1.970000, 1.000000, 1.000000, 1.000000}
streak={ 1.000000, 0.310000, 2.600000, 1.000000, 1.000000, 1.000000}
reddot={ 0.000000, 1.130000, 0.380000, 1.000000, 1.000000, 1.000000}
glow={ 0.000000, 0.000000, 0.030000, 1.000000, 1.000000, 1.000000}
blueglow={ 1.000000, 0.560000, 4.940000, 1.000000, 1.000000, 1.000000}
The GUI is updated with the import of the file.
Also all fx code has been rewritten cause of a big bug.