void init(void) { forward = SetVector(1,1,1); // GL inits glClearColor(0.2,0.2,0.5,0); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glCullFace(GL_BACK); printError("GL inits"); projectionMatrix = frustum(-0.1, 0.1, -0.1, 0.1, 0.2, 500.0); // Load and compile shader programSky = loadShaders("sky.vert", "sky.frag"); skybox = LoadModelPlus("skybox.obj"); program = loadShaders("terrain.vert", "terrain.frag"); //goal = LoadModelPlus("cube.obj"); // If I put this here the walls get darker printError("init shader"); glUseProgram(programSky); glActiveTexture(GL_TEXTURE2); glUniform1i(glGetUniformLocation(programSky, "tex"),2); // Texture unit 1 glBindTexture(GL_TEXTURE_2D, myTex); LoadTGATextureSimple("SkyBox512.tga", &myTex); glActiveTexture(GL_TEXTURE3); glUniform1i(glGetUniformLocation(program, "tex"),3); // Texture unit 1 glBindTexture(GL_TEXTURE_2D, tex3); LoadTGATextureSimple("gold.tga", &tex3); glUseProgram(program); glActiveTexture(GL_TEXTURE0); glUniformMatrix4fv(glGetUniformLocation(program, "projMatrix"), 1, GL_TRUE, projectionMatrix.m); glUniform1i(glGetUniformLocation(program, "tex"),0); // Texture unit 1 glBindTexture(GL_TEXTURE_2D, tex1); LoadTGATextureSimple("maskros512.tga", &tex1); glActiveTexture(GL_TEXTURE1); glUniform1i(glGetUniformLocation(program, "tex"),1); // Texture unit 1 glBindTexture(GL_TEXTURE_2D, tex2); LoadTGATextureSimple("dirt.tga", &tex2); // Load terrain data LoadTGATextureData("MazeWall.tga", &ttexm); LoadTGATextureData("fft-terrain.tga", &ttex); tm = GenerateMazeTerrain(&ttexm,&ttex,vertexArray); mm = GenerateTerrain(&ttex,vertexArray); goal = LoadModelPlus("groundsphere.obj"); // The walls do not get darker printError("init terrain"); sfMakeRasterFont(); // init font sfSetRasterSize(600, 200); }
int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); // glutInitWindowPosition(40,50); glutInitWindowSize(600,200); glutInitContextVersion(3, 2); glutCreateWindow("simplefont demo"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); sfMakeRasterFont(); // init font sfSetRasterSize(600, 200); glutMainLoop(); }
void display(void) { //std::cout << "time boost = " << time_boost << std::endl; if (time_boost >= 1) { time_boost -= 1; if (time_boost < 1) { std::cout << "BOOST OFF!" << std::endl; game_->ball_speed = game_->ball_speed_global; game_->imortality = false; } } //printf("d1 \n"); t += 0.005; game_->world_dir(); // clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mat4 total, modelView, camMatrix; printError("pre display"); glUseProgram(program); // Build matrix vec3 cam = vec3(0, 5, 8); vec3 lookAtPoint = vec3(2, 0, 2); camMatrix = lookAt(cam.x, cam.y, cam.z, lookAtPoint.x, lookAtPoint.y, lookAtPoint.z, 0.0, 1.0, 0.0); modelView = IdentityMatrix(); total = Mult(camMatrix, modelView); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); glUniformMatrix4fv(glGetUniformLocation(program, "Camera"), 1, GL_TRUE, camera.m); // skybox // Disable Z-buffer to draw sky glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); // Use skytex as texture and switch to skyprogram glUseProgram(skyprogram); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, skytex); // Sky mat4 skylookAT = camera; skylookAT.m[3] = 0; skylookAT.m[7] = 0; skylookAT.m[11] = 0; skylookAT = Mult(T(-0.2,0,0), skylookAT); mat4 skyrot = Ry(game_->turn_angle*game_->pol_dir); skytot = Mult(skytot, skyrot); glUniformMatrix4fv(glGetUniformLocation(skyprogram, "lookAT"), 1, GL_TRUE, skylookAT.m); glUniformMatrix4fv(glGetUniformLocation(skyprogram, "mdlMatrix"),1, GL_TRUE, skytot.m); DrawModel(skybox, skyprogram, "in_Position", NULL, "in_TexCoord"); printError("sky shader"); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glUseProgram(program); glBindTexture(GL_TEXTURE_2D, tex1); // Bind Our Texture tex1 glActiveTexture(GL_TEXTURE0); // game clock if (!game_->dead) { // game clock time_count += 0.02; snprintf(buffer, 50, "%f", time_count); sfDrawString(30, 30, "Elapsed Time:"); sfDrawString(170, 30, buffer); if (game_->ball_speed_global < 5) { game_->ball_speed_global += 0.0002; } } //Current total = game_->maze->get_total(); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(game_->maze->track, program, "inPosition", "inNormal", "inTexCoord"); //left total = game_->maze->left->get_total(); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(game_->maze->left->track, program, "inPosition", "inNormal", "inTexCoord"); //left->left total = game_->maze->left->left->get_total(); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(game_->maze->left->left->track, program, "inPosition", "inNormal", "inTexCoord"); //left->right total = game_->maze->left->right->get_total(); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(game_->maze->left->right->track, program, "inPosition", "inNormal", "inTexCoord"); //right total = game_->maze->right->get_total(); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(game_->maze->right->track, program, "inPosition", "inNormal", "inTexCoord"); //right->left total = game_->maze->right->left->get_total(); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(game_->maze->right->left->track, program, "inPosition", "inNormal", "inTexCoord"); //right->right total = game_->maze->right->right->get_total(); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(game_->maze->right->right->track, program, "inPosition", "inNormal", "inTexCoord"); //sphere glBindTexture(GL_TEXTURE_2D, tex2); glActiveTexture(GL_TEXTURE0); // GLfloat y_pos_des = height_controll(x_pos, z_pos,&ttex,tm)+0.1; // y_pos -= (y_pos - y_pos_des)/1*0.5; game_->update(); if (game_->generate_terrain_bool) { NewTerrain(game_->x_pos); game_->generate_terrain_bool = false; } //trans = T(0,0,0); // <<< -- Vart spheren är //rot = Rx(0); //rot = Ry(M_PI_2/4); //total = game_->player_->total_pos();//Mult(game_->strans, rot); camera = game_->update_camera(); //Body total = game_->player_->body_total; glBindTexture(GL_TEXTURE_2D, tex_body); glActiveTexture(GL_TEXTURE0); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(Body,program,"inPosition","inNormal","inTexCoord"); //Rest of player init tex glBindTexture(GL_TEXTURE_2D, tex_head); glActiveTexture(GL_TEXTURE0); total = game_->player_->head_total; //head glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(Body,program,"inPosition","inNormal","inTexCoord"); //arms total = game_->player_->arm_total_l; //lsft glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(ArmL,program,"inPosition","inNormal","inTexCoord"); total = game_->player_->arm_total_r; //right glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(ArmR,program,"inPosition","inNormal","inTexCoord"); //legs total = game_->player_->leg_total_l; //Left glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(LegL,program,"inPosition","inNormal","inTexCoord"); total = game_->player_->leg_total_r; //Right glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, total.m); DrawModel(LegR,program,"inPosition","inNormal","inTexCoord"); //Lava glBindTexture(GL_TEXTURE_2D, lavatex); glActiveTexture(GL_TEXTURE0); lavatot = Mult(T(0.0,(game_->y_pos_t),0.0),lavatot); lavatot = Mult(lavatot, skyrot); glUniformMatrix4fv(glGetUniformLocation(program, "mdlMatrix"), 1, GL_TRUE, lavatot.m); DrawModel(Lava,program,"inPosition","inNormal","inTexCoord"); //BOOSTERS // ---------------------- ______________------------------ //printf("b1 \n"); bool b_col = game_->maze->b_collision; // printf("bool b_collision: %d \n", b_col ); if (b_col == false){ game_->boost_collision(); draw_boost(game_->maze); b_col = game_->maze->b_collision; if (b_col == true) { // if collision give points time_count += 100; time_boost = (3*(1+game_->ball_speed))*(1/0.02); std::cout << "tB = " << time_boost << std::endl; if (game_->maze->boost == 1) { //if speed game_->ball_speed += 1; } else{ // if imortality game_->imortality = true; } } } draw_boost(game_->maze->right); draw_boost(game_->maze->left); // printf("obstacle main%d \n", obstacle ); // printf("obstaclex main %d \n", obstacle_x_pos ); draw_obsticle(game_->maze); draw_obsticle(game_->maze->left); draw_obsticle(game_->maze->right); if (game_->dead) { sfSetRasterSize(600, 200); sfDrawString(250, 90, "GAME OVER"); GLfloat time_score = time_count; snprintf(buffer, 50, "%f", time_score); sfDrawString(220, 110, "Score: "); sfDrawString(290, 110, buffer); } printError("display 2"); glutSwapBuffers(); }
void reshape(GLsizei w, GLsizei h) { // Viewport is a separate setting glViewport(0, 0, w, h); sfSetRasterSize(w, h); }
void reshape(GLsizei w, GLsizei h) { // Viewport is a separate setting glViewport(0, 0, w, h); sfSetRasterSize(w, h); // update dimensions for font rendering }