/////////////////////////////////////////////////////////////// // Draw Level /////////////////////////////////////////////////////////////// void DrawDemoLevel(void) { DrawCurrentLevel(); DrawConv(); DrawKeys(); DrawSwitches(); DrawExit(); DrawTPlate(); DrawAirBG(); DoHRobo(); DoVRobo(); DoSpecialRobo(); DrawExit(); DrawAir(); FontPrint(0,18," "); FontPrint(0,19," "); FontPrint(0,20," "); FontPrint(0,21," "); FontPrint(0,22," "); FontPrint(0,23," "); PrintScore(); PrintHighScore(); DrawLives(); }
void GameUpdate() { glUniform1f(DefaultShaderProgram.timeLocation, g_fGameTime); double drawStart = glfwGetTime(); const float yAngle = drawStart; const float xAngle = 0.2f; float sy = sin( yAngle ); float cy = cos( yAngle ); float sx = sin( xAngle ); float cx = cos( xAngle ); const float dist = 20.0f; from = Vec3( cx * sy * dist, sx * dist, cx * cy * dist ); DefaultOrtho(); SetCamera(gIdentityMat); glDepthFunc(GL_LEQUAL); ClearScreen( 0.3f, 0.3f, 0.3f ); SetTexture( "sword", 0 ); DrawSquare( 16, 16, 32, 32, 0xFFFFFFFF ); Mat44 modelMat = Translation(Vec3( 30.0f + from.x, 30.0f + from.z, 0.0f)); //modelMat.Scale(1.0f); //glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, modelMat ); DefaultProjection(); from = Vec3( sy * 20.0f, 5.0f, cy * 20.0f ); to = Vec3( 0.0f, 0.0f, 0.0f ); Mat44 look = Mat44LookAt( from, to, Vec4(0.0f,1.0f,0.0f,0.0f)); SetCamera(look); modelMat = Translation(Vec3( 0.0f, 0.0f, 0.0f)); SetTexture( "owl", 0 ); modelMat.Scale(2.0f); SetModel( modelMat ); cube->DrawTriangles(); SetTexture( "dragon", 0 ); modelMat = Translation(Vec3( 0.0f, 0.0f, 6.0f)); SetModel( modelMat ); bunny->DrawTriangles(); SetTexture( "guy", 0 ); modelMat = Translation(Vec3( 0.0f, 0.0f, -6.0f)); SetModel( modelMat ); rocks->DrawTriangles(); SetTexture( "toughguy", 0 ); modelMat = Translation(Vec3( 0.0f, 2.0f, 0.0f)); SetModel( modelMat ); GameMeshes::Get("quadpeep")->DrawTriangles(); SetTexture( "wall", 0 ); modelMat = Translation(Vec3( 6.0f, 0.0f, 0.0f)); SetModel( modelMat ); torus->DrawTriangles(); SetTexture( "chest", 0 ); modelMat = Translation(Vec3( 6.0f, 0.0f, 6.0f)); SetModel( modelMat ); wall->DrawTriangles(); SetTexture( "door-closed", 0 ); modelMat = Translation(Vec3( 6.0f, 0.0f, -6.0f)); SetModel( modelMat ); well->DrawTriangles(); SetTexture( "earth", 0 ); modelMat = Translation(Vec3( -6.0f, 0.0f, 6.0f)); SetModel( modelMat ); floortile->DrawTriangles(); SetTexture( "potion-blue", 0 ); modelMat = Translation(Vec3( -6.0f, 0.0f, 0.0f)); SetModel( modelMat ); monkey->DrawTriangles(); SetTexture( "ring-yellow", 0 ); modelMat = Translation(Vec3( -6.0f, 0.0f, -6.0f)); SetModel( modelMat ); sword->DrawTriangles(); modelMat = Translation(Vec3( 30.0f + from.x, 30.0f + from.z, 0.0f)); Ortho( "prelit" ); glUniform1f(GLShader::Current()->timeLocation, g_fGameTime); //DefaultOrtho(); glDepthFunc(GL_LEQUAL); SetCamera( gIdentityMat ); SetModel( gIdentityMat ); SetTexture( "sword", 0 ); DrawSquare( 64, 16, 32, 32, 0xFFFFFFFF ); SetFontTexture( 'B' ); DrawSquare( 96, 16, 32, 32, 0xFFFFFFFF ); DefaultOrtho(); SetCamera( gIdentityMat ); SetModel( gIdentityMat ); SetTexture( "sword", 0 ); DrawSquare( 128, 16, 32, 32, 0xFFFFFFFF ); SetFontTexture( 'B' ); SetFontTexture( -1 ); DrawSquare( 160, 16, 32, 32, 0xFFFFFFFF ); glUniformMatrix4fv(GLShader::Current()->viewLocation, 1, false, gIdentityMat ); modelMat = Translation(Vec3( 0.0f,0.0f,0.0f )); modelMat.Scale(1.0f); FontPrint( modelMat, "Testing No VAR Water Kerning MMennwwWW" ); }
void game_on_draw( double gameTime ) { CATCH_GL_ERROR("OnEntry to game_on_draw()"); double drawStart = glfwGetTime(); drawStart = 0.0f; const float yAngle = 0.0f; const float xAngle = 0.2f; float sy = sin( yAngle ); float cy = cos( yAngle ); float sx = sin( xAngle ); float cx = cos( xAngle ); const float dist = 20.0f; gCamPos = Vec3( cx * sy * dist, sx * dist, cx * cy * dist ); DefaultShaderProgram.Use(true); CATCH_GL_ERROR("On UseDefaultShader"); GLfloat mvmat[16]; glEnable(GL_DEPTH_TEST); glDepthFunc(GL_GEQUAL); glDisable(GL_BLEND);//glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); Vec3 camUp = Vec3(0,1,0); const float fov = 1.0f; gProjectionMat = Mat44Perspective( fov, (float)win_width / (float)win_height, 0.1f, 100.0f); g_fLastPerspectiveValues[0] = gProjectionMat.x.x; g_fLastPerspectiveValues[1] = gProjectionMat.y.y; gCameraMat = Mat44LookAt( gCamPos, gCamAim, camUp); gCamProj = gCameraMat * gProjectionMat;// * gCameraMat; memset(mvmat, 0, sizeof(mvmat)); mvmat[0*4+0] = mvmat[1*4+1] = mvmat[2*4+2] = mvmat[3*4+3] = 1; CATCH_GL_ERROR("miscPreDraw"); GLShader *current = GLShader::Current(); if( current ) { glUniformMatrix4fv(GLShader::Current()->projLocation, 1, false, gCamProj); CATCH_GL_ERROR("UploadProj"); } else { printf( "No current shader!\n" ); } glClearColor( 0.4f,0.4f,0.5f, 1.0f ); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); Vec4 point; point.x = 0.6f; point.y = 2.0f; point.z = 0.26; point.w = 1.0f; // the elements of space current = GLShader::Current(); if( current ) { mvmat[3*4+0] = 0.0f; mvmat[3*4+2] = 0.0f; glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, mvmat ); CATCH_GL_ERROR("ModelMatrix"); } else { printf( "No current shader\n" ); } if( gWireframeMode ) { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } GLuint textureID; glDisable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); CATCH_GL_ERROR("Draw"); glEnable(GL_BLEND); DefaultShaderProgram.Use(); glDepthMask(GL_TRUE); CATCH_GL_ERROR("Pre-Default Shader"); DefaultShaderProgram.Use(); CATCH_GL_ERROR("Setting Default Shader"); glActiveTexture(GL_TEXTURE0); SetTexture( "cursor", 0 ); glEnable(GL_ALPHA_TEST); glEnable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); if( true ) { for( ThingList::iterator i = gWorldThings.begin(); i != gWorldThings.end(); ++i ) { if( i->texture.c_str()[0] ) { SetTexture(i->texture.c_str(),0); Mat44 modelMat = Translation(i->position); modelMat.Rotation(i->angle, Vec3(0,0,1)); modelMat.Scale(i->scale); glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, modelMat ); i->mesh->DrawTriangles(); } } // do cursor extern Vec2 mouseScreenPos; Vec3 mouseRay = RayFromCam( gCameraMat, mouseScreenPos, GLPerspectiveFactorX(), GLPerspectiveFactorY() ); Vec3 rayHit = RayHitsPlaneAt( gCamPos, mouseRay, Vec4( 0, 0, 1, 0 ) ); Vec3 mpos = Vec3( rayHit.x, rayHit.y, 0.001f ); ClearTexture(); glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, Translation(mpos) ); //extern BadMesh *gMonkeyMesh; //if( gMonkeyMesh ) { //gMonkeyMesh->DrawTriangles(); //} } //glDisable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); glLoadIdentity(); float w = float(win_width / 2); float h = float(win_height / 2); gProjectionMat = Mat44Orthographic( 0, win_width, win_height, 0, -1, 1 ); glUniformMatrix4fv(GLShader::Current()->projLocation, 1, false, gProjectionMat ); CATCH_GL_ERROR("Proj"); if( 1 ) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, 0.1f); glScalef( 8.0f, 8.0f, 1.0f ); char buffer[128]; sprintf( buffer, "%ims", (int)(gameTime * 1000) ); FontPrint( buffer ); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glColor4f(1.0f,1.0f,1.0f,0.9f); glScalef(1.0f,1.0f,0.1f); glRotatef(drawStart*45.0f, 0.0f,1.0f,0.0f ); glGetFloatv(GL_MODELVIEW_MATRIX,mvmat); //glUniformMatrix4fv(mvLocation, 1, false, mvmat ); glUniformMatrix4fv(GLShader::Current()->mvLocation, 1, false, mvmat ); CATCH_GL_ERROR("ModelMatrix"); SetTexture( "cursor", 0 ); //printf( "Bound the shader to 0, not %i\n", textureID ); draw_ZNEG(); CATCH_GL_ERROR("DrawZNeg"); glLoadIdentity(); glTranslatef(8+16-w,8+16-h,0); glScalef(16.0f,16.0f,0.1f); glGetFloatv(GL_MODELVIEW_MATRIX,mvmat); //glUniformMatrix4fv(mvLocation, 1, false, mvmat ); CATCH_GL_ERROR("ModelView"); //draw_ZNEG(); CATCH_GL_ERROR("EndOfDisplay"); }