New Paste :: Recent Pastes:: No Line Numbers
some rendering crap by JazzD
1
/*================================================================== Copyright (C) 2002-2004 Enigmatic Studios AS. All Rights Reserved. http://www.enigmatic-studios.com philipp[at]enigmatic-studios[dot]com Lead Codework by Philipp Karbach ==================================================================*/ #include "render.h" #include "art.h" #include "CFrustum.h" #include "CMission.h" #include "CLog.h" #include "CPlayer.h" #include "CRecordPath.h" #include "CPlayPath.h" #include "CGLSL.h" extern CMission Mission; CFrustum Frustum; extern CRecordPath path; extern CPlayPath playpath; extern bool noclip; /* HERE GOES THE MAIN RENDERING! */ extern HDC g_HDC; CCamera Camera; CHud hud; float skymove; extern HWND hwnd; extern HINSTANCE hInstance2; float runtime = 0.0f; int fpsnum=0; DWORD fpstime=0; int fps=0; GLfloat elapsed = 0; GLfloat timeFromStart = 0; extern bool showCursor; CDirectInputSystem *DirectInput; CGame Game; extern CVector3 drakir; float frametime; extern float v; extern int Mx,My; extern bool render; float Shine = 10.0; float lightpos[]= { 0.0f,80.0f,0.0f }; CTexture barr; CTexture barl; CTexture barseg; CBar test5; CBar test6; CTexture wall; CTexture sphere1; float dec1=0.0f; float move=0; float snirf=0.0f; extern bool debug; extern bool debugprint; GLuint g_Texture[1000]; extern bool MirrorIsVisible; extern bool LiquidIsVisible; extern bool recording; extern int num_OfStartPoints; extern CVector3 info_player_start[128]; CVector3 current_IPS (0.0f,0.0f,0.0f); bool firstframe=true; bool wireframe=false; bool noclip=false; bool EndFrame=false; bool BlurCam=false; GLuint MirrorTex; GLuint BlurTex; GLhandleARB TestPrg; extern float curFOV; bool InitMain() { glClearColor (0.0f, 0.0f, 0.0f, 0.5f); if(!EndFrame) DirectInput->Initialize(hwnd, hInstance2); Font.LoadTexture("base/menu/font"); flare.LoadTexture("base/textures/sfx/flare"); sky.LoadTexture("base/sky/sky0"); sky0.LoadTexture("base/sky/sky"); if(!EndFrame) hud.Init(); return true; } void InitCam() { //Camera.PositionCamera( 60, 20, 350.58f, 60, 20, 350, 0, 1, 0); // Notice that we need to convert quake coordinate system to ours, the formula is: // NewX = QuakeX // NewY = QuakeZ // NewZ = -QuakeY if(num_OfStartPoints == 0) { print("No Startpoint in map! (info_player_deathmatch not found!)"); GetLog().Print("info_player_deathmatch missing!"); GetLog().DeInit(); exit(0); } current_IPS = info_player_start[rand()%num_OfStartPoints]; current_IPS.x = current_IPS.x; current_IPS.y = current_IPS.z; current_IPS.z = current_IPS.y; Camera.PositionCamera( current_IPS.x,current_IPS.y,current_IPS.z, current_IPS.x,current_IPS.y,current_IPS.z+1, 0,1,0); Camera.RotateView(360.0f,0,1,0); } bool InitGame(char *file) { Game.Init(file); InitCam(); BlurCam = false; if(!EndFrame) { CreateRenderTexture(MirrorTex, 512, 4, GL_RGBA); CreateRenderTexture(BlurTex, 512, 4, GL_RGBA); TestPrg = GLslangMgr::Inst()->LoadProgram("base/shaders/test.spo"); } showCursor=false; return true; } bool InitGL() { glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glLightfv(GL_LIGHT0,GL_POSITION,lightpos); float specularColor[3] = {1.0, 1.0, 1.0}; glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularColor); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &Shine); glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); return true; } void InitFrame() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glLoadIdentity(); Game.GetInput(); GetInput(); } void DrawBlur(int times, float inc) { float spost = 0.0f; float alphainc = 0.6f / times; float alpha = 0.2f; glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_2D); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D,BlurTex); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glOrtho( 0, Width() , Height() , 0, -1, 1 ); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); alphainc = (alpha / times) * 2; glBegin(GL_QUADS); for (int num = 0;num < times;num++) { glColor4f(1.0f, 1.0f, 1.0f, alpha*2); glTexCoord2f(0+spost,1-spost); glVertex2f(0,0); glTexCoord2f(0+spost,0+spost); glVertex2f(0,Height()); glTexCoord2f(1-spost,0+spost); glVertex2f(Width(),Height()); glTexCoord2f(1-spost,1-spost); glVertex2f(Width(),0); spost += inc; alpha = alpha - alphainc; } glEnd(); glMatrixMode( GL_PROJECTION ); glPopMatrix(); glMatrixMode( GL_MODELVIEW ); glPopMatrix(); glEnable(GL_DEPTH_TEST); glDisable(GL_BLEND); glBindTexture(GL_TEXTURE_2D,0); } void RenderMirror() { if(MirrorIsVisible) { glViewport(0, 0, 512, 512); glMatrixMode(GL_PROJECTION); glLoadIdentity (); gluPerspective( curFOV+15, (GLfloat)Width()/(GLfloat)Height(), 1.0f, 80000.0f); // Render the game glRotatef(180.0f,0,1,0); Game.Render(); glEnable(GL_TEXTURE_2D); if(!noclip) { glBindTexture(GL_TEXTURE_2D,MirrorTex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 512,512, 0); glTexGenf(GL_S,GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGenf(GL_T,GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); } glClearColor(0.0f, 0.0f, 0.5f, 0.5); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, Width(), Height()); glMatrixMode(GL_PROJECTION); glLoadIdentity (); gluPerspective( curFOV, (GLfloat)Width()/(GLfloat)Height(), 1.0f, 80000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); } } void RenderBlur() { if(BlurCam) { gluLookAt(Camera.Position().x, Camera.Position().y+20, Camera.Position().z, Camera.View().x, Camera.View().y+20, Camera.View().z, 0, 1, 0); glViewport(0, 0, 512, 512); // Render the game Game.Render(); glEnable(GL_TEXTURE_2D); if(!noclip) { glBindTexture(GL_TEXTURE_2D,BlurTex); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 512, 512, 0); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, Width(), Height()); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } } void RenderScene() { glMatrixMode(GL_PROJECTION); glLoadIdentity (); gluPerspective( curFOV, (GLfloat)Width()/(GLfloat)Height(), 1.0f, 80000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor3f(1.0f,1.0f,1.0f); if(playpath.play) { gluLookAt(playpath.xp, playpath.yp, playpath.zp, playpath.xv, playpath.yv, playpath.zv, 0, 1, 0); } else { if(MirrorIsVisible) { CVector3 Position = Normalize(Camera.Position()); CVector3 View = Normalize(Camera.View()); gluLookAt(Camera.Position().x-(Position.x*10) ,Camera.Position().y+(Position.y*10),Camera.Position().y+(Position.y*10), 1,Camera.View().y+(View.x*10),1, 0, 1, 0); } } glEnable(GL_TEXTURE_2D); glEnable(GL_COLOR_MATERIAL); if(wireframe) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glLineWidth(2.0f); glColor3f(0.0f,0.68359375f,0.8828125f); } else { glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); } glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glCullFace(GL_FRONT); RenderMirror(); RenderBlur(); Camera.Look(); Game.Render(); /* glDisable(GL_CULL_FACE); GLslangMgr::Inst()->UseProgram(TestPrg); auxSolidSphere(20.0f); GLslangMgr::Inst()->UseProgram(0);*/ glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); glDisable(GL_FOG); glCullFace(GL_BACK); glPushMatrix(); if(BlurCam) DrawBlur(15,0.01f); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glLoadIdentity(); glTranslatef(0.0f,0.0f,-1.0f); if(!recording) { if(debugprint) { //hud.Draw(); //hud.DrawFPS(); } else { hud.DrawFPS(); } } glPopMatrix(); if(EndFrame) { render = false; Mission.Restart(); showCursor=true; } } void GetInput() { DirectInput->UpdateDevices(); // getinput game if(DirectInput->KeyDown(DIK_ADD)) { if(debug) snirf += 0.1f; } if(DirectInput->KeyDown(DIK_SUBTRACT)) { if(debug) snirf -= 0.1f; } if(DirectInput->KeyDown(DIK_ESCAPE)) { EndFrame = true; } if(DirectInput->KeyDown(DIK_F5)) { if(Camera.movetype == CAM_PLAYER) { if(wait(300)) Camera.movetype = CAM_FREELOOK; } else if(Camera.movetype == CAM_FREELOOK) { if(wait(300)) Camera.movetype = CAM_PLAYER; } } if(DirectInput->KeyDown(DIK_F4)) { if(noclip) { if(wait(300)) noclip=false; } else if(!noclip) { if(wait(300)) noclip=true; } } if(DirectInput->KeyDown(DIK_TAB)) { if(wireframe) { if(wait(300)) wireframe=false; } else if (!wireframe) { if(wait(300)) wireframe=true; } } if(DirectInput->KeyDown(DIK_LSHIFT)) { if(showCursor) { if(wait(500)) showCursor=false; } else { if(wait(500)) showCursor=true; } } if(firstframe) { firstframe = false; } else { if(!playpath.play && !showCursor) Camera.Update(); } } void Swapbuffers(DWORD milliseconds) { fpstime+=milliseconds; fpsnum++; if (fpstime>=1000) { fpstime=0; fps=fpsnum+((fpsnum/2)+8); fpsnum=0; } elapsed = (GLfloat)milliseconds; timeFromStart += milliseconds; skymove +=(GLfloat)(((GLfloat)milliseconds * 0.1 ) / 1000); // Refresh the game if(!wireframe && !EndFrame) Game.Refresh(); SwapBuffers(g_HDC); } void ShutDown() { if(DirectInput) delete DirectInput; DirectInput = NULL; }