// GlutRTTAlap.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "ThirdPersonCamera.h" #include #include Scene theScene; ThirdPersonCamera theCamera; PreIllumSystem *theSystem; bool headsup=true; bool anim_on=false; char* therendermode; int rendermode=0; SkyBox theSkyBox; float lightposangle1=0.4; float lightposangle2=1.2; bool isrecording=false; int framenum; Vector SkyColor(0,0,0); Vector LightPos(0,5,-5); //Vector LightColor(3,1.5,0); Vector LightColor(4.6,4.6,5.1); //Vector LightColor(0,0,0); Vector LightPos2(1,-10,-1); //Vector LightColor2(0.7,0.4,0.5); Vector LightColor2(5.6,5.7,6); //Vector LightColor2(1,0,0); Vector positions[2]; float angle=0; unsigned int lastTime; unsigned int frameRate=0; unsigned int frameRateLast=0; unsigned int timeElapsed; unsigned int LastDtTime=0; unsigned int Dt=0; bool start=true; int direction=0; Impostor ScreenQuad; RenderTexture PhaseTexture; CgProgram PhaseProgram; void drawFrameRate(char *str, void *font, GLclampf r, GLclampf g, GLclampf b, GLfloat x, GLfloat y) { /* font: font to use, e.g., GLUT_BITMAP_HELVETICA_10 r, g, b: text colour x, y: text position in window: range [0,0] (bottom left of window) to [1,1] (top right of window). */ char *ch; GLint matrixMode; GLboolean lightingOn; lightingOn= glIsEnabled(GL_LIGHTING); /* lighting on? */ if (lightingOn) glDisable(GL_LIGHTING); glGetIntegerv(GL_MATRIX_MODE, &matrixMode); /* matrix mode? */ glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0.0, 1.0, 0.0, 1.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glPushAttrib(GL_COLOR_BUFFER_BIT); /* save current colour */ glColor4f(r, g, b,1); glRasterPos3f(x, y, 0.0); for(ch= str; *ch; ch++) { glutBitmapCharacter(font, (int)*ch); } glPopAttrib(); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(matrixMode); if (lightingOn) glEnable(GL_LIGHTING); glColor4f(1, 1, 1,1); } void calculateFrameRate() { unsigned int thisTime=(unsigned)timeGetTime(); timeElapsed=thisTime-lastTime; Dt=thisTime-LastDtTime; LastDtTime=thisTime; frameRate++; if(timeElapsed>1000) { lastTime=thisTime; frameRateLast=frameRate; frameRate=0; } } void RenderPhaseTexture() { PhaseTexture.EnableTarget(); PhaseProgram.Enable(); glClearColor(1,1,1,1); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_DEPTH_TEST); ScreenQuad.DisplayScreenQuad(); glEnable(GL_DEPTH_TEST); PhaseProgram.Disable(); PhaseTexture.DisableTarget(); PhaseTexture.BindColorBuffer(); } static void display() { LightPos=Vector(cos(lightposangle1)*cos(lightposangle2),sin(lightposangle2),sin(lightposangle1)*cos(lightposangle2)); LightPos=LightPos*6; theSystem->setSkyColor(SkyColor); calculateFrameRate(); if(anim_on) angle+=0.5; if(start) { Dt=0;timeElapsed=0; start=false; } float x=cos(angle/180*3.14)*10; float y=sin(angle/180*3.14)*10; //float z=sin(angle/180*30+0.45)*1.5; //LightPos.x=x; //LightPos.z=y; //LightPos.y=0; glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); theSkyBox.Display(theCamera); theCamera.SetViewandProjection(); //theScene.Display(false); glDisable(GL_LIGHTING); glColor3f(LightColor.x/2.5,LightColor.y/2.5,LightColor.z/2.5); glPushMatrix(); glTranslatef(LightPos.x,LightPos.y,LightPos.z); glutSolidSphere(0.1,5,5); glPopMatrix(); theSystem->Refresh(LightPos,LightPos2,LightColor,LightColor2); glDisable(GL_LIGHTING); glColor3f(LightColor2.x/2.5,LightColor2.y/2.5,LightColor2.z/2.5); glPushMatrix(); glTranslatef(LightPos2.x,LightPos2.y,LightPos2.z); glutSolidSphere(0.1,5,5); glPopMatrix(); therendermode="Default Dislay"; if(rendermode==0) theSystem->Display(); else therendermode=theSystem->DisplayTexture(rendermode); char fr[255]; if(headsup) { sprintf( fr,"FPS:%u Iterate:%i RenderMode:%s Albedo:%f Opacity:%f",frameRateLast,theSystem->m_IterateCount,therendermode,theSystem->getAlbedo(),theSystem->getOpacity()); } else { sprintf( fr,"LCol1: r:%.2f g:%.2f b:%.2f LCol2: r:%.2f g:%.2f b:%.2f SkyC: r:%.2f g:%.2f b:%.2f" ,LightColor.x,LightColor.y,LightColor.z ,LightColor2.x,LightColor2.y,LightColor2.z ,SkyColor.x,SkyColor.y,SkyColor.z); } //sprintf( fr,"campos:%f %f %f lookat:%f %f %f",theCamera.getPosition().x,theCamera.getPosition().y,theCamera.getPosition().z, // theCamera.getLookAt().x,theCamera.getLookAt().y,theCamera.getLookAt().z); drawFrameRate(fr, GLUT_BITMAP_HELVETICA_10, 1.0f, 0.0f, 1.0f, 0.05, 0.95 ); glutSwapBuffers(); glutReportErrors(); if(isrecording) { framenum++; ilutGLScreenie(); char fname[25]; sprintf( fname,"img%i.tga",framenum); rename("screen0.tga",fname); } } void idle() { glutPostRedisplay(); } void getExts(void) { if(! glh_init_extensions( "GL_ARB_multitexture " "WGL_ARB_pbuffer " "WGL_ARB_pixel_format " "WGL_ARB_render_texture " "GL_NV_vertex_program " "GL_NV_fragment_program " // "GL_ARB_vertex_program " // "GL_ARB_fragment_program " // "WGL_NV_float_buffer" "GL_ARB_vertex_buffer_object " "GL_ATI_draw_buffers " "GL_EXT_blend_equation_separate " "GL_EXT_blend_minmax " "GL_EXT_blend_func_separate " "GL_ARB_point_sprite " "GL_ARB_point_parameters " "GL_EXT_blend_color " //"GL_EXT_pixel_buffer_object " )) { fprintf(stderr, "Error - required extensions were not supported: %s", glh_get_unsupported_extensions()); exit(-1); } } void specialkey(int key, int x, int y) { switch(key) { case GLUT_KEY_F1: if(glutGetModifiers()) { theSystem->m_IterateCount--; if(theSystem->m_IterateCount==-1) theSystem->m_IterateCount=0; } else theSystem->m_IterateCount++; break; case GLUT_KEY_F2: if(glutGetModifiers()) { theSystem->DecreaseAlbedo(); } else theSystem->IncreaseAlbedo(); break; case GLUT_KEY_F3: if(glutGetModifiers()) { theSystem->DecreaseOpacity(); } else theSystem->IncreaseOpacity(); break; case GLUT_KEY_F4: if(glutGetModifiers()) { LightColor.x-=0.1; if(LightColor.x<0)LightColor.x=0; } else { LightColor.x+=0.1; if(LightColor.x>6)LightColor.x=6; } break; case GLUT_KEY_F5: if(glutGetModifiers()) { LightColor.y-=0.1; if(LightColor.y<0)LightColor.y=0; } else { LightColor.y+=0.1; if(LightColor.y>6)LightColor.y=6; } break; case GLUT_KEY_F6: if(glutGetModifiers()) { LightColor.z-=0.1; if(LightColor.z<0)LightColor.z=0; } else { LightColor.z+=0.1; if(LightColor.z>6)LightColor.z=6; } break; case GLUT_KEY_F7: if(glutGetModifiers()) { LightColor2.x-=0.1; if(LightColor2.x<0)LightColor2.x=0; } else { LightColor2.x+=0.1; if(LightColor2.x>6)LightColor2.x=6; } break; case GLUT_KEY_F8: if(glutGetModifiers()) { LightColor2.y-=0.1; if(LightColor2.y<0)LightColor2.y=0; } else { LightColor2.y+=0.1; if(LightColor2.y>6)LightColor2.y=6; } break; case GLUT_KEY_F9: if(glutGetModifiers()) { LightColor2.z-=0.1; if(LightColor2.z<0)LightColor2.z=0; } else { LightColor2.z+=0.1; if(LightColor2.z>6)LightColor2.z=6; } break; case GLUT_KEY_F10: if(glutGetModifiers()) { SkyColor.x-=0.1; if(SkyColor.x<0)SkyColor.x=0; } else { SkyColor.x+=0.1; if(SkyColor.x>6)SkyColor.x=6; } break; case GLUT_KEY_F11: if(glutGetModifiers()) { SkyColor.y-=0.1; if(SkyColor.y<0)SkyColor.y=0; } else { SkyColor.y+=0.1; if(SkyColor.y>6)SkyColor.y=6; } break; case GLUT_KEY_F12: if(glutGetModifiers()) { SkyColor.z-=0.1; if(SkyColor.z<0)SkyColor.z=0; } else { SkyColor.z+=0.1; if(SkyColor.z>6)SkyColor.z=6; } break; /* case GLUT_KEY_LEFT: //theCamera.Rotate(AXIS_Y,1); theCamera.Rotate(Vector(0,1,0)); break; case GLUT_KEY_RIGHT: //theCamera.Rotate(AXIS_Y,-1); theCamera.Rotate(Vector(0,-1,0)); break; case GLUT_KEY_UP: //theCamera.Rotate(AXIS_X,1); theCamera.Rotate(Vector(1,0,0)); break; case GLUT_KEY_DOWN: //theCamera.Rotate(AXIS_X,-1); theCamera.Rotate(Vector(-1,0,0)); break; */ case GLUT_KEY_LEFT: lightposangle1+=0.02; break; case GLUT_KEY_RIGHT: lightposangle1-=0.02; break; case GLUT_KEY_UP: lightposangle2+=0.02; break; case GLUT_KEY_DOWN: lightposangle2-=0.02; break; } } static void keyboard(unsigned char key, int x, int y) { switch(key) { case 27: exit(0); break; case ' ': anim_on=!anim_on; break; case 'w': theCamera.Move(AXIS_Z,0.1); break; case 's': theCamera.Move(AXIS_Z,-0.1); break; case 'd': theCamera.Move(AXIS_X,0.1); break; case 'a': theCamera.Move(AXIS_X,-0.1); break; case 'r': theCamera.Move(AXIS_Y,0.1); break; case 'f': theCamera.Move(AXIS_Y,-0.1); break; case 'l': rendermode++; if(rendermode==7) rendermode=0; break; case 'L': rendermode--; if(rendermode==-1) rendermode=6; break; case 'm': ilutGLScreenie();//screenshot break; case 'p': theSystem->ResetIllumTexture(); break; case 'o': isrecording=!isrecording; break; case 'h': headsup=!headsup; break; } } void initOpenGL() { srand( (unsigned)timeGetTime() ); glEnable(GL_DEPTH_TEST); glClearDepth(1.0); //glClearColor(.6, .5, 1.0, 0.0); glClearColor(.6, .6, 0.6, 0.0); getExts(); /* theCamera.Move(AXIS_X,0); theCamera.Move(AXIS_Y,0); theCamera.Move(AXIS_Z,-3); */ //theCamera.Rotate(AXIS_Y,115); //theCamera.Rotate(AXIS_X,0); theCamera.setFarClipDistance(100); theCamera.setNearClipDistance(0.01); theSkyBox.Initialize("bluedream"); //theSkyBox.Initialize("simple"); //theScene.Load("thinker.txt"); theSystem=new PreIllumSystem; theSystem->SetEyeCamera(&theCamera); theSystem->Init(512,128); } int _tmain(int argc, _TCHAR* argv[]) { //srand(timeGetTime()); glutInit(&argc, argv); ilInit(); iluInit(); ilutRenderer(ILUT_OPENGL); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(512, 512); glutCreateWindow("GlutRTTAlap"); initOpenGL(); glutSpecialFunc(specialkey); glutKeyboardFunc(keyboard); glutDisplayFunc(display); glutIdleFunc(idle); glutMainLoop(); return 0; }