// TRANSPARENCY WORKS!!!!**************************
// MOUSE WORKS
// SPECULAR works
// g++ ogl9.cpp -lSDL -lGL = ./a.out
#include "SDL/SDL.h" // -lSDL
#include "GL/gl.h" // -lGL
#include "math.h"
#include "iostream"
void glup(GLfloat fov,GLfloat aspectr,GLfloat zn,GLfloat zf){
GLfloat xmin,xmax,ymin,ymax;
ymax=(float)zn*tan(fov*0.00872);
ymin=-ymax;
xmin=ymin*aspectr;
xmax=ymax*aspectr;
glFrustum(xmin,xmax,ymin,ymax,zn,zf);
}
using namespace std;
int main(){
unsigned short screen_width = 1024, screen_height = 768;
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
SDL_Surface* sl1=SDL_SetVideoMode(screen_width,screen_height,16,SDL_HWSURFACE|SDL_OPENGL|SDL_NOFRAME|SDL_DOUBLEBUF);
SDL_Event gameover,mouse;
Uint8* key;
bool quit=false;
unsigned char framerate=10;//1000/10=100fps
unsigned int oldTime=0,currentTime=0;
float mx=0.2f,my=0.2f;//mousespeed
float tfmx,tfmy,drawdistance=40,tra=0.5f;
int dir[9];GLfloat sx[9],sn[9],sv[1][9];
glClearColor(0.0f,0.0f,0.2f,1.0f);
glClearDepth(1.0f);
glClearStencil(0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glDepthFunc(GL_LEQUAL);//New pixel passes if depth value less or equal
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
float e,xpos=0,zpos=-2,yrot=0,y=0.0f,q=0,fspeed=0.04f,xx=1.0f;
float piover180=0.0174532925f,aspect_ratio=45.0f;
SDL_Surface* texturesar[1];
GLuint texture[1];
texturesar[0]=SDL_LoadBMP("mud.bmp");
glGenTextures(1,&texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D,0,3,
texturesar[0]->w,texturesar[0]->h,0,
GL_BGR,GL_UNSIGNED_BYTE,texturesar[0]->pixels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
free(texturesar[0]);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
//glColor4f(1.0f,1.0f,1.0f,tra);
GLfloat lightambient[] = { 0.8f, 0.7f, 0.6f, 1.0f };
glLightfv( GL_LIGHT1, GL_AMBIENT, lightambient );
//glEnable(GL_LIGHT1);
//glCullFace(GL_BACK);
//glEnable(GL_CULL_FACE);
//glEnable(GL_STENCIL_TEST);
//glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);
//glStencilFunc(GL_EQUAL,1,0xffffffff);
/* SPECULAR */
GLfloat lp[]={1.0f, 1.0f, 1.0f, 1.0f};
GLfloat diffMat[4]={0.0f, 1.0f, 0.0f, 1.0f};
GLfloat specMat[4]={1.0f, 1.0f, 1.0f, 1.0f};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glLightfv(GL_LIGHT0, GL_POSITION, lp);
//glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColor4fv(diffMat);
/* FOG */
GLfloat fc[4]={0.0f,0.0f,0.0f,1.0f},fd[]={0.08f},fs[]={10000.0f};
glFogfv(GL_FOG_COLOR,fc);
glFogfv(GL_FOG_DENSITY,fd);
glFogfv(GL_FOG_START,fs);
//glEnable(GL_FOG);
/* Print FrameRate */
static GLint T0=0,Frames=0;
glEnable(GL_DEPTH_TEST);
SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_WarpMouse(512,384);
SDL_ShowCursor(0);
// GAME LOOP STARTS HERE **************************************
while(quit==false){
while(SDL_PollEvent(&mouse)){switch(mouse.type){
case SDL_MOUSEMOTION:
yrot+=mouse.motion.xrel*mx;
e+=mouse.motion.yrel*my;
break;}
if(yrot<0.0f){yrot+=359.0f;}
if(yrot>359.0f){yrot-=359.0f;}}
while(SDL_PollEvent(&gameover))
{if(gameover.type==SDL_QUIT){quit=true;}}
key=SDL_GetKeyState(NULL); // CONTROLS
if(key[SDLK_ESCAPE]){quit=true;}
if(key[SDLK_UP]){
xpos -= ( float )sin( yrot * piover180 ) * fspeed;
zpos += ( float )cos( yrot * piover180 ) * fspeed;}
if(key[SDLK_DOWN]){
xpos += ( float )sin( yrot * piover180 ) * fspeed;
zpos -= ( float )cos( yrot * piover180 ) * fspeed;}
if(key[SDLK_LEFT]){
xpos -= ( float )sin( (yrot-90) * piover180 ) * fspeed;
zpos += ( float )cos( (yrot-90) * piover180 ) * fspeed;}
if(key[SDLK_RIGHT]){
xpos -= ( float )sin( (yrot+90) * piover180 ) * fspeed;
zpos += ( float )cos( (yrot+90) * piover180 ) * fspeed;}
if(key[SDLK_a]){y-=0.02f;}
if(key[SDLK_z]){y+=0.02f;}
if(key[SDLK_q]){y=0.0f;}
if(key[SDLK_e]){e=0.0f;}
if(key[SDLK_w]){e=0.0f;}
if(key[SDLK_s]){e-=0.3f;}
if(key[SDLK_x]){e+=0.3f;}
if(key[SDLK_i]){aspect_ratio=45.0f;}
if(key[SDLK_o]){aspect_ratio-=5.0f;}
if(key[SDLK_p]){aspect_ratio+=5.0f;}
if(key[SDLK_k]){xx+=1.0f;}
if(key[SDLK_l]){xx-=1.0f;}
if(key[SDLK_j]){xx=1.0f;}// END OF CONTROLS
GLfloat vertices[12]={0,1,0, 1,-1,-1, -1,-1,1,0,0,0};
if(yrot<0.0f){yrot+=359.0f;}
if(yrot>359.0f){yrot-=359.0f;}
if(e<0.0f){e+=359.0f;}
if(e>359.0f){e-=359.0f;}
if(e<269.0f&&e>179.0f){e=269.0f;}
if(e>89.0f&&e<=179.0f){e=89.0f;}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glup(aspect_ratio,0.85f,0.1f,250.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// CAMERA START
glRotatef(e,1.0f,0.0f,0.0f);
glRotatef(yrot,0.0f,1.0f,0.0f);
glTranslatef(xpos,y,zpos);
// CAMERA END
/* SHADOW CALCULATIONS START */
vertices[0]=0;vertices[1]=1;vertices[2]=0;
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
if(vertices[0]<=lp[0]){dir[0]=1;sx[0]=lp[0]-vertices[0];}else{dir[0]=2;sx[0]=vertices[0]-lp[0];}
if(vertices[1]<=lp[1]){dir[1]=1;sx[1]=lp[1]-vertices[1];}else{dir[1]=2;sx[1]=vertices[1]-lp[1];}
if(vertices[2]<=lp[2]){dir[2]=1;sx[2]=lp[2]-vertices[2];}else{dir[2]=2;sx[2]=vertices[2]-lp[2];}
if(vertices[3]<=lp[0]){dir[3]=1;sx[3]=lp[0]-vertices[3];}else{dir[3]=2;sx[3]=vertices[3]-lp[0];}
if(vertices[4]<=lp[1]){dir[4]=1;sx[4]=lp[1]-vertices[4];}else{dir[4]=2;sx[4]=vertices[4]-lp[1];}
if(vertices[5]<=lp[2]){dir[5]=1;sx[5]=lp[2]-vertices[5];}else{dir[5]=2;sx[5]=vertices[5]-lp[2];}
if(vertices[6]<=lp[0]){dir[6]=1;sx[6]=lp[0]-vertices[6];}else{dir[6]=2;sx[6]=vertices[6]-lp[0];}
if(vertices[7]<=lp[1]){dir[7]=1;sx[7]=lp[1]-vertices[7];}else{dir[7]=2;sx[7]=vertices[7]-lp[1];}
if(vertices[8]<=lp[2]){dir[8]=1;sx[8]=lp[2]-vertices[8];}else{dir[8]=2;sx[8]=vertices[8]-lp[2];}
/* MAKE NORMALS */
sn[0]=sx[0];sn[1]=sx[1];sn[2]=sx[2];
if(sx[0]>=sx[1]&&sx[0]>=sx[2]){sn[1]/=sx[0];sn[2]/=sx[0];sn[0]=1;}
if(sx[1]>=sx[0]&&sx[1]>=sx[2]){sn[0]/=sx[1];sn[2]/=sx[1];sn[1]=1;}
if(sx[2]>=sx[1]&&sx[2]>=sx[0]){sn[1]/=sx[2];sn[0]/=sx[2];sn[2]=1;}
sn[3]=sx[3];sn[4]=sx[4];sn[5]=sx[5];
if(sx[3]>=sx[4]&&sx[3]>=sx[5]){sn[4]/=sx[3];sn[5]/=sx[3];sn[3]=1;}
if(sx[4]>=sx[3]&&sx[4]>=sx[5]){sn[3]/=sx[4];sn[5]/=sx[4];sn[4]=1;}
if(sx[5]>=sx[4]&&sx[5]>=sx[3]){sn[4]/=sx[5];sn[3]/=sx[5];sn[5]=1;}
sn[6]=sx[6];sn[7]=sx[7];sn[8]=sx[8];
if(sx[6]>=sx[7]&&sx[6]>=sx[8]){sn[7]/=sx[6];sn[8]/=sx[6];sn[6]=1;}
if(sx[7]>=sx[6]&&sx[7]>=sx[8]){sn[6]/=sx[7];sn[8]/=sx[7];sn[7]=1;}
if(sx[8]>=sx[7]&&sx[8]>=sx[6]){sn[7]/=sx[8];sn[6]/=sx[8];sn[8]=1;}
/* MAKE VERTICES FOR SHADOW POLYGONS */
if(dir[0]==1){sv[0][0]=vertices[0]-(sn[0]*drawdistance);}
else{sv[0][0]=vertices[0]+(sn[0]*drawdistance);}
if(dir[1]==1){sv[0][1]=vertices[1]-(sn[1]*drawdistance);}
else{sv[0][1]=vertices[1]+(sn[1]*drawdistance);}
if(dir[2]==1){sv[0][2]=vertices[2]-(sn[2]*drawdistance);}
else{sv[0][2]=vertices[2]+(sn[2]*drawdistance);}
if(dir[3]==1){sv[0][3]=vertices[3]-(sn[3]*drawdistance);}
else{sv[0][3]=vertices[3]+(sn[3]*drawdistance);}
if(dir[4]==1){sv[0][4]=vertices[4]-(sn[4]*drawdistance);}
else{sv[0][4]=vertices[4]+(sn[4]*drawdistance);}
if(dir[5]==1){sv[0][5]=vertices[5]-(sn[5]*drawdistance);}
else{sv[0][5]=vertices[5]+(sn[5]*drawdistance);}
if(dir[6]==1){sv[0][6]=vertices[6]-(sn[6]*drawdistance);}
else{sv[0][6]=vertices[6]+(sn[6]*drawdistance);}
if(dir[7]==1){sv[0][7]=vertices[7]-(sn[7]*drawdistance);}
else{sv[0][7]=vertices[7]+(sn[7]*drawdistance);}
if(dir[8]==1){sv[0][8]=vertices[8]-(sn[8]*drawdistance);}
else{sv[0][8]=vertices[8]+(sn[8]*drawdistance);}
/* END OF SHADOW CALCULATIONS */
//glBindTexture(GL_TEXTURE_2D,texture[0]);
GLfloat texc[]={1,0,0,0,1,1,0,1};
glEnableClientState(GL_VERTEX_ARRAY);
//glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3,GL_FLOAT,0,vertices);
glTexCoordPointer(2,GL_FLOAT,0,texc);
lightambient[0]=0.2f;
lightambient[1]=0.0f;
lightambient[2]=0.0f;
lightambient[3]=0.1f;
/* SPECULAR */
GLfloat lp[]={1.0f, 1.0f, 1.0f, 1.0f};
GLfloat diffMat[4]={0.0f, 1.0f, 0.0f, 1.0f};
GLfloat specMat[4]={1.0f, 1.0f, 1.0f, 1.0f};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glLightfv(GL_LIGHT0, GL_POSITION, lp);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColor4fv(diffMat);
// PASS 1 *************
glColorMask(0,0,0,0);
glDisable(GL_LIGHT0);
glDisable(GL_STENCIL_TEST);
// WALL 1
vertices[0]=0;vertices[1]=1;vertices[2]=0;
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
glDrawArrays(GL_TRIANGLES,0,3);
// FLOOR
vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;
vertices[3]=24;vertices[4]=-1;vertices[5]=5;
vertices[6]=-6;vertices[7]=-1;vertices[8]=15;
glDrawArrays(GL_TRIANGLES,0,3);
// CAST SHADOWS a
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,1,9999);
glStencilOp(GL_KEEP,GL_INCR,GL_KEEP);
// BOTTOM
vertices[0]=sv[0][0];vertices[1]=sv[0][1];vertices[2]=sv[0][2];
vertices[3]=sv[0][3];vertices[4]=sv[0][4];vertices[5]=sv[0][5];
vertices[6]=sv[0][6];vertices[7]=sv[0][7];vertices[8]=sv[0][8];
glDrawArrays(GL_TRIANGLES,0,3);
// SIDE 1
vertices[0]=sv[0][0];vertices[1]=sv[0][1];vertices[2]=sv[0][2];
vertices[3]=0;vertices[4]=1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
vertices[9]=sv[0][6];vertices[10]=sv[0][7];vertices[11]=sv[0][8];
glDrawArrays(GL_QUADS,0,4);
// SIDE 2
vertices[0]=sv[0][6];vertices[1]=sv[0][7];vertices[2]=sv[0][8];
vertices[3]=2;vertices[4]=-1;vertices[5]=0;
vertices[6]=0;vertices[7]=-1;vertices[8]=0;
vertices[9]=sv[0][3];vertices[10]=sv[0][4];vertices[11]=sv[0][5];
glDrawArrays(GL_QUADS,0,4);
// SIDE 3
vertices[0]=sv[0][3];vertices[1]=sv[0][4];vertices[2]=sv[0][5];
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=0;vertices[7]=1;vertices[8]=0;
vertices[9]=sv[0][0];vertices[10]=sv[0][1];vertices[11]=sv[0][2];
glDrawArrays(GL_QUADS,0,4);
glStencilFunc(GL_ALWAYS,1,9999);
glStencilOp(GL_KEEP,GL_KEEP,GL_INCR);
// WALL 1
vertices[0]=0;vertices[1]=1;vertices[2]=0;
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
glDrawArrays(GL_TRIANGLES,0,3);
// CAST SHADOWS b
glStencilFunc(GL_ALWAYS,1,9999);
glStencilOp(GL_KEEP,GL_DECR,GL_KEEP);
glCullFace(GL_BACK);
// BOTTOM
vertices[0]=sv[0][0];vertices[1]=sv[0][1];vertices[2]=sv[0][2];
vertices[3]=sv[0][3];vertices[4]=sv[0][4];vertices[5]=sv[0][5];
vertices[6]=sv[0][6];vertices[7]=sv[0][7];vertices[8]=sv[0][8];
glDrawArrays(GL_TRIANGLES,0,3);
// SIDE 1
vertices[0]=sv[0][0];vertices[1]=sv[0][1];vertices[2]=sv[0][2];
vertices[3]=0;vertices[4]=1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
vertices[9]=sv[0][6];vertices[10]=sv[0][7];vertices[11]=sv[0][8];
glDrawArrays(GL_QUADS,0,4);
// SIDE 2
vertices[0]=sv[0][6];vertices[1]=sv[0][7];vertices[2]=sv[0][8];
vertices[3]=2;vertices[4]=-1;vertices[5]=0;
vertices[6]=0;vertices[7]=-1;vertices[8]=0;
vertices[9]=sv[0][3];vertices[10]=sv[0][4];vertices[11]=sv[0][5];
glDrawArrays(GL_QUADS,0,4);
// SIDE 3
vertices[0]=sv[0][3];vertices[1]=sv[0][4];vertices[2]=sv[0][5];
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=0;vertices[7]=1;vertices[8]=0;
vertices[9]=sv[0][0];vertices[10]=sv[0][1];vertices[11]=sv[0][2];
glDrawArrays(GL_QUADS,0,4);
glStencilFunc(GL_ALWAYS,1,9999);
glStencilOp(GL_KEEP,GL_KEEP,GL_DECR);
// WALL 1
vertices[0]=0;vertices[1]=1;vertices[2]=0;
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
glDrawArrays(GL_TRIANGLES,0,3);
glDisable(GL_CULL_FACE);
/* // CAST TRANSLUCENT SHADOWS a
glStencilFunc(GL_ALWAYS,3,9999);
glStencilOp(GL_KEEP,GL_REPLACE,GL_KEEP);
// CAST TRANSLUCENT SHADOWS b
glStencilFunc(GL_ALWAYS,0,9999);
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);
// WALL 1
vertices[0]=0;vertices[1]=1;vertices[2]=0;
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
glDrawArrays(GL_TRIANGLES,0,3);
// FLOOR
vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;
vertices[3]=24;vertices[4]=-1;vertices[5]=5;
vertices[6]=-6;vertices[7]=-1;vertices[8]=15;
glDrawArrays(GL_TRIANGLES,0,3);
// PREPARE FOR TRANSLUCENT SURFACES
glStencilFunc(GL_ALWAYS,1,9999);
glStencilOp(GL_KEEP,GL_KEEP,GL_REPLACE);*/
// PASS 2a (INSIDE SHADOWS)*************
glClear(GL_DEPTH_BUFFER_BIT);
glColorMask(1,1,1,1);
glStencilFunc(GL_EQUAL,1,9999);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
//glEnable(GL_LIGHT0);
//glDisable(GL_LIGHT0);
/* SPECULAR */
diffMat[0]=1.0f;
diffMat[1]=0.0f;
diffMat[2]=1.0f;
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glLightfv(GL_LIGHT0, GL_POSITION, lp);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColor4fv(diffMat);
// WALL 1
vertices[0]=0;vertices[1]=1;vertices[2]=0;
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
glDrawArrays(GL_TRIANGLES,0,3);
// FLOOR
vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;
vertices[3]=24;vertices[4]=-1;vertices[5]=5;
vertices[6]=-6;vertices[7]=-1;vertices[8]=15;
glDrawArrays(GL_TRIANGLES,0,3);
/*
// INSIDE TRANSLUCENT SHADOWS ****
glStencilFunc(GL_EQUAL,3,9999);
lightambient[0]=(0.3f+diffMat[0])*tra;
lightambient[1]=(0.3f+diffMat[1])*tra;
lightambient[2]=(0.3f+diffMat[2])*tra;
lightambient[3]=1.0f;
// WALL 1
vertices[0]=0;vertices[1]=1;vertices[2]=0;
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
glDrawArrays(GL_TRIANGLES,0,3);
// FLOOR
vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;
vertices[3]=24;vertices[4]=-1;vertices[5]=5;
vertices[6]=-6;vertices[7]=-1;vertices[8]=15;
glDrawArrays(GL_TRIANGLES,0,3);
*/
// PASS 2b (OUTSIDE SHADOWS)*************
glStencilFunc(GL_EQUAL,0,9999);
//glEnable(GL_LIGHT0);
/* SPECULAR */
diffMat[0]=0.0f;
diffMat[1]=1.0f;
diffMat[2]=0.0f;
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffMat);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specMat);
glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 25.0);
glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
glLightfv(GL_LIGHT0, GL_POSITION, lp);
glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glColor4fv(diffMat);
// WALL 1
vertices[0]=0;vertices[1]=1;vertices[2]=0;
vertices[3]=0;vertices[4]=-1;vertices[5]=0;
vertices[6]=2;vertices[7]=-1;vertices[8]=0;
glDrawArrays(GL_TRIANGLES,0,3);
// FLOOR
vertices[0]=-5;vertices[1]=-1;vertices[2]=-5;
vertices[3]=24;vertices[4]=-1;vertices[5]=5;
vertices[6]=-6;vertices[7]=-1;vertices[8]=15;
glDrawArrays(GL_TRIANGLES,0,3);
// DRAW TRANSLUCENT SURFACES
// glStencilFunc(GL_EQUAL,1,9999);
glDisableClientState(GL_VERTEX_ARRAY);
//glDisableClientState(GL_TEXTURE_COORD_ARRAY);
q-=0.1f;
SDL_GL_SwapBuffers();
Frames++;
{
GLint t = SDL_GetTicks();
if (t - T0 >= 5000) {
GLfloat seconds = (t - T0) / 1000.0;
GLfloat fps = Frames / seconds;
printf("%d frames in %g seconds = %g FPS\n", Frames, seconds, fps);
T0 = t;
Frames = 0;
}
}
currentTime=SDL_GetTicks();
if(currentTime-oldTime<framerate)
{SDL_Delay(framerate-(currentTime-oldTime));}
oldTime=SDL_GetTicks();}
SDL_Quit();
return 0;
}