// Initialization code void init() { glewExperimental = GL_TRUE; // Initializes the glew library glewInit(); // Read in the shader code from a file. std::string vertShader = readShader("VertexShader.glsl"); std::string fragShader = readShader("FragmentShader.glsl"); // createShader consolidates all of the shader compilation code vertex_shader = createShader(vertShader, GL_VERTEX_SHADER); fragment_shader = createShader(fragShader, GL_FRAGMENT_SHADER); // A shader is a program that runs on your GPU instead of your CPU. In this sense, OpenGL refers to your groups of shaders as "programs". // Using glCreateProgram creates a shader program and returns a GLuint reference to it. program = glCreateProgram(); glAttachShader(program, vertex_shader); // This attaches our vertex shader to our program. glAttachShader(program, fragment_shader); // This attaches our fragment shader to our program. // This links the program, using the vertex and fragment shaders to create executables to run on the GPU. glLinkProgram(program); // End of shader and program creation // Tell our code to use the program glUseProgram(program); // Enables the depth test, which you will want in most cases. You can disable this in the render loop if you need to. glEnable(GL_DEPTH_TEST); // We are drawing a quad, what this means is that we're drawing two triangles to create a rectangle that covers the entire view area. // Thus, we're only passing in 4 vertices in a triangle fan to the vertex shader. It will then call the pixel shader and draw the pixel at it's appropriate coordinate. glm::vec2 quadVerts[4]; quadVerts[0] = glm::vec2(1.0, -1.0); quadVerts[1] = glm::vec2(-1.0, -1.0); quadVerts[2] = glm::vec2(-1.0, 1.0); quadVerts[3] = glm::vec2(1.0, 1.0); // No reason to bother with a Z parameter, as the quad will fill up the entire screen, facing the camera directly, making depth irrelevant. // Generate your vertex array object name. glGenVertexArrays(1, &vao); // Bind the vertex array object glBindVertexArray(vao); // This generates buffer object names // The first parameter is the number of buffer objects, and the second parameter is a pointer to an array of buffer objects (yes, before this call, vbo was an empty variable) // (In this example, there's only one buffer object.) glGenBuffers(1, &vbo); // Binds a named buffer object to the specified buffer binding point. Give it a target (GL_ARRAY_BUFFER) to determine where to bind the buffer. // There are several different target parameters, GL_ARRAY_BUFFER is for vertex attributes, feel free to Google the others to find out what else there is. // The second paramter is the buffer object reference. If no buffer object with the given name exists, it will create one. // Buffer object names are unsigned integers (like vbo). Zero is a reserved value, and there is no default buffer for each target (targets, like GL_ARRAY_BUFFER). // Passing in zero as the buffer name (second parameter) will result in unbinding any buffer bound to that target, and frees up the memory. glBindBuffer(GL_ARRAY_BUFFER, vbo); // Creates and initializes a buffer object's data. // First parameter is the target, second parameter is the size of the buffer, third parameter is a pointer to the data that will copied into the buffer, and fourth parameter is the // expected usage pattern of the data. Possible usage patterns: GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, // GL_DYNAMIC_READ, or GL_DYNAMIC_COPY // Stream means that the data will be modified once, and used only a few times at most. Static means that the data will be modified once, and used a lot. Dynamic means that the data // will be modified repeatedly, and used a lot. Draw means that the data is modified by the application, and used as a source for GL drawing. Read means the data is modified by // reading data from GL, and used to return that data when queried by the application. Copy means that the data is modified by reading from the GL, and used as a source for drawing. glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec2) * 4, &quadVerts[0], GL_STATIC_DRAW); // GL_ARRAY_BUFFER is for vertices in an array, all drawing commands of glDrawArrays will use vertices from that buffer. // By default, all client-side capabilities are disabled, including all generic vertex attribute arrays. // When enabled, the values in a generic vertex attribute array will be accessed and used for rendering when calls are made to vertex array commands (like glDrawArrays/glDrawElements) // A GL_INVALID_VALUE will be generated if the index parameter is greater than or equal to GL_MAX_VERTEX_ATTRIBS glEnableVertexAttribArray(0); // Defines an array of generic vertex attribute data. Takes an index, a size specifying the number of components (in this case, floats)(has a max of 4) // The third parameter, type, can be GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FIXED, or GL_FLOAT // The fourth parameter specifies whether to normalize fixed-point data values, the fifth parameter is the stride which is the offset (in bytes) between generic vertex attributes // The fifth parameter is a pointer to the first component of the first generic vertex attribute in the array. If a named buffer object is bound to GL_ARRAY_BUFFER (and it is, in this case) // then the pointer parameter is treated as a byte offset into the buffer object's data. glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(glm::vec2), (void*)0); // You'll note sizeof(glm::vec2) is our stride, because each vertex is that size. // This gets us a reference to the uniform variables in the vertex shader, which are called by the same name here as in the shader. // We're using these variables to define the camera. The eye is the camera position, and teh rays are the four corner rays of what the camera sees. // Only 2 parameters required: A reference to the shader program and the name of the uniform variable within the shader code. eye = glGetUniformLocation(program, "eye"); ray00 = glGetUniformLocation(program, "ray00"); ray01 = glGetUniformLocation(program, "ray01"); ray10 = glGetUniformLocation(program, "ray10"); ray11 = glGetUniformLocation(program, "ray11"); // This is where we'll set up our camera location at. cameraPos = glm::vec3(4.0f, 8.0f, 8.0f); // These are four corner ray variables to store the output from our calcCameraRays function. glm::vec4 r00; glm::vec4 r01; glm::vec4 r10; glm::vec4 r11; // Call our function to calculate the four corner rays. We're choosing to make the point the camera centeras on at 0, 0.5, 0. // Our FoV angle is 60 degrees and our ratio is 800/600 which is just the pixel ratio. calcCameraRays(cameraPos, glm::vec3(0.0f, 0.5f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), 60.0f, 800.0f/600.0f, &r00, &r01, &r10, &r11); // Now set the uniform variables in the shader to match our camera variables (cameraPos = eye, then four corner rays) glUniform3f(eye, cameraPos.x, cameraPos.y, cameraPos.z); glUniform3f(ray00, r00.x, r00.y, r00.z); glUniform3f(ray01, r01.x, r01.y, r01.z); glUniform3f(ray10, r10.x, r10.y, r10.z); glUniform3f(ray11, r11.x, r11.y, r11.z); // This is not necessary, but I prefer to handle my vertices in the clockwise order. glFrontFace defines which face of the triangles you're drawing is the front. // Essentially, if you draw your vertices in counter-clockwise order, by default (in OpenGL) the front face will be facing you/the screen. If you draw them clockwise, the front face // will face away from you. By passing in GL_CW to this function, we are saying the opposite, and now the front face will face you if you draw in the clockwise order. // If you don't use this, just reverse the order of the vertices in your array when you define them so that you draw the points in a counter-clockwise order. glFrontFace(GL_CW); }
int main () { assert (restart_gl_log ()); /*------------------------------start GL context------------------------------*/ assert (start_gl ()); /*------------------------------create geometry-------------------------------*/ GLfloat points[] = { 0.0f, 0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, -0.5f, 0.0f }; GLfloat colours[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; GLuint points_vbo; glGenBuffers (1, &points_vbo); glBindBuffer (GL_ARRAY_BUFFER, points_vbo); glBufferData (GL_ARRAY_BUFFER, 9 * sizeof (GLfloat), points, GL_STATIC_DRAW); GLuint colours_vbo; glGenBuffers (1, &colours_vbo); glBindBuffer (GL_ARRAY_BUFFER, colours_vbo); glBufferData (GL_ARRAY_BUFFER, 9 * sizeof (GLfloat), colours, GL_STATIC_DRAW); GLuint vao; glGenVertexArrays (1, &vao); glBindVertexArray (vao); glBindBuffer (GL_ARRAY_BUFFER, points_vbo); glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL); glBindBuffer (GL_ARRAY_BUFFER, colours_vbo); glVertexAttribPointer (1, 3, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray (0); glEnableVertexAttribArray (1); /*------------------------------create shaders--------------------------------*/ char vertex_shader[1024 * 256]; char fragment_shader[1024 * 256]; assert (parse_file_into_str ("Shaders/test_vs.glsl", vertex_shader, 1024 * 256)); assert (parse_file_into_str ("Shaders/test_fs.glsl", fragment_shader, 1024 * 256)); GLuint vs = glCreateShader (GL_VERTEX_SHADER); const GLchar* p = (const GLchar*)vertex_shader; glShaderSource (vs, 1, &p, NULL); glCompileShader (vs); // check for compile errors int params = -1; glGetShaderiv (vs, GL_COMPILE_STATUS, ¶ms); if (GL_TRUE != params) { fprintf (stderr, "ERROR: GL shader index %i did not compile\n", vs); print_shader_info_log (vs); return 1; // or exit or something } GLuint fs = glCreateShader (GL_FRAGMENT_SHADER); p = (const GLchar*)fragment_shader; glShaderSource (fs, 1, &p, NULL); glCompileShader (fs); // check for compile errors glGetShaderiv (fs, GL_COMPILE_STATUS, ¶ms); if (GL_TRUE != params) { fprintf (stderr, "ERROR: GL shader index %i did not compile\n", fs); print_shader_info_log (fs); return 1; // or exit or something } GLuint shader_programme = glCreateProgram (); glAttachShader (shader_programme, fs); glAttachShader (shader_programme, vs); glLinkProgram (shader_programme); glGetProgramiv (shader_programme, GL_LINK_STATUS, ¶ms); if (GL_TRUE != params) { fprintf ( stderr, "ERROR: could not link shader programme GL index %i\n", shader_programme ); print_programme_info_log (shader_programme); return false; } /*--------------------------create camera matrices----------------------------*/ /* create PROJECTION MATRIX */ #define ONE_DEG_IN_RAD (2.0 * M_PI) / 360.0 // 0.017444444 // input variables float near = 0.1f; // clipping plane float far = 100.0f; // clipping plane float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio // matrix components float range = tan (fov * 0.5f) * near; float Sx = (2.0f * near) / (range * aspect + range * aspect); float Sy = near / range; float Sz = -(far + near) / (far - near); float Pz = -(2.0f * far * near) / (far - near); GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f, 0.0f, 0.0f, Sz, -1.0f, 0.0f, 0.0f, Pz, 0.0f }; /* create VIEW MATRIX */ float cam_speed = 1.0f; // 1 unit per second float cam_yaw_speed = 10.0f; // 10 degrees per second float cam_pos[] = {0.0f, 0.0f, 2.0f}; // don't start at zero, or we will be too close float cam_yaw = 0.0f; // y-rotation in degrees mat4 T = translate (identity_mat4 (), vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2])); mat4 R = rotate_y_deg (identity_mat4 (), -cam_yaw); mat4 view_mat = R * T; /* get location numbers of matrices in shader programme */ GLint view_mat_location = glGetUniformLocation (shader_programme, "view"); GLint proj_mat_location = glGetUniformLocation (shader_programme, "proj"); /* use program (make current in state machine) and set default matrix values*/ glUseProgram (shader_programme); glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view_mat.m); glUniformMatrix4fv (proj_mat_location, 1, GL_FALSE, proj_mat); /*------------------------------rendering loop--------------------------------*/ /* some rendering defaults */ glEnable (GL_CULL_FACE); // cull face glCullFace (GL_BACK); // cull back face glFrontFace (GL_CW); // GL_CCW for counter clock-wise while (!glfwWindowShouldClose (g_window)) { static double previous_seconds = glfwGetTime (); double current_seconds = glfwGetTime (); double elapsed_seconds = current_seconds - previous_seconds; previous_seconds = current_seconds; _update_fps_counter (g_window); // wipe the drawing surface clear glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport (0, 0, g_gl_width, g_gl_height); glUseProgram (shader_programme); glBindVertexArray (vao); // draw points 0-3 from the currently bound VAO with current in-use shader glDrawArrays (GL_TRIANGLES, 0, 3); // update other events like input handling glfwPollEvents (); /*-----------------------------move camera here-------------------------------*/ // control keys bool cam_moved = false; if (glfwGetKey (g_window, GLFW_KEY_A)) { cam_pos[0] -= cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_D)) { cam_pos[0] += cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_PAGE_UP)) { cam_pos[1] += cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_PAGE_DOWN)) { cam_pos[1] -= cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_W)) { cam_pos[2] -= cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_S)) { cam_pos[2] += cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_LEFT)) { cam_yaw += cam_yaw_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_RIGHT)) { cam_yaw -= cam_yaw_speed * elapsed_seconds; cam_moved = true; } /* update view matrix */ if (cam_moved) { mat4 T = translate (identity_mat4 (), vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2])); // cam translation mat4 R = rotate_y_deg (identity_mat4 (), -cam_yaw); // mat4 view_mat = R * T; glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view_mat.m); } if (GLFW_PRESS == glfwGetKey (g_window, GLFW_KEY_ESCAPE)) { glfwSetWindowShouldClose (g_window, 1); } // put the stuff we've been drawing onto the display glfwSwapBuffers (g_window); } // close GL context and any other GLFW resources glfwTerminate(); return 0; }
int main () { assert (restart_gl_log ()); assert (start_gl ()); reserve_video_memory (); // tell GL to only draw onto a pixel if the shape is closer to the viewer glEnable (GL_DEPTH_TEST); // enable depth-testing glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer" GLfloat points[] = { -0.5f, -0.5f, 0.0f, 0.5f, -0.5f, 0.0f, 0.5f, 0.5f, 0.0f, 0.5f, 0.5f, 0.0f, -0.5f, 0.5f, 0.0f, -0.5f, -0.5f, 0.0f }; GLfloat texcoords[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f }; GLuint points_vbo; glGenBuffers (1, &points_vbo); glBindBuffer (GL_ARRAY_BUFFER, points_vbo); glBufferData (GL_ARRAY_BUFFER, 18 * sizeof (GLfloat), points, GL_STATIC_DRAW); GLuint texcoords_vbo; glGenBuffers (1, &texcoords_vbo); glBindBuffer (GL_ARRAY_BUFFER, texcoords_vbo); glBufferData (GL_ARRAY_BUFFER, 12 * sizeof (GLfloat), texcoords, GL_STATIC_DRAW); GLuint vao; glGenVertexArrays (1, &vao); glBindVertexArray (vao); glBindBuffer (GL_ARRAY_BUFFER, points_vbo); glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL); glBindBuffer (GL_ARRAY_BUFFER, texcoords_vbo); glVertexAttribPointer (1, 2, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray (0); glEnableVertexAttribArray (1); GLuint shader_programme = create_programme_from_files ( "test_vs.glsl", "test_fs.glsl"); #define ONE_DEG_IN_RAD (2.0 * M_PI) / 360.0 // 0.017444444 // input variables float near = 0.1f; // clipping plane float far = 100.0f; // clipping plane float fov = 67.0f * ONE_DEG_IN_RAD; // convert 67 degrees to radians float aspect = (float)g_gl_width / (float)g_gl_height; // aspect ratio // matrix components float range = tan (fov * 0.5f) * near; float Sx = (2.0f * near) / (range * aspect + range * aspect); float Sy = near / range; float Sz = -(far + near) / (far - near); float Pz = -(2.0f * far * near) / (far - near); GLfloat proj_mat[] = { Sx, 0.0f, 0.0f, 0.0f, 0.0f, Sy, 0.0f, 0.0f, 0.0f, 0.0f, Sz, -1.0f, 0.0f, 0.0f, Pz, 0.0f }; float cam_speed = 1.0f; // 1 unit per second float cam_yaw_speed = 10.0f; // 10 degrees per second float cam_pos[] = {0.0f, 0.0f, 2.0f}; // don't start at zero, or we will be too close float cam_yaw = 0.0f; // y-rotation in degrees mat4 T = translate (identity_mat4 (), vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2])); mat4 R = rotate_y_deg (identity_mat4 (), -cam_yaw); mat4 view_mat = R * T; int view_mat_location = glGetUniformLocation (shader_programme, "view"); glUseProgram (shader_programme); glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view_mat.m); int proj_mat_location = glGetUniformLocation (shader_programme, "proj"); glUseProgram (shader_programme); glUniformMatrix4fv (proj_mat_location, 1, GL_FALSE, proj_mat); // load texture GLuint tex; assert (load_texture ("skulluvmap.png", &tex)); glEnable (GL_CULL_FACE); // cull face glCullFace (GL_BACK); // cull back face glFrontFace (GL_CCW); // GL_CCW for counter clock-wise // initialise timers bool dump_video = false; double video_timer = 0.0; // time video has been recording double video_dump_timer = 0.0; // timer for next frame grab double frame_time = 0.04; // 1/25 seconds of time while (!glfwWindowShouldClose (g_window)) { static double previous_seconds = glfwGetTime (); double current_seconds = glfwGetTime (); double elapsed_seconds = current_seconds - previous_seconds; previous_seconds = current_seconds; if (dump_video) { // elapsed_seconds is seconds since last loop iteration video_timer += elapsed_seconds; video_dump_timer += elapsed_seconds; // only record 10s of video, then quit if (video_timer > 10.0) { break; } } _update_fps_counter (g_window); // wipe the drawing surface clear glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport (0, 0, g_gl_width, g_gl_height); glUseProgram (shader_programme); glBindVertexArray (vao); // draw points 0-3 from the currently bound VAO with current in-use shader glDrawArrays (GL_TRIANGLES, 0, 6); // update other events like input handling glfwPollEvents (); if (GLFW_PRESS == glfwGetKey (g_window, GLFW_KEY_F11)) { dump_video = true; } // control keys bool cam_moved = false; if (glfwGetKey (g_window, GLFW_KEY_A)) { cam_pos[0] -= cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_D)) { cam_pos[0] += cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_PAGE_UP)) { cam_pos[1] += cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_PAGE_DOWN)) { cam_pos[1] -= cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_W)) { cam_pos[2] -= cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_S)) { cam_pos[2] += cam_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_LEFT)) { cam_yaw += cam_yaw_speed * elapsed_seconds; cam_moved = true; } if (glfwGetKey (g_window, GLFW_KEY_RIGHT)) { cam_yaw -= cam_yaw_speed * elapsed_seconds; cam_moved = true; } // update view matrix if (cam_moved) { mat4 T = translate (identity_mat4 (), vec3 (-cam_pos[0], -cam_pos[1], -cam_pos[2])); // cam translation mat4 R = rotate_y_deg (identity_mat4 (), -cam_yaw); // mat4 view_mat = R * T; glUniformMatrix4fv (view_mat_location, 1, GL_FALSE, view_mat.m); } if (dump_video) { // check if recording mode is enabled while (video_dump_timer > frame_time) { grab_video_frame (); // 25 Hz so grab a frame video_dump_timer -= frame_time; } } if (GLFW_PRESS == glfwGetKey (g_window, GLFW_KEY_ESCAPE)) { glfwSetWindowShouldClose (g_window, 1); } // put the stuff we've been drawing onto the display glfwSwapBuffers (g_window); } if (dump_video) { dump_video_frames (); } // close GL context and any other GLFW resources glfwTerminate(); return 0; }
int main(int argc, char* argv[]) { hvLogInit(HV_LOG_INFO, stdout); hvPrint("HyperVision design approach test programme: OpenGL + EGL"); /* Create a Window */ gtk_init(&argc, &argv); GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect (window, "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_widget_show (window); /* Initialise display */ EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, &major, &minor); hvErrorCheckEGL("Unable to initialise display"); hvInfo2("Detected EGL version: ", eglQueryString(display, EGL_VERSION)); /* Choose visual and initalise window */ EGLint configs; EGLConfig config; const EGLint attribs[] = { EGL_CONFIG_CAVEAT, EGL_NONE, EGL_COLOR_BUFFER_TYPE, EGL_RGB_BUFFER, EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8, EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE }; eglChooseConfig(display, (const EGLint *) &attribs, &config, 1, &configs); hvErrorCheckEGL("Unable to retrieve visual"); EGLSurface surface = eglCreateWindowSurface(display, config, (EGLNativeWindowType) window, NULL); hvErrorCheckEGL("Unable to create EGL surface"); eglBindAPI(EGL_OPENGL_API); hvErrorCheckEGL("Unable to bing OpenGL API"); EGLContext context = eglCreateContext(display, config, EGL_NO_CONTEXT, NULL); hvErrorCheckEGL("Unable to create context"); if (context != EGL_NO_CONTEXT) hvInfo("Hurra!"); eglMakeCurrent(display, surface, surface, context); hvErrorCheckEGL("Unable to activate rendering context"); /* OpenGL API */ eglBindAPI(EGL_OPENGL_API); hvErrorCheckEGL("Unable to bind OpenGL API"); glGetError(); glClearColor(0.0f, 0.5f, 0.0f, 0.0f); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); hvErrorCheckGL("Could not set OpenGL culling options"); glClear(GL_COLOR_BUFFER_BIT); glFlush(); eglSwapBuffers(display, surface); gtk_main (); eglDestroyContext(display, context); eglTerminate(display); exit(EXIT_SUCCESS); }
//-------------------------------------------------------------- void ofApp::draw(){ glEnable(GL_DEPTH_TEST); /******************** ********************/ apply_gui_parameter(); /******************** 両面を描く glDisable(GL_CULL_FACE); 表面のみを描く glEnable(GL_CULL_FACE); glCullFace(GL_BACK); 裏面のみを描く glEnable(GL_CULL_FACE); glCullFace(GL_FRONT); ********************/ if (b_cull){ if(b_cull_cw) glFrontFace(GL_CW);//時計回りが表 else glFrontFace(GL_CCW);//反時計回りが表 glEnable(GL_CULL_FACE); glCullFace(GL_BACK); // glCullFace(GL_FRONT); }else{ glDisable(GL_CULL_FACE); } /******************** ********************/ cam.begin(); //draw x/y/z axis ofSetLineWidth(3); ofSetColor(255, 0, 0); ofLine(0, 0, 200, 0); ofSetColor(0, 255, 0); ofLine(0, 0, 0, 200); ofSetColor(0, 0, 255); ofLine(0, 0, 0, 0, 0, 200); /******************** ********************/ if (b_useAmb) amb.enable(); else amb.disable(); if (b_useDir) dir.enable(); else dir.disable(); if (b_useSpot) spot.enable(); else spot.disable(); if (b_usePoint) point.enable(); else point.disable(); /******************** enabling lights above will call ofEnableLighting() which will enable GL_COLOR_MATERIAL. This which means calls to ofSetColor() would change material properties, which we dont want here. We want it controlled by the sliders, so we turn it off then turn on our material. ...と、original commentには書いてあったが、 glDisable(GL_COLOR_MATERIAL); の効果がわからなかった。 この行のある/なし に関わらず、 Lightが一つでもある時は、materialとLightの組み合わせで Lightが一つもない時は、ofSetColor(materialColor_when_noLight); によって colorが決定された。 ********************/ glDisable(GL_COLOR_MATERIAL); material.begin(); //we could enable GL_COLOR_MATERIAL set the color here ofSetColor(materialColor_when_noLight); if(!b_Box){ // ofSphere(0,0,0, radius); sphere.setRadius(radius); sphere.setPosition(0, 0, 0); sphere.setResolution(Resolution); sphere.draw(); }else{ box.set(radius); box.setPosition(0, 0, 0); box.setResolution(Resolution); box.draw(); } amb.disable(); dir.disable(); spot.disable(); point.disable(); material.end(); ofDisableLighting(); if (b_useSpot && b_showSpotSource) { ofSetColor(spot.getDiffuseColor()); spot.draw(); } if (b_usePoint && b_showPointSource) { ofSetColor(point.getDiffuseColor()); point.draw(); } if (b_useDir && b_showDirSource) { ofSetColor(dir.getDiffuseColor()); dir.draw(); } cam.end(); /******************** ********************/ glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); gui[id_gui_panel].draw(); }
/** * Function to render and display content. */ GLUSboolean renderWaterTexture(GLUSfloat passedTime) { static WaveParameters waveParameters[NUMBERWAVES]; static WaveDirections waveDirections[NUMBERWAVES]; static GLfloat overallSteepness = 0.2f; // Waves memset(waveParameters, 0, sizeof(waveParameters)); memset(waveDirections, 0, sizeof(waveDirections)); // Wave One waveParameters[0].speed = 0.05f; waveParameters[0].amplitude = 0.02f; waveParameters[0].wavelength = 0.3f; waveParameters[0].steepness = overallSteepness / (waveParameters[0].wavelength * waveParameters[0].amplitude * (GLfloat) NUMBERWAVES); waveDirections[0].x = +1.0f; waveDirections[0].z = +1.5f; // Wave Two waveParameters[1].speed = 0.1f; waveParameters[1].amplitude = 0.01f; waveParameters[1].wavelength = 0.4f; waveParameters[1].steepness = overallSteepness / (waveParameters[1].wavelength * waveParameters[1].amplitude * (GLfloat) NUMBERWAVES); waveDirections[1].x = +0.8f; waveDirections[1].z = +0.2f; // Wave Thre waveParameters[2].speed = 0.04f; waveParameters[2].amplitude = 0.035f; waveParameters[2].wavelength = 0.1f; waveParameters[2].steepness = overallSteepness / (waveParameters[1].wavelength * waveParameters[1].amplitude * (GLfloat) NUMBERWAVES); waveDirections[2].x = -0.2f; waveDirections[2].z = -0.1f; // Wave Four waveParameters[3].speed = 0.05f; waveParameters[3].amplitude = 0.007f; waveParameters[3].wavelength = 0.2f; waveParameters[3].steepness = overallSteepness / (waveParameters[1].wavelength * waveParameters[1].amplitude * (GLfloat) NUMBERWAVES); waveDirections[3].x = -0.4f; waveDirections[3].z = -0.3f; glViewport(0, 0, TEXTURE_SIZE, TEXTURE_SIZE); glBindFramebuffer(GL_FRAMEBUFFER, g_fboWaterTexture); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(g_programWaterTexture.program); glUniform1f(g_passedTimeWaterTextureLocation, passedTime); glUniform4fv(g_waveParametersWaterTextureLocation, 4 * NUMBERWAVES, (GLfloat*) waveParameters); glUniform2fv(g_waveDirectionsWaterTextureLocation, 2 * NUMBERWAVES, (GLfloat*) waveDirections); glFrontFace(GL_CCW); glBindVertexArray(g_vaoWaterTexture); glDrawElements(GL_TRIANGLES, g_numberIndicesWaterTexture, GL_UNSIGNED_INT, 0); // glBindFramebuffer(GL_FRAMEBUFFER, 0); glViewport(0, 0, g_parentWidth, g_parentHeight); return GLUS_TRUE; }
/*!**************************************************************************** @Function RenderScene @Return bool true if no error occured @Description Main rendering loop function of the program. The shell will call this function every frame. eglSwapBuffers() will be performed by PVRShell automatically. PVRShell will also manage important OS events. Will also manage relevent OS events. The user has access to these events through an abstraction layer provided by PVRShell. ******************************************************************************/ bool OGLES3StencilBuffer::RenderScene() { m_fAngle += 0.005f; // Clear the color, depth and stencil buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // Use shader program glUseProgram(m_ShaderProgram.uiId); /* Set up the transformation matrices for our two shapes (the cylinder and the sphere) */ PVRTMat4 mSphere, mCylinder; PVRTMat4 mTrans, mRotZ, mRotX, mScale; mScale = PVRTMat4::Scale((float)PVRShellGet(prefHeight)/(float)PVRShellGet(prefWidth), 1.0f, 1.0f); mRotZ = PVRTMat4::RotationX(m_fAngle); mSphere = mRotZ * mScale; mTrans = PVRTMat4::Translation(-0.4f, -0.5f, 0.0f); mRotZ = PVRTMat4::RotationZ(m_fAngle); mRotX = PVRTMat4::RotationX(m_fAngle); mCylinder = mScale * mRotX * mRotZ * mTrans; // Bind texture and set transform glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_uiStoneTex); glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMVPMatrix], 1, GL_FALSE, mSphere.ptr()); glCullFace(GL_BACK); glFrontFace(GL_CW); /* Draw the sphere This sphere is textured with the stone texture and will be visible outside the stencil volume as we are drawing a second sphere with a green tiles texture everywhere within the stencil geometry. Also this sphere is used to set the depth values in the Z-Buffer. */ m_Sphere.DrawMesh(0); /* Enable the stencil test, disable color and depth writes */ glEnable(GL_STENCIL_TEST); glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE ); glDepthMask(GL_FALSE); /* What we are going to do is draw a volume (a cylinder) so that all front faces that are in front of the already rendered geometry (the sphere) increase the stencil value by one, while all back faces that are in front of the rendered geometry decrease the stencil value. This way only surfaces that intersect the stencil volume will get a stencil value != 0. Since OpenGL ES 2.0 offers two-sided stencil, we can do this in a single pass. */ // Disable culling as we want to use the back and front faces of the geometry. glDisable(GL_CULL_FACE); /* glStencilFunc tells OGLES3 the type of per-pixel test that we want to do. In the case below GL_ALWAYS says we want the test to always pass. The third value is the mask value which is ANDed with the second value (the reference value) to create the value that is put in the stencil buffer. Alternative values for the first value are GL_NEVER which causes the test to never pass. GL_LESS Passes if ( ref & mask ) < ( stencil & mask ) GL_LEQUAL Passes if ( ref & mask ) <= ( stencil & mask ) GL_GREATER Passes if ( ref & mask ) > ( stencil & mask ) GL_GEQUAL Passes if ( ref & mask ) >= ( stencil & mask ) GL_EQUAL Passes if ( ref & mask ) = ( stencil & mask ) GL_NOTEQUAL Passes if ( ref & mask ) != ( stencil & mask ) A call to glStencilFunc is the same as calling glStencilFuncSeparate with GL_FRONT_AND_BACK */ glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF); /* glStencilOp has 3 parameters. The first parameter specifies the action to take if the stencil test fails. The second specifies the stencil action to take if the stencil test passes but the depth test fails. The third one specifies the stencil action when the stencil test and the depth test pass, or when the stencil test passes and their is no depth testing done. These three parameters can be set to one of the following GL_KEEP Keeps the current value. GL_ZERO Sets the stencil buffer value to zero. GL_REPLACE Sets the stencil buffer value to ref, as specified by glStencilFunc. GL_INCR Increments the current stencil buffer value. Clamps to the maximum representable unsigned value. GL_DECR Decrements the current stencil buffer value. Clamps to zero. GL_INCR_WRAP Increments the current stencil buffer value and wraps round to zero if the value is above the maximum. GL_DECR_WRAP Decrements the current stencil buffer value and wraps it round to the maximum if it goes below zero. GL_INVERT Bitwise inverts the current stencil buffer value. We're going to do our stencil operations in one pass so we need to specify an operation for each face type using the glStencilOpSeparate function which takes an extra variable. This variable will define which face type we'll work on and it can be set to GL_FRONT GL_BACK GL_FRONT_AND_BACK In our case we are going to use GL_INCR_WRAP for the front faces and GL_DECR_WRAP for the back faces. As the geometry will be processed in the order it is submitted we can't guarantee that we'll do all the INCR operations first therefore we are using INCR_WRAP and DECR_WRAP so the values don't get clamped at the minimum and maximum possible values. */ glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_INCR_WRAP); glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_DECR_WRAP); glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMVPMatrix], 1, GL_FALSE, mCylinder.ptr()); m_Cylinder.DrawMesh(0); /* Enable drawing to the colour buffer again as what we draw now we want to be visible. Switch back to back face culling and enable the depth test again. */ #if defined(__PALMPDK__) glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); // The alpha part is false as we don't want to blend with the video layer on the Palm Pre #else glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); #endif glDepthMask(GL_TRUE); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); /* Set the stencil test to draw only pixels that are inside the stencil volume */ glStencilFunc(GL_NOTEQUAL, 0, 0xFFFFFFFF); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glBindTexture(GL_TEXTURE_2D, m_uiTileTex); glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMVPMatrix], 1, GL_FALSE, mSphere.ptr()); m_Sphere.DrawMesh(0); /* Disable the stencil test as it is no longer needed.*/ glDisable(GL_STENCIL_TEST); /* Draw the cylinder with alpha blending, back faces first then front faces */ glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, m_uiCylinderTex); glUniformMatrix4fv(m_ShaderProgram.auiLoc[eMVPMatrix], 1, GL_FALSE, mCylinder.ptr()); // Draw back faces of the cylinder glCullFace(GL_FRONT); m_Cylinder.DrawMesh(0); // Draw the front faces glCullFace(GL_BACK); m_Cylinder.DrawMesh(0); // Disable blending as it is no longer required glDisable(GL_BLEND); // Displays the demo name using the tools. For a detailed explanation, see the training course IntroducingPVRTools m_Print3D.DisplayDefaultTitle("Stencil Buffer", "", ePVRTPrint3DSDKLogo); m_Print3D.Flush(); return true; }
static void Init(ModeInfo *mi) { atlantisstruct *ap = &atlantis[MI_SCREEN(mi)]; static const float ambient[] = {0.1, 0.1, 0.1, 1.0}; static const float diffuse[] = {1.0, 1.0, 1.0, 1.0}; static const float position[] = {0.0, 1.0, 0.0, 0.0}; static const float mat_shininess[] = {90.0}; static const float mat_specular[] = {0.8, 0.8, 0.8, 1.0}; static const float mat_diffuse[] = {0.46, 0.66, 0.795, 1.0}; static const float mat_ambient[] = {0.0, 0.1, 0.2, 1.0}; static const float lmodel_ambient[] = {0.4, 0.4, 0.4, 1.0}; static const float lmodel_localviewer[] = {0.0}; float fblue = 0.0, fgreen; glFrontFace(GL_CCW); if (ap->wire) { glDisable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); glDisable(GL_LIGHTING); glDisable(GL_NORMALIZE); } else { glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glEnable(GL_NORMALIZE); glShadeModel(GL_SMOOTH); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_localviewer); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); } if (ap->wire || !do_texture) { glDisable(GL_TEXTURE_2D); } else { GLfloat scale = 0.0005; if (!ap->texture) parse_image_data (mi); clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ap->texture->width, ap->texture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, ap->texture->data); check_gl_error("texture"); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); # ifndef HAVE_JWZGLES { GLfloat s_plane[] = { 1, 0, 0, 0 }; GLfloat t_plane[] = { 0, 0, 1, 0 }; glTexGeni (GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni (GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_S, GL_EYE_PLANE, s_plane); glTexGenfv(GL_T, GL_EYE_PLANE, t_plane); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); } # endif glEnable(GL_TEXTURE_2D); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(scale, scale, 1); glMatrixMode(GL_MODELVIEW); } InitFishs(ap); /* Add a little randomness */ fblue = ((float) (NRAND(30)) / 100.0) + 0.70; fgreen = fblue * 0.56; glClearColor(0.0, fgreen, fblue, 1.0); }
static void render_unlocked(glw_root_t *gr) { glw_backend_root_t *gbr = &gr->gr_be; render_state_t rs = {0}; int64_t ts = arch_get_ts(); int current_blendmode = GLW_BLEND_NORMAL; glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE); const float *vertices = gr->gr_vertex_buffer; glBindBuffer(GL_ARRAY_BUFFER, gbr->gbr_vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(float) * VERTEX_SIZE * gr->gr_vertex_offset, vertices, GL_STATIC_DRAW); int current_frontface = GLW_CCW; glFrontFace(GL_CCW); vertices = NULL; glVertexAttribPointer(0, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices); glVertexAttribPointer(1, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices + 4); glVertexAttribPointer(2, 4, GL_FLOAT, 0, sizeof(float) * VERTEX_SIZE, vertices + 8); for(int j = 0; j < gr->gr_num_render_jobs; j++) { const glw_render_order_t *ro = gr->gr_render_order + j; const glw_render_job_t *rj = ro->job; if(unlikely(rj->num_vertices == 0)) continue; const struct glw_backend_texture *t0 = rj->t0; glw_program_t *gp = load_program(gr, t0, rj->t1, rj->blur, rj->flags, rj->gpa, &rs, rj); if(gbr->gbr_use_stencil_buffer) glStencilFunc(GL_GEQUAL, ro->zindex, 0xFF); if(unlikely(gp == NULL)) { #if ENABLE_GLW_BACKEND_OPENGL if(rj->eyespace) { glLoadMatrixf(glw_identitymtx); } else { glLoadMatrixf(glw_mtx_get(rj->m)); } glBegin(GL_QUADS); if(t0 != NULL) glTexCoord2i(0, t0->height); glVertex3i(-1, -1, 0); if(t0 != NULL) glTexCoord2i(t0->width, t0->height); glVertex3i(1, -1, 0); if(t0 != NULL) glTexCoord2i(t0->width, 0); glVertex3i(1, 1, 0); if(t0 != NULL) glTexCoord2i(0, 0); glVertex3i(-1, 1, 0); glEnd(); glDisable(t0->gltype); #endif continue; } else { glUniform4f(gp->gp_uniform_color_offset, rj->rgb_off.r, rj->rgb_off.g, rj->rgb_off.b, 0); glUniform4f(gbr->gbr_current->gp_uniform_color, rj->rgb_mul.r, rj->rgb_mul.g, rj->rgb_mul.b, rj->alpha); if(gp->gp_uniform_time != -1) glUniform1f(gp->gp_uniform_time, gr->gr_time_sec); if(gp->gp_uniform_resolution != -1) glUniform3f(gp->gp_uniform_resolution, rj->width, rj->height, 1); if(gp->gp_uniform_blur != -1 && t0 != NULL) glUniform3f(gp->gp_uniform_blur, rj->blur, 1.5 / t0->width, 1.5 / t0->height); if(rj->eyespace) { glUniformMatrix4fv(gp->gp_uniform_modelview, 1, 0, glw_identitymtx); } else { glUniformMatrix4fv(gp->gp_uniform_modelview, 1, 0, glw_mtx_get(rj->m)); } } if(unlikely(current_blendmode != rj->blendmode)) { current_blendmode = rj->blendmode; switch(current_blendmode) { case GLW_BLEND_NORMAL: glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA, GL_ONE); break; case GLW_BLEND_ADDITIVE: glBlendFuncSeparate(GL_SRC_COLOR, GL_ONE, GL_ONE_MINUS_DST_ALPHA, GL_ONE); break; } } if(unlikely(current_frontface != rj->frontface)) { current_frontface = rj->frontface; glFrontFace(current_frontface == GLW_CW ? GL_CW : GL_CCW); } glDrawArrays(rj->primitive_type, rj->vertex_offset, rj->num_vertices); } if(current_blendmode != GLW_BLEND_NORMAL) { glBlendFuncSeparate(GL_SRC_COLOR, GL_ONE, GL_ONE_MINUS_DST_ALPHA, GL_ONE); } ts = arch_get_ts() - ts; static int hold; hold++; if(hold < 20) return; #if 0 static int cnt; static int64_t tssum; tssum += ts; cnt++; printf("%16d (%d) %d saved texloads\n", (int)ts, (int)(tssum/cnt), rs.texload_skips); #endif }
ENTRYPOINT void init_planet (ModeInfo * mi) { planetstruct *gp; int screen = MI_SCREEN(mi); Bool wire = MI_IS_WIREFRAME(mi); if (planets == NULL) { if ((planets = (planetstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (planetstruct))) == NULL) return; } gp = &planets[screen]; if ((gp->glx_context = init_GL(mi)) != NULL) { reshape_planet(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } { char *f = get_string_resource(mi->dpy, "imageForeground", "Foreground"); char *b = get_string_resource(mi->dpy, "imageBackground", "Background"); char *s; if (!f) f = strdup("white"); if (!b) b = strdup("black"); for (s = f + strlen(f)-1; s > f; s--) if (*s == ' ' || *s == '\t') *s = 0; for (s = b + strlen(b)-1; s > b; s--) if (*s == ' ' || *s == '\t') *s = 0; if (!XParseColor(mi->dpy, mi->xgwa.colormap, f, &gp->fg)) { fprintf(stderr, "%s: unparsable color: \"%s\"\n", progname, f); exit(1); } if (!XParseColor(mi->dpy, mi->xgwa.colormap, b, &gp->bg)) { fprintf(stderr, "%s: unparsable color: \"%s\"\n", progname, f); exit(1); } free (f); free (b); } { double spin_speed = 0.1; double wander_speed = 0.005; gp->rot = make_rotator (do_roll ? spin_speed : 0, do_roll ? spin_speed : 0, 0, 1, do_wander ? wander_speed : 0, True); gp->z = frand (1.0); gp->tilt = frand (23.4); gp->trackball = gltrackball_init (True); } if (wire) do_texture = False; if (do_texture) setup_texture (mi); if (do_stars) init_stars (mi); /* construct the polygons of the planet */ gp->platelist = glGenLists(1); glNewList (gp->platelist, GL_COMPILE); glFrontFace(GL_CCW); glPushMatrix(); glRotatef (90, 1, 0, 0); unit_sphere (resolution, resolution, wire); glPopMatrix(); glEndList(); gp->shadowlist = glGenLists(1); glNewList (gp->shadowlist, GL_COMPILE); glFrontFace(GL_CCW); unit_dome (resolution, resolution, wire); glEndList(); /* construct the polygons of the latitude/longitude/axis lines. */ gp->latlonglist = glGenLists(1); glNewList (gp->latlonglist, GL_COMPILE); glPushMatrix (); glRotatef (90, 1, 0, 0); /* unit_sphere is off by 90 */ glRotatef (8, 0, 1, 0); /* line up the time zones */ unit_sphere (12, 24, 1); unit_sphere (12, 24, 1); glBegin(GL_LINES); glVertex3f(0, -2, 0); glVertex3f(0, 2, 0); glEnd(); glPopMatrix (); glEndList(); }
void Scene::init() { _shaderProgram = createShaderProgramWithFilenames("PosColorLocalTransform.vert", "ColorPassthrough.frag"); glUseProgram(_shaderProgram); printOpenGLError(); // Uniforms modelToCameraMatrixUniform = glGetUniformLocation(_shaderProgram, "modelToCameraMatrix"); cameraToClipMatrixUniform = glGetUniformLocation(_shaderProgram, "cameraToClipMatrix"); // Matrix float fzNear = 1.0f; float fzFar = 45.0f; cameraToClipMatrix[0].x = frustumScale; cameraToClipMatrix[1].y = frustumScale; cameraToClipMatrix[2].z = (fzFar + fzNear) / (fzNear - fzFar); cameraToClipMatrix[2].w = -1.0f; cameraToClipMatrix[3].z = (2 * fzFar * fzNear) / (fzNear - fzFar); glUniformMatrix4fv(cameraToClipMatrixUniform, 1, GL_FALSE, glm::value_ptr(cameraToClipMatrix)); // Vertex buffer objects glGenBuffers(1, &_vertexBufferObject); glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObject); glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glGenBuffers(1, &indexBufferObject); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indexData), indexData, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); printOpenGLError(); // Vertex array objects glGenVertexArrays(1, &_vertexArrayObject); glBindVertexArray(_vertexArrayObject); size_t colorDataOffset = sizeof(float) * 3 * numberOfVertices; glBindBuffer(GL_ARRAY_BUFFER, _vertexBufferObject); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, (void*)colorDataOffset); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferObject); glBindVertexArray(0); printOpenGLError(); // Enable cull facing glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); printOpenGLError(); // Enable depth testing glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glDepthRange(0.0f, 1.0f); }
void COGLGraphicsContext::InitState(void) { m_pRenderStr = glGetString(GL_RENDERER); m_pExtensionStr = glGetString(GL_EXTENSIONS); m_pVersionStr = glGetString(GL_VERSION); m_pVendorStr = glGetString(GL_VENDOR); glMatrixMode(GL_PROJECTION); OPENGL_CHECK_ERRORS; glLoadIdentity(); OPENGL_CHECK_ERRORS; glClearColor(0.0f, 0.0f, 0.0f, 0.0f); OPENGL_CHECK_ERRORS; glClearDepth(1.0f); OPENGL_CHECK_ERRORS; #ifndef USE_GLES glShadeModel(GL_SMOOTH); OPENGL_CHECK_ERRORS; //position viewer //glMatrixMode(GL_MODELVIEW); //glLoadIdentity(); glDisable(GL_ALPHA_TEST); OPENGL_CHECK_ERRORS; #endif glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); OPENGL_CHECK_ERRORS; glDisable(GL_BLEND); OPENGL_CHECK_ERRORS; glFrontFace(GL_CCW); OPENGL_CHECK_ERRORS; glDisable(GL_CULL_FACE); OPENGL_CHECK_ERRORS; #ifndef USE_GLES glDisable(GL_NORMALIZE); OPENGL_CHECK_ERRORS; #endif glDepthFunc(GL_LEQUAL); OPENGL_CHECK_ERRORS; glEnable(GL_DEPTH_TEST); OPENGL_CHECK_ERRORS; #ifndef USE_GLES glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); OPENGL_CHECK_ERRORS; #endif glEnable(GL_BLEND); OPENGL_CHECK_ERRORS; #ifndef USE_GLES glEnable(GL_ALPHA_TEST); OPENGL_CHECK_ERRORS; glMatrixMode(GL_PROJECTION); OPENGL_CHECK_ERRORS; glLoadIdentity(); OPENGL_CHECK_ERRORS; glDepthRange(-1, 1); #else glDepthRangef(0.0f, 1.0f); #endif OPENGL_CHECK_ERRORS; }
void DemoApplication::renderme() { myinit(); updateCamera(); if (m_dynamicsWorld) { if(m_enableshadows) { glClear(GL_STENCIL_BUFFER_BIT); glEnable(GL_CULL_FACE); renderscene(0); glDisable(GL_LIGHTING); glDepthMask(GL_FALSE); glDepthFunc(GL_LEQUAL); glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); glStencilFunc(GL_ALWAYS,1,0xFFFFFFFFL); glFrontFace(GL_CCW); glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); renderscene(1); glFrontFace(GL_CW); glStencilOp(GL_KEEP,GL_KEEP,GL_DECR); renderscene(1); glFrontFace(GL_CCW); glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_BACK,GL_FILL); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_LIGHTING); glDepthMask(GL_TRUE); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); glDepthFunc(GL_LEQUAL); glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL ); glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); glDisable(GL_LIGHTING); renderscene(2); glEnable(GL_LIGHTING); glDepthFunc(GL_LESS); glDisable(GL_STENCIL_TEST); glDisable(GL_CULL_FACE); } else { glDisable(GL_CULL_FACE); renderscene(0); } int xOffset = 10; int yStart = 20; int yIncr = 20; glDisable(GL_LIGHTING); glColor3f(0, 0, 0); if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0) { setOrthographicProjection(); showProfileInfo(xOffset,yStart,yIncr); #ifdef USE_QUICKPROF if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings) { static int counter = 0; counter++; std::map<std::string, hidden::ProfileBlock*>::iterator iter; for (iter = btProfiler::mProfileBlocks.begin(); iter != btProfiler::mProfileBlocks.end(); ++iter) { char blockTime[128]; sprintf(blockTime, "%s: %lf",&((*iter).first[0]),btProfiler::getBlockTime((*iter).first, btProfiler::BLOCK_CYCLE_SECONDS));//BLOCK_TOTAL_PERCENT)); glRasterPos3f(xOffset,yStart,0); GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),blockTime); yStart += yIncr; } } #endif //USE_QUICKPROF resetPerspectiveProjection(); } glEnable(GL_LIGHTING); } updateCamera(); }
bool glWindow::ResetGL () { if (m_resetGLMode == RGM_RECREATEWINDOW) { RecreateWindow (m_fullScreen, m_border, m_width, m_height, m_bpp, m_stencil, m_title, m_allowResizing, m_fitToWorkArea); return true; } else if (m_resetGLMode == RGM_RECREATECONTEXT) { RecreateGLContext (); return true; } // Setup OpenGL defaults. // This should reset as much as possible back to the initial state of OpenGL. // Exceptions: // * Projection matrix is initialised to a perspective transform // End current gl block try { glEnd (); } catch (...) { ; } m_dontPaint = false; // Intialise matrices try { glMatrixMode (GL_PROJECTION); ClearGLMatrix (); } catch (...) { ; } try { glMatrixMode (GL_TEXTURE); ClearGLMatrix (); } catch (...) { ; } try { glMatrixMode (GL_MODELVIEW); ClearGLMatrix (); } catch (...) { ; } // Initialise state int i; try { glColor4f (1, 1, 1, 1); } catch (...) { ; } try { glIndexi (1); } catch (...) { ; } try { glTexCoord4f (0, 0, 0, 1); } catch (...) { ; } try { glNormal3f (0, 0, 1); } catch (...) { ; } // try { glRasterPos4f (0, 0, 0, 1); } catch (...) { ; } try { glEdgeFlag (GL_TRUE); } catch (...) { ; } try { glDisable (GL_VERTEX_ARRAY); } catch (...) { ; } try { glDisable (GL_NORMAL_ARRAY); } catch (...) { ; } try { glDisable (GL_COLOR_ARRAY); } catch (...) { ; } try { glDisable (GL_INDEX_ARRAY); } catch (...) { ; } try { glDisable (GL_TEXTURE_COORD_ARRAY); } catch (...) { ; } try { glDisable (GL_EDGE_FLAG_ARRAY); } catch (...) { ; } try { glDepthRange (0, 1); } catch (...) { ; } try { glDisable (GL_NORMALIZE); } catch (...) { ; } for (i = 0; i < GL_MAX_CLIP_PLANES; i++) try { glDisable (GL_CLIP_PLANE0 + i); } catch (...) { ; } GLfloat fog[] = {0, 0, 0, 0}; try { glFogfv (GL_FOG_COLOR, fog); } catch (...) { ; } try { glFogi (GL_FOG_INDEX, 0); } catch (...) { ; } try { glFogf (GL_FOG_DENSITY, 1.0); } catch (...) { ; } try { glFogf (GL_FOG_START, 0.0); } catch (...) { ; } try { glFogf (GL_FOG_END, 1.0); } catch (...) { ; } try { glFogi (GL_FOG_MODE, GL_EXP); } catch (...) { ; } try { glDisable (GL_FOG); } catch (...) { ; } try { glShadeModel (GL_SMOOTH); } catch (...) { ; } try { glDisable (GL_LIGHTING); } catch (...) { ; } try { glDisable (GL_COLOR_MATERIAL); } catch (...) { ; } try { glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); } catch (...) { ; } GLfloat ambient[] = { 0.2, 0.2, 0.2, 1.0 }, diffuse[] = { 0.8, 0.8, 0.8, 1.0 }, specular[] = { 0.0, 0.0, 0.0, 1.0 }, emission[] = { 0.0, 0.0, 0.0, 1.0 }, shininess[] = { 0.0 }; try { glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, ambient); } catch (...) { ; } try { glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse); } catch (...) { ; } try { glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, specular); } catch (...) { ; } try { glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION, emission); } catch (...) { ; } try { glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, shininess); } catch (...) { ; } try { glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient); } catch (...) { ; } try { glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE); } catch (...) { ; } try { glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); } catch (...) { ; } GLfloat lambient[] = { 0.0, 0.0, 0.0, 1.0 }, ldiffuse0[] = { 1.0, 1.0, 1.0, 1.0 }, ldiffuse1[] = { 0.0, 0.0, 0.0, 1.0 }, lspecular0[] = { 1.0, 1.0, 1.0, 1.0 }, lspecular1[] = { 0.0, 0.0, 0.0, 1.0 }, lposition[] = { 0.0, 0.0, 1.0, 0.0 }; for (i = 0; i < 8; i++) { try { glLightfv (GL_LIGHT0 + i, GL_AMBIENT, lambient); } catch (...) { ; } try { glLightfv (GL_LIGHT0 + i, GL_DIFFUSE, i == 0 ? ldiffuse0 : ldiffuse1); } catch (...) { ; } try { glLightfv (GL_LIGHT0 + i, GL_SPECULAR, i == 0 ? lspecular0 : lspecular1); } catch (...) { ; } try { glLightfv (GL_LIGHT0 + i, GL_POSITION, lposition); } catch (...) { ; } try { glLightf (GL_LIGHT0 + i, GL_SPOT_EXPONENT, 0.0); } catch (...) { ; } try { glLightf (GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 1.0); } catch (...) { ; } try { glLightf (GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 0.0); } catch (...) { ; } try { glLightf (GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 0.0); } catch (...) { ; } try { glDisable (GL_LIGHT0 + i); } catch (...) { ; } } try { glPointSize (1.0); } catch (...) { ; } try { glDisable (GL_POINT_SMOOTH); } catch (...) { ; } try { glLineWidth (1.0); } catch (...) { ; } try { glDisable (GL_LINE_SMOOTH); } catch (...) { ; } try { glLineStipple (1, 0xffff); } catch (...) { ; } try { glDisable (GL_LINE_STIPPLE); } catch (...) { ; } try { glDisable (GL_CULL_FACE); } catch (...) { ; } try { glCullFace (GL_BACK); } catch (...) { ; } try { glFrontFace (GL_CCW); } catch (...) { ; } try { glDisable (GL_POLYGON_SMOOTH); } catch (...) { ; } try { glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); } catch (...) { ; } try { glDisable (GL_TEXTURE_1D); } catch (...) { ; } try { glDisable (GL_TEXTURE_2D); } catch (...) { ; } try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } catch (...) { ; } try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } catch (...) { ; } try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); } catch (...) { ; } try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); } catch (...) { ; } GLfloat texBorder[] = {0, 0, 0, 0}; try { glTexParameterfv (GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, texBorder); } catch (...) { ; } try { glDisable (GL_TEXTURE_GEN_T); } catch (...) { ; } try { glDisable (GL_TEXTURE_GEN_S); } catch (...) { ; } try { glDisable (GL_TEXTURE_GEN_R); } catch (...) { ; } try { glDisable (GL_TEXTURE_GEN_Q); } catch (...) { ; } for (i = 0; i < 4; i++) { GLenum coord; switch (i) { case 0: coord = GL_T; break; case 1: coord = GL_S; break; case 2: coord = GL_R; break; case 3: coord = GL_Q; break; } try { glTexGeni (coord, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); } catch (...) { ; } } try { glDisable (GL_SCISSOR_TEST); } catch (...) { ; } try { glDisable (GL_ALPHA_TEST); } catch (...) { ; } try { glAlphaFunc (GL_ALWAYS, 0); } catch (...) { ; } try { glDisable (GL_STENCIL_TEST); } catch (...) { ; } try { glStencilFunc (GL_ALWAYS, 0, 0xffffffff); } catch (...) { ; } try { glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP); } catch (...) { ; } try { glDisable (GL_DEPTH_TEST); } catch (...) { ; } try { glDepthFunc (GL_LESS); } catch (...) { ; } try { glDisable (GL_BLEND); } catch (...) { ; } try { glBlendFunc (GL_ONE, GL_ZERO); } catch (...) { ; } try { glDrawBuffer (GL_BACK); } catch (...) { ; } try { glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); } catch (...) { ; } try { glDepthMask (GL_TRUE); } catch (...) { ; } try { glClearAccum (0, 0, 0, 0); } catch (...) { ; } try { glClearColor (0, 0, 0, 0); } catch (...) { ; } try { glClearDepth (1); } catch (...) { ; } try { glClearIndex (0); } catch (...) { ; } try { glClearStencil (0); } catch (...) { ; } try { glPixelStorei (GL_PACK_SWAP_BYTES, GL_FALSE); } catch (...) { ; } try { glPixelStorei (GL_PACK_LSB_FIRST, GL_FALSE); } catch (...) { ; } try { glPixelStoref (GL_PACK_ROW_LENGTH, 0); } catch (...) { ; } try { glPixelStoref (GL_PACK_SKIP_PIXELS, 0); } catch (...) { ; } try { glPixelStorei (GL_PACK_ALIGNMENT, 4); } catch (...) { ; } try { glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); } catch (...) { ; } try { glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); } catch (...) { ; } try { glPixelStoref (GL_UNPACK_ROW_LENGTH, 0); } catch (...) { ; } try { glPixelStoref (GL_UNPACK_SKIP_PIXELS, 0); } catch (...) { ; } try { glPixelStorei (GL_UNPACK_ALIGNMENT, 4); } catch (...) { ; } try { glPixelTransferi (GL_MAP_COLOR, GL_FALSE); } catch (...) { ; } try { glPixelTransferi (GL_MAP_STENCIL, GL_FALSE); } catch (...) { ; } try { glPixelTransferi (GL_INDEX_SHIFT, 0); } catch (...) { ; } try { glPixelTransferi (GL_INDEX_OFFSET, 0); } catch (...) { ; } try { glPixelTransferf (GL_RED_SCALE, 1.0); } catch (...) { ; } try { glPixelTransferf (GL_GREEN_SCALE, 1.0); } catch (...) { ; } try { glPixelTransferf (GL_BLUE_SCALE, 1.0); } catch (...) { ; } try { glPixelTransferf (GL_ALPHA_SCALE, 1.0); } catch (...) { ; } try { glPixelTransferf (GL_DEPTH_SCALE, 1.0); } catch (...) { ; } try { glPixelTransferf (GL_RED_BIAS, 0.0); } catch (...) { ; } try { glPixelTransferf (GL_GREEN_BIAS, 0.0); } catch (...) { ; } try { glPixelTransferf (GL_BLUE_BIAS, 0.0); } catch (...) { ; } try { glPixelTransferf (GL_ALPHA_BIAS, 0.0); } catch (...) { ; } try { glPixelTransferf (GL_DEPTH_BIAS, 0.0); } catch (...) { ; } try { glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE); } catch (...) { ; } try { glHint (GL_POINT_SMOOTH_HINT, GL_DONT_CARE); } catch (...) { ; } try { glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE); } catch (...) { ; } try { glHint (GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE); } catch (...) { ; } try { glHint (GL_FOG_HINT, GL_DONT_CARE); } catch (...) { ; } // Multitexturing if (ExtensionSupported ("GL_ARB_multitexture")) { // Disable texturing for all texture units int units; try { glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &units); } catch (...) { ; } for (int i = 0; i < units; i++) { if (glActiveTexture != NULL) glActiveTexture (GL_TEXTURE0_ARB + i); try { glDisable (GL_TEXTURE_2D); } catch (...) { ; } try { glDisable (GL_TEXTURE_1D); } catch (...) { ; } if (i == 0) try { glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } catch (...) { ; } else try { glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); } catch (...) { ; } } if (glActiveTexture != NULL) try { glActiveTexture (GL_TEXTURE0_ARB); } catch (...) { ; } } // Setup OpenGL defaults OpenGLDefaults (); return TRUE; // Initialization Went OK }
int unit_teapot (int grid, int wire_p) { GLenum type = wire_p ? GL_LINE : GL_FILL; float p[4][4][3], q[4][4][3], r[4][4][3], s[4][4][3]; long i, j, k, l; int polys = 0; glPushAttrib(GL_ENABLE_BIT | GL_EVAL_BIT); glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); glEnable(GL_MAP2_VERTEX_3); glEnable(GL_MAP2_TEXTURE_COORD_2); glFrontFace (GL_CW); glPushMatrix(); glRotatef(270.0, 1.0, 0.0, 0.0); glScalef(0.5, 0.5, 0.5); glTranslatef(0.0, 0.0, -1.5); for (i = 0; i < 10; i++) { for (j = 0; j < 4; j++) { for (k = 0; k < 4; k++) { for (l = 0; l < 3; l++) { p[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]; q[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l]; if (l == 1) q[j][k][l] *= -1.0; if (i < 6) { r[j][k][l] = cpdata[patchdata[i][j * 4 + (3 - k)]][l]; if (l == 0) r[j][k][l] *= -1.0; s[j][k][l] = cpdata[patchdata[i][j * 4 + k]][l]; if (l == 0) s[j][k][l] *= -1.0; if (l == 1) s[j][k][l] *= -1.0; } } } } glMap2f(GL_MAP2_TEXTURE_COORD_2, 0, 1, 2, 2, 0, 1, 4, 2, &tex[0][0][0]); glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &p[0][0][0]); glMapGrid2f(grid, 0.0, 1.0, grid, 0.0, 1.0); glEvalMesh2(type, 0, grid, 0, grid); polys += grid*grid*2; glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &q[0][0][0]); glEvalMesh2(type, 0, grid, 0, grid); polys += grid*grid*2; if (i < 6) { glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &r[0][0][0]); glEvalMesh2(type, 0, grid, 0, grid); polys += grid*grid*2; glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, &s[0][0][0]); glEvalMesh2(type, 0, grid, 0, grid); polys += grid*grid*2; } } glPopMatrix(); glPopAttrib(); return polys; }
GLFWwindow* gfx::GraphicsEngine::Initialize( int width, int height, bool vsync, bool fullscreen ){ m_Width = width; m_Height = height; if( !glfwInit( ) ) return nullptr; //glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); //glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); //glfwWindowHint(GLFW_DECORATED, GL_FALSE); if(fullscreen){ m_Window = glfwCreateWindow( width, height, "ModelViewer", glfwGetPrimaryMonitor( ), nullptr ); }else{ m_Window = glfwCreateWindow( width, height, "ModelViewer", nullptr, nullptr ); } if(!m_Window) return nullptr; glfwMakeContextCurrent( m_Window ); ImGui_ImplGlfwGL3_Init( m_Window, true ); glewExperimental = GL_TRUE; glewInit( ); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); if(vsync){ glfwSwapInterval( 1 ); }else{ glfwSwapInterval( 0 ); } glClearColor(0.2f, 0.2f, 0.2f, 1.0f); //set camera float aspectRatio = width / (float)height; m_Camera.GetEditableLens( ).Near = 0.1f; m_Camera.GetEditableLens( ).Far = 100.0f; m_Camera.GetEditableLens( ).VerticalFOV = ( ( 90.0f / ( aspectRatio ) ) / 360.0f ) * 2 * glm::pi<float>( ); // calc FOV as horisontal FOV 90 degrees m_Camera.GetEditableLens().WindowHeight = height - BUTTON_SIZE * 2; m_Camera.GetEditableLens().WindowWidth = (int)(width * 0.5f); m_Camera.SetPosition(glm::vec3(0.0f, 10.0f, 20.0f)); m_Camera.CalculateViewProjection(); //load shaders m_Shader = g_ShaderBank.LoadShaderProgram( "shader/CombinedShader.glsl" ); m_SpriteShader = g_ShaderBank.LoadShaderProgram("shader/SpriteShader.glsl"); m_GizmoProgram = g_ShaderBank.LoadShaderProgram("shader/GizmoProgram.glsl"); m_LineProgram = g_ShaderBank.LoadShaderProgram("shader/LineShader.glsl"); //Load cubeTex m_SkyTex = new Texture(); m_SkyTex->Init("asset/CubeMaps/square.dds", TEXTURE_CUBE); m_IrradianceTex = new Texture(); m_IrradianceTex->Init("asset/CubeMaps/square_irr.dds", TEXTURE_CUBE); m_FrameBuffer.Init(); glGenBuffers(1, &m_LineVBO); glGenVertexArrays(1, &m_LineVAO); glBindVertexArray(m_LineVAO); glBindBuffer(GL_ARRAY_BUFFER, m_LineVBO); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec2) * 100000, nullptr, GL_DYNAMIC_DRAW); //allocate buffer return m_Window; }
void Graphic::Initialize() { GLuint Vao; glfwInit(); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwOpenWindow( 800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ); glewExperimental = GL_TRUE; glewInit(); glfwSetWindowTitle( "Hej!" ); glEnable( GL_DEPTH_TEST ); glEnable( GL_CULL_FACE ); glEnable( GL_BLEND ); glCullFace( GL_BACK ); glFrontFace( GL_CCW ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glClearColor( 0.5f, 0.5f, 0.5f, 0.5f ); glDepthFunc( GL_LESS ); glm::vec3 eye( 0.f, 0.f, 5.f ), centre( 0.f, 0.f, 0.f ), up( 0.f, 1.f, 0.f ); viewMatrix = glm::lookAt(eye, centre, up); shaderProgram = CreateShader( "Source/shader.vertex", "Source/shader.fragment" ); shaderLine = CreateShader( "Source/line.vertex", "Source/line.fragment" ); shaderText = CreateShader( "Source/text.vertex", "Source/text.fragment" ); Texture t; glGenTextures( (int)Type::Size + 43, glTexture ); int i = 0; #define DEFAULT_TEXTURE_OPTIONS \ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); \ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); \ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB8, t.width, t.height, 0, GL_BGR, GL_UNSIGNED_BYTE, &t[0] ); #define FOO( CLASS, ARRAY, NUMBER ) \ t.LoadBmp( #CLASS ".bmp" ); \ assert( i == NUMBER ); \ glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); \ DEFAULT_TEXTURE_OPTIONS TYPE_TABLE #undef FOO t.LoadBmp( "Mountain.bmp" ); mountain = i; glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS t.LoadBmp( "Forest.bmp" ); forest = i; glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS // Load char numbers for( char j(0); j < 10; j++ ) { char_textures[ std::to_string(j)[0] ] = i; t.LoadBmp( "Font/" + std::to_string(j) + ".bmp" ); glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS } // Load char letters for( char j(0); j < 26; j++ ) { char_textures[ 'A'+j ] = i; std::stringstream s; s << "Font/" << (char)('A'+j) << ".bmp"; t.LoadBmp( s.str() ); glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS } char_textures[ '/' ] = i; t.LoadBmp( "Font/forward_slash.bmp" ); glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS char_textures[ '+' ] = i; t.LoadBmp( "Font/plus.bmp" ); glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS char_textures[ '-' ] = i; t.LoadBmp( "Font/minus.bmp" ); glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS char_textures[ '#' ] = i; t.LoadBmp( "food.bmp" ); glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS char_textures[ '$' ] = i; t.LoadBmp( "money.bmp" ); glBindTexture( GL_TEXTURE_2D, glTexture[i++] ); DEFAULT_TEXTURE_OPTIONS #undef DEFAULT_TEXTURE_OPTIONS lines.push_back( Line( vertexs[0], vertexs[1], vertexs[3], vertexs[4] ) ); lines.push_back( Line( vertexs[6], vertexs[7], vertexs[9], vertexs[10] ) ); // Vertex, normal, texture, text glGenBuffers( 3, Vbo ); int size = 4 * sizeof(float); glBindBuffer(GL_ARRAY_BUFFER, Vbo[0]); glBufferData(GL_ARRAY_BUFFER, lines.size() * 2 * 3 * sizeof(float), &lines[0], GL_DYNAMIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, Vbo[1]); glBufferData(GL_ARRAY_BUFFER, size * 3, &normals[0], GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, Vbo[2]); glBufferData(GL_ARRAY_BUFFER, size * 2, &textureCoordinates[0], GL_STATIC_DRAW); glGenVertexArrays(1, &Vao); glBindVertexArray(Vao); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); GLubyte* null = 0; glBindBuffer(GL_ARRAY_BUFFER, Vbo[0]); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, null); glBindBuffer(GL_ARRAY_BUFFER, Vbo[1]); glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, null); glBindBuffer(GL_ARRAY_BUFFER, Vbo[2]); glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, null); glBindVertexArray(Vao); }
void Draw( double t ) { double xpos, ypos, zpos, angle_x, angle_y, angle_z; static double t_old = 0.0; float dt; // Calculate frame-to-frame delta time dt = (float)(t-t_old); t_old = t; // Setup viewport glViewport( 0, 0, width, height ); // Clear color and Z-buffer glClearColor( 0.1f, 0.1f, 0.1f, 1.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); // Setup projection glMatrixMode( GL_PROJECTION ); glLoadIdentity(); gluPerspective( 65.0, (double)width/(double)height, 1.0, 60.0 ); // Setup camera glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); // Rotate camera angle_x = 90.0 - 10.0; angle_y = 10.0 * sin( 0.3 * t ); angle_z = 10.0 * t; glRotated( -angle_x, 1.0, 0.0, 0.0 ); glRotated( -angle_y, 0.0, 1.0, 0.0 ); glRotated( -angle_z, 0.0, 0.0, 1.0 ); // Translate camera xpos = 15.0 * sin( (M_PI/180.0) * angle_z ) + 2.0 * sin( (M_PI/180.0) * 3.1 * t ); ypos = -15.0 * cos( (M_PI/180.0) * angle_z ) + 2.0 * cos( (M_PI/180.0) * 2.9 * t ); zpos = 4.0 + 2.0 * cos( (M_PI/180.0) * 4.9 * t ); glTranslated( -xpos, -ypos, -zpos ); // Enable face culling glFrontFace( GL_CCW ); glCullFace( GL_BACK ); glEnable( GL_CULL_FACE ); // Enable lighting SetupLights(); glEnable( GL_LIGHTING ); // Enable fog (dim details far away) glEnable( GL_FOG ); glFogi( GL_FOG_MODE, GL_EXP ); glFogf( GL_FOG_DENSITY, 0.05f ); glFogfv( GL_FOG_COLOR, fog_color ); // Draw floor DrawFloor(); // Enable Z-buffering glEnable( GL_DEPTH_TEST ); glDepthFunc( GL_LEQUAL ); glDepthMask( GL_TRUE ); // Draw fountain DrawFountain(); // Disable fog & lighting glDisable( GL_LIGHTING ); glDisable( GL_FOG ); // Draw all particles (must be drawn after all solid objects have been // drawn!) DrawParticles( t, dt ); // Z-buffer not needed anymore glDisable( GL_DEPTH_TEST ); }
static void draw_floater (ModeInfo *mi, floater *f) { toaster_configuration *bp = &bps[MI_SCREEN(mi)]; GLfloat n; glFrontFace(GL_CCW); glPushMatrix(); glTranslatef (f->x, f->y, f->z); if (f->toaster_p) { glPushMatrix(); glRotatef (180, 0, 1, 0); glCallList (bp->dlists[BASE_TOASTER]); mi->polygon_count += (*all_objs[BASE_TOASTER])->points / 3; glPopMatrix(); glPushMatrix(); glTranslatef(0, 1.01, 0); n = 0.91; glScalef(n,n,n); glCallList (bp->dlists[SLOTS]); mi->polygon_count += (*all_objs[SLOTS])->points / 3; glPopMatrix(); glPushMatrix(); glRotatef (180, 0, 1, 0); glTranslatef(0, -0.4, -2.38); n = 0.33; glScalef(n,n,n); glCallList (bp->dlists[HANDLE_SLOT]); mi->polygon_count += (*all_objs[HANDLE_SLOT])->points / 3; glPopMatrix(); glPushMatrix(); glTranslatef(0, -1.1, 3); n = 0.3; glScalef (n,n,n); glTranslatef(0, f->handle_pos * 4.8, 0); glCallList (bp->dlists[HANDLE]); mi->polygon_count += (*all_objs[HANDLE])->points / 3; glPopMatrix(); glPushMatrix(); glRotatef (180, 0, 1, 0); glTranslatef(0, -1.1, -3); /* where the handle is */ glTranslatef (1, -0.4, 0); /* down and to the left */ n = 0.08; glScalef (n,n,n); glRotatef (f->knob_pos, 0, 0, 1); glCallList (bp->dlists[KNOB]); mi->polygon_count += (*all_objs[KNOB])->points / 3; glPopMatrix(); glPushMatrix(); glRotatef (180, 0, 1, 0); glTranslatef (0, -2.3, 0); glCallList (bp->dlists[BASE]); mi->polygon_count += (*all_objs[BASE])->points / 3; glPopMatrix(); glPushMatrix(); glTranslatef(-4.8, 0, 0); glCallList (bp->dlists[JET_WING]); mi->polygon_count += (*all_objs[JET_WING])->points / 3; glScalef (0.5, 0.5, 0.5); glTranslatef (-2, -1, 0); glCallList (bp->dlists[JET]); mi->polygon_count += (*all_objs[JET])->points / 3; glPopMatrix(); glPushMatrix(); glTranslatef(4.8, 0, 0); glScalef(-1, 1, 1); glFrontFace(GL_CW); glCallList (bp->dlists[JET_WING]); mi->polygon_count += (*all_objs[JET_WING])->points / 3; glScalef (0.5, 0.5, 0.5); glTranslatef (-2, -1, 0); glCallList (bp->dlists[JET]); mi->polygon_count += (*all_objs[JET])->points / 3; glFrontFace(GL_CCW); glPopMatrix(); if (f->loaded) { glPushMatrix(); glTranslatef(0, 1.01, 0); n = 0.91; glScalef(n,n,n); glRotatef (90, 0, 0, 1); glRotatef (90, 0, 1, 0); glTranslatef(0, 0, -0.95); glTranslatef(0, 0.72, 0); if (f->loaded & 1) { glCallList (bp->dlists[TOAST]); mi->polygon_count += (*all_objs[TOAST])->points / 3; } glTranslatef(0, -1.46, 0); if (f->loaded & 2) { glCallList (bp->dlists[TOAST]); mi->polygon_count += (*all_objs[TOAST])->points / 3; } glPopMatrix(); } } else { glScalef (0.7, 0.7, 0.7); if (f->toast_type == 0) { glCallList (bp->dlists[TOAST]); mi->polygon_count += (*all_objs[TOAST])->points / 3; } else { glCallList (bp->dlists[TOAST_BITTEN]); mi->polygon_count += (*all_objs[TOAST_BITTEN])->points / 3; } } glPopMatrix(); }
void CSm3GroundDrawer::Draw(bool drawWaterReflection,bool drawUnitReflection,unsigned int overrideVP) { if(drawUnitReflection || drawWaterReflection) return; terrain::RenderContext *currc; if (drawWaterReflection) { if (!reflectrc) { reflectrc = tr->AddRenderContext(&reflectCam, true); tr->Update(); } SpringCamToTerrainCam(*camera, reflectCam); currc = reflectrc; } else currc = rc; tr->SetShaderParams(gs->sunVector, currc->cam->pos); if (shadowHandler->drawShadows) { terrain::ShadowMapParams params; shadowHandler->GetShadowMapSizeFactors (params.f_a, params.f_b); params.mid [0] = shadowHandler->xmid; params.mid [1] = shadowHandler->ymid; params.shadowMap = shadowHandler->shadowTexture; for (int a=0;a<16;a++) params.shadowMatrix[a] = shadowHandler->shadowMatrix[a]; tr->SetShadowParams (¶ms); } tr->SetActiveContext (currc); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); glColor4f(1.0f,1.0f,1.0f,1.0f); glEnable(GL_LIGHTING); glLightfv(GL_LIGHT0, GL_POSITION,gs->sunVector4); float d[4]={0.0f,0.0f,0.0f,1.0f}; for (int a=0;a<3;a++) d[a]=map->sunColor[a]; glLightfv(GL_LIGHT0, GL_DIFFUSE, d); for (int a=0;a<3;a++) d[a]=map->ambientColor[a]; glLightfv(GL_LIGHT0, GL_AMBIENT, d); for (int a=0;a<3;a++) d[a]=map->specularColor[a]; glLightfv (GL_LIGHT0, GL_SPECULAR, d); for (int a=0;a<4;a++) d[a]=0.0f; glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, d); const float zero[] = { 0.0f, 0.0f, 0.0f, 1.0f }; glLightModelfv (GL_LIGHT_MODEL_AMBIENT, zero); glDisable(GL_LIGHT1); glEnable(GL_LIGHT0); glEnable(GL_RESCALE_NORMAL); // glLightfv (GL_LIGHT0, GL_SPOT_DIRECTION,dir.getf()); // glLightf (GL_LIGHT0, GL_SPOT_CUTOFF, 90.0f); /* const float ambient[] = { 0.4f, 0.4f, 0.4f, 1.0f }; const float diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glLightfv (GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv (GL_LIGHT0, GL_AMBIENT, ambient); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); const float md[] = { 1.0f, 1.0f, 1.0f, 1.0f }; glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, md); glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, md); glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);*/ ///////////////////// tr->Draw (); glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); if (drawMode != drawNormal) { glEnable(GL_BLEND); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.0f,- 10.0f); glColor4f(1.0f,1.0f,1.0f,0.5f); tr->DrawOverlayTexture (infoTex); glDisable(GL_POLYGON_OFFSET_FILL); glDepthMask(GL_FALSE); glDisable(GL_BLEND); } glFrontFace(GL_CCW); glDisable(GL_CULL_FACE); glColor3ub(255,255,255); DrawObjects(drawWaterReflection, drawUnitReflection); glActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); }
RenderingEngine::RenderingEngine(){ glDepthMask(GL_TRUE); glFrontFace(GL_CCW); glCullFace(GL_BACK); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_CLAMP); const int numGBuffers = 8; GLenum filters[numGBuffers] = { GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_LINEAR, GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR, GL_LINEAR, GL_NEAREST }; GLenum internalFormats[numGBuffers] = { GL_RGBA, GL_RGBA16F, GL_RGBA16F, GL_R32F, GL_RGBA, GL_RGBA16F, GL_RGBA16F, GL_R32F }; GLenum formats[numGBuffers] = { GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA, GL_RGBA }; GLenum attachments[numGBuffers] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3, GL_COLOR_ATTACHMENT4, GL_COLOR_ATTACHMENT5, GL_COLOR_ATTACHMENT6, GL_COLOR_ATTACHMENT7 }; setTexture("gBuffer", Texture::makePtr(new Texture(4, 800, 600, GL_TEXTURE_2D, filters, internalFormats, formats, false, attachments))); setTexture("gBufferTransparency", Texture::makePtr(new Texture(4, 800, 600, GL_TEXTURE_2D, filters, internalFormats, formats, false, attachments))); setTexture("targetBuffer", Texture::makePtr(new Texture(0, 800, 600, GL_TEXTURE_2D, GL_LINEAR, GL_RGBA, GL_RGBA, false, GL_COLOR_ATTACHMENT0))); setTexture("transparencyBuffer", Texture::makePtr(new Texture(0, 800, 600, GL_TEXTURE_2D, GL_LINEAR, GL_RGBA, GL_RGBA, false, GL_COLOR_ATTACHMENT0))); setTexture("transparencyShandowColorBuffer", Texture::makePtr(new Texture(0, 1024, 1024, GL_TEXTURE_2D, GL_LINEAR, GL_RGBA, GL_RGBA, false, GL_COLOR_ATTACHMENT0))); setTexture("TestTexture", Texture::makePtr(new Texture("res/textures/Grid.png"))); int numShandowMaps = 10; for (int i = 0; i < numShandowMaps; i++){ int shandowMapSize = 1 << (i + 1); shandowMaps.push_back(Texture::makePtr(new Texture(0, shandowMapSize, shandowMapSize, GL_TEXTURE_2D, GL_NEAREST, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0))); transparencyShandowMaps.push_back(Texture::makePtr(new Texture(0, shandowMapSize, shandowMapSize, GL_TEXTURE_2D, GL_NEAREST, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0))); shandowMapTempTargets.push_back(Texture::makePtr(new Texture(0, shandowMapSize, shandowMapSize, GL_TEXTURE_2D, GL_NEAREST, GL_RG32F, GL_RGBA, true, GL_COLOR_ATTACHMENT0))); } setTexture("shandowMap", shandowMaps.at(0)); canvas = new RenderCanvas; canvas->getMaterial()->setVector("color", Vector3(0, 0, 0)); canvas->getMaterial()->setFloat("blue",1); altCamera = Camera::makePtr(70.f, (float)CoreEngine::window->getWidth() / (float)CoreEngine::window->getHeight(), 0.001f, 1000.0f); cameraObject = GameObject::makePtr(); cameraObject->addComponent(altCamera); transparentOverride = false; setPointer("writeShader", new Shader("deferred/deferred-writer")); setPointer("defaultShader", new Shader("defaultShader")); setPointer("ambientShader", new Shader("deferred/deferred-ambient")); setPointer("shandowMapGenerator", new Shader("shandowMapGenerator")); setPointer("gausBlurFilter", new Shader("filter-gausBlur7x1")); setPointer("depthMapGenerator", new Shader("depthMapGenerator")); setPointer("transparentShader", new Shader("deferred/transparentBlend")); setPointer("multiAphaFilter", new Shader("filter-multiplyAlpha")); setPointer("testShader", new Shader("testShader")); Shader::addStaticCallback(UUCallback([](Transform* transform, Material* material, RenderingEngine* renderingEngine, const Shader& shader, Uniform& localUniform, Uniform& storedUniform){ if (localUniform.getType() == "sampler2D"){ int _pos = localUniform.getName().find_first_of('_', 3); std::string postfix = localUniform.getName().substr(_pos + 1, localUniform.getName().length() - _pos); bool isGbuffer = localUniform.getName().find("gBuffer") != localUniform.getName().npos && localUniform.getName().find("Transparency") == localUniform.getName().npos; if (isGbuffer && postfix.at(postfix.length() - 1) == 'T'){ localUniform.setName("R_gBufferTransparency_" + postfix.substr(0, 1)); } else if (renderingEngine->transparentOverride && isGbuffer){ localUniform.setName("R_gBufferTransparency_" + postfix.substr(0, 1)); } } return false; } )); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); MappedValues::setVector("ambient", Vector3(0.1f, 0.1f, 0.1f)); MappedValues::setFloat("useMVP", 1.0f); samplerMap["diffuse"] = 14; samplerMap["normalMap"] = 1; samplerMap["dispMap"] = 2; samplerMap["shandowMap"] = 3; samplerMap["gBuffer_0"] = 4; samplerMap["gBuffer_1"] = 5; samplerMap["gBuffer_2"] = 6; samplerMap["gBuffer_3"] = 7; samplerMap["gBufferTransparency_0"] = 8; samplerMap["gBufferTransparency_1"] = 9; samplerMap["gBufferTransparency_2"] = 10; samplerMap["gBufferTransparency_3"] = 11; samplerMap["transparencyShandowMap"] = 12; samplerMap["transparencyShandowColorBuffer"] = 13; CoreEngine::window->bindAsRenderTarget(); }
void BaseApp::RenderUnderwaterNormalMap() { glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, g_texWaterReflect.GetID(), 0 ); glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, g_depthRenderBuffer2 ); glViewport( 0, 0, 512, 512 ); glMatrixMode(GL_PROJECTION); glLoadMatrixf(projMat); glMatrixMode(GL_MODELVIEW); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glDepthMask(GL_FALSE); glDisable(GL_DEPTH_TEST); m_camera.BuildViewMatrix(&modelViewMat); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(modelViewMat); glScalef(1.0f, -1.0f, 1.0f); glFrontFace(GL_CW); glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_CUBE_MAP_ARB); glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, m_texCubeUnderwaterNormMap.GetID()); static float a = 0.0f; a+=0.02f; glPushMatrix(); glTranslatef(m_camera.m_vEye.x, -m_camera.m_vEye.y - 500, m_camera.m_vEye.z); glDepthMask(GL_FALSE); glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); //glTranslatef(a, 0.0f, 0.0f); glRotatef(a, 0.0f, 5.0f, 5.0f); m_skydome.RenderCubeMap(); glRotatef(-2*a, 0.5f, 0.5f, 0.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 0.5f); m_skydome.RenderCubeMap(); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glDisable(GL_BLEND); glMatrixMode(GL_TEXTURE); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glDepthMask(GL_TRUE); glPopMatrix(); glDisable(GL_TEXTURE_CUBE_MAP_ARB); glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glViewport( 0, 0, m_width, m_height); glFrontFace(GL_CCW); }
void CShaderAPIOES2::ResetRenderState(bool bFullReset) { int i; if (!IsDeactivated()) { glFrontFace(GL_CW); glEnable(GL_CULL_FACE); // glCullFace(GL_BACK); // Never changed. glDisable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glStencilFunc(GL_ALWAYS, 0, 0xffffffff); glStencilMask(0xffffffff); glDisable(GL_SCISSOR_TEST); glDisable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(0.0f, 0.0f); glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // glBlendColor(1.0f, 1.0f, 1.0f, 1.0f); // Constant color blending modes are not used. // glBlendEquation(GL_FUNC_ADD); // Never changed. glActiveTexture(GL_TEXTURE0); glClearDepthf(1.0f); glClearStencil(0); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); } m_CurrentSnapshot = -1; m_CachedFastClipProjectionMatrix.Identity(); m_SceneFogColor[0] = m_SceneFogColor[1] = m_SceneFogColor[2] = 0; m_SceneFogMode = MATERIAL_FOG_NONE; m_DynamicState.m_ClearColor[0] = m_DynamicState.m_ClearColor[1] = m_DynamicState.m_ClearColor[2] = m_DynamicState.m_ClearColor[3] = 0; m_ClearColorChanged = true; m_ClearReverseDepth = false; m_ClearStencil = 0; m_ZWriteEnable = true; StandardConstantChanged(OES2_SHADER_CONST_AMBIENT_LIGHT); m_WorldSpaceCameraPosition.Init(0.0f, 0.0f, 0.0f); m_DynamicState.m_PixelFogColor[0] = m_DynamicState.m_PixelFogColor[1] = m_DynamicState.m_PixelFogColor[2] = 0.0f; m_DynamicState.m_FogStart = 0.0f; m_DynamicState.m_FogEnd = 0.0f; m_DynamicState.m_FogMaxDensity = 1.0f; m_DynamicState.m_FogZ = 1.0f; UpdateFogConstant(); // Shadow state applied in ShaderAPI. m_DynamicState.m_CullEnabled = true; m_DynamicState.m_FrontFace = GL_CW; m_DynamicState.m_DepthBiasEnabled = false; m_DynamicState.m_NumBones = 0; for (i = HardwareConfig()->Caps().m_NumCombinedSamplers; i-- > 0; ) m_BoundTextures[i] = INVALID_SHADERAPI_TEXTURE_HANDLE; m_PixelShaderLightingChanged = true; m_VertexShaderLightingChanged = true; for (i = MAX_NUM_LIGHTS; i--; ) m_DynamicState.m_LightEnable[i] = false; for (i = NUM_MATRIX_MODES; i--; ) m_DynamicState.m_TransformType[i] = TRANSFORM_IS_GENERAL; StandardConstantChanged(OES2_SHADER_CONST_MODELVIEWPROJ); StandardConstantChanged(OES2_SHADER_CONST_VIEWPROJ); StandardConstantChanged(OES2_SHADER_CONST_MODEL); m_TransitionTable.UseDefaultState(); SetDefaultState(); if (bFullReset) { SetAnisotropicLevel(1); float *pBoneMatrix; for (i = 16; i--; ) { pBoneMatrix = m_BoneMatrix[i]; memset(pBoneMatrix, 0, sizeof(float) * 12); pBoneMatrix[0] = 1.0f; pBoneMatrix[5] = 1.0f; pBoneMatrix[10] = 1.0f; } MatrixMode(MATERIAL_VIEW); LoadIdentity(); MatrixMode(MATERIAL_PROJECTION); LoadIdentity(); } int width, height; GetBackBufferDimensions(width, height); m_Viewport.Init(0, 0, width, height); m_ViewportChanged = true; m_ViewportZChanged = true; m_ScissorEnabled = m_DynamicState.m_ScissorEnabled = false; m_DynamicState.m_ScissorRect.x = m_DynamicState.m_ScissorRect.y = m_DynamicState.m_ScissorRect.width = m_DynamicState.m_ScissorRect.height = -1; m_ScissorRectChanged = true; EnableFastClip(false); float fakePlane[4]; int fakePlaneVal = -1; fakePlane[0] = fakePlane[1] = fakePlane[2] = fakePlane[3] = *((float *)(&fakePlaneVal)); SetFastClipPlane(fakePlane); m_DynamicState.m_FastClipPlaneChanged = true; m_pRenderMesh = NULL; MeshMgr()->SetVertexDecl(VERTEX_FORMAT_UNKNOWN); SetRenderTarget(SHADER_RENDERTARGET_BACKBUFFER, SHADER_RENDERTARGET_DEPTHBUFFER); m_ActiveTexture = SHADER_SAMPLER0; m_UnpackAlignment = 4; }
/****************************************************************************** *############################################################################* *# Screen functions #* *############################################################################* ******************************************************************************/ void openglInit() { /*setting up OpenGL*/ screen_w = 10; screen_h = 10; global_screenratio = 1.0; glViewport(0, 0, 10, 10); glMatrixMode(GL_PROJECTION); glLoadIdentity(); vp_wrel = vp_hrel = FALSE; vp_top = vp_left = 0; vp_width = vp_height = 10; glClearColor(0.0f, 0.0f, 0.0f, 1.0f); wireframe2d = FALSE; wireframe3d = FALSE; shading = GL_SMOOTH; lighting = TRUE; texture2d = TRUE; texture3d = TRUE; glFrontFace(GL_CCW); glCullFace(GL_BACK); glDepthFunc(GL_LEQUAL); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); global_forceblend = FALSE; glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glHint(GL_FOG_HINT, GL_FASTEST); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, TRUE); curcount = 0; count = 0; fog = FALSE; fogdensity = 0.0; fogcolor[0] = 0.5; fogcolor[1] = 0.5; fogcolor[2] = 0.5; fogcolor[3] = 1.0; /*core declaration*/ MOD_ID = coreDeclareModule("opengl", NULL, NULL, shellCallback, NULL, NULL, NULL); FUNC_WIREFRAME = coreDeclareShellFunction(MOD_ID, "wireframe", VAR_VOID, 2, VAR_INT, VAR_INT); FUNC_FOG = coreDeclareShellFunction(MOD_ID, "fog", VAR_VOID, 1, VAR_INT); FUNC_LIGHTING = coreDeclareShellFunction(MOD_ID, "lighting", VAR_VOID, 2, VAR_INT, VAR_INT); FUNC_TEXTURE = coreDeclareShellFunction(MOD_ID, "texture", VAR_VOID, 2, VAR_INT, VAR_INT); FUNC_COUNT = coreDeclareShellFunction(MOD_ID, "count", VAR_INT, 0); /*OpenGL info*/ shellPrintf(LEVEL_INFO, " -> OpenGL version: %s", (const char*)glGetString(GL_VERSION)); shellPrintf(LEVEL_INFO, " -> OpenGL vendor: %s", (const char*)glGetString(GL_VENDOR)); shellPrintf(LEVEL_INFO, " -> OpenGL renderer: %s", (const char*)glGetString(GL_RENDERER)); shellPrintf(LEVEL_DEBUG, " -> OpenGL extensions: %s", (const char*)glGetString(GL_EXTENSIONS)); /*GLU info*/ shellPrintf(LEVEL_INFO, " -> GLU version: %s", (const char*)gluGetString(GLU_VERSION)); shellPrintf(LEVEL_DEBUG, " -> GLU extensions: %s", (const char*)gluGetString(GLU_EXTENSIONS)); }
void bulletBaseApp::renderme() { myinit(); updateCamera(); if (m_dynamicsWorld) { if(m_enableshadows) { glClear(GL_STENCIL_BUFFER_BIT); glEnable(GL_CULL_FACE); renderscene(0); glDisable(GL_LIGHTING); glDepthMask(GL_FALSE); glDepthFunc(GL_LEQUAL); glEnable(GL_STENCIL_TEST); glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE); glStencilFunc(GL_ALWAYS,1,0xFFFFFFFFL); glFrontFace(GL_CCW); glStencilOp(GL_KEEP,GL_KEEP,GL_INCR); renderscene(1); glFrontFace(GL_CW); glStencilOp(GL_KEEP,GL_KEEP,GL_DECR); renderscene(1); glFrontFace(GL_CCW); glPolygonMode(GL_FRONT,GL_FILL); glPolygonMode(GL_BACK,GL_FILL); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glEnable(GL_LIGHTING); glDepthMask(GL_TRUE); glCullFace(GL_BACK); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glColorMask(GL_TRUE,GL_TRUE,GL_TRUE,GL_TRUE); glDepthFunc(GL_LEQUAL); glStencilFunc( GL_NOTEQUAL, 0, 0xFFFFFFFFL ); glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP ); glDisable(GL_LIGHTING); renderscene(2); glEnable(GL_LIGHTING); glDepthFunc(GL_LESS); glDisable(GL_STENCIL_TEST); glDisable(GL_CULL_FACE); } else { glDisable(GL_CULL_FACE); renderscene(0); } int xOffset = 10; int yStart = 20; int yIncr = 20; char buf[124]; glDisable(GL_LIGHTING); glColor3f(0, 0, 0); if ((m_debugMode & btIDebugDraw::DBG_NoHelpText)==0) { setOrthographicProjection(); showProfileInfo(xOffset,yStart,yIncr); #ifdef USE_QUICKPROF if ( getDebugMode() & btIDebugDraw::DBG_ProfileTimings) { static int counter = 0; counter++; std::map<std::string, hidden::ProfileBlock*>::iterator iter; for (iter = btProfiler::mProfileBlocks.begin(); iter != btProfiler::mProfileBlocks.end(); ++iter) { char blockTime[128]; sprintf(blockTime, "%s: %lf",&((*iter).first[0]),btProfiler::getBlockTime((*iter).first, btProfiler::BLOCK_CYCLE_SECONDS));//BLOCK_TOTAL_PERCENT)); glRasterPos3f(xOffset,yStart,0); GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),blockTime); yStart += yIncr; } } #endif //USE_QUICKPROF sprintf(buf,"mouse to interact"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"ALT + mouse to move camera"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"space to reset"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"cursor keys and z,x to navigate"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"i to toggle simulation, s single step"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"q to quit"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,". to shoot box"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; // not yet hooked up again after refactoring... sprintf(buf,"d to toggle deactivation"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"g to toggle mesh animation (ConcaveDemo)"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"h to toggle help text"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"o to toggle orthogonal/perspective view"); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; //bool useBulletLCP = !(getDebugMode() & btIDebugDraw::DBG_DisableBulletLCP); //bool useCCD = (getDebugMode() & btIDebugDraw::DBG_EnableCCD); //glRasterPos3f(xOffset,yStart,0); //sprintf(buf,"1 CCD mode (adhoc) = %i",useCCD); //GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),buf); //yStart += yIncr; sprintf(buf,"+- shooting speed = %10.2f",m_ShootBoxInitialSpeed); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; #ifdef SHOW_NUM_DEEP_PENETRATIONS sprintf(buf,"gNumDeepPenetrationChecks = %d",gNumDeepPenetrationChecks); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"gNumGjkChecks= %d",gNumGjkChecks); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"gNumClampedCcdMotions = %d",gNumClampedCcdMotions); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"gNumSplitImpulseRecoveries= %d",gNumSplitImpulseRecoveries); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"gNumAlignedAllocs = %d",gNumAlignedAllocs); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"gNumAlignedFree= %d",gNumAlignedFree); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"# alloc-free = %d",gNumAlignedAllocs-gNumAlignedFree); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; //enable BT_DEBUG_MEMORY_ALLOCATIONS define in Bullet/src/LinearMath/btAlignedAllocator.h for memory leak detection #ifdef BT_DEBUG_MEMORY_ALLOCATIONS glRasterPos3f(xOffset,yStart,0); sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs); GLDebugDrawString(BMF_GetFont(BMF_kHelvetica10),buf); yStart += yIncr; #endif //BT_DEBUG_MEMORY_ALLOCATIONS if (getDynamicsWorld()) { glRasterPos3f(xOffset,yStart,0); sprintf(buf,"# objects = %d",getDynamicsWorld()->getNumCollisionObjects()); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; glRasterPos3f(xOffset,yStart,0); sprintf(buf,"# pairs = %d",getDynamicsWorld()->getBroadphase()->getOverlappingPairCache()->getNumOverlappingPairs()); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; sprintf(buf,"# hitPos = %f,%f,%f",gHitPos.getX(),gHitPos.getY(),gHitPos.getZ()); GLDebugDrawString(xOffset,yStart,buf); yStart += yIncr; } #endif //SHOW_NUM_DEEP_PENETRATIONS resetPerspectiveProjection(); } glEnable(GL_LIGHTING); } updateCamera(); }
bool MwOpenGL1_1GraphicsDevice::SetRenderTargetWindow(void *windowHandle) { if (*(HWND*)this->windowHandle_HWND == *(HWND*)windowHandle) return true; PIXELFORMATDESCRIPTOR pixelFormatDescriptor = { sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor 1, // Version Number PFD_DRAW_TO_WINDOW | // Format Must Support Window PFD_SUPPORT_OPENGL | // Format Must Support OpenGL PFD_DOUBLEBUFFER, // Must Support Double Buffering PFD_TYPE_RGBA, // Request An RGBA Format 32, // Select Our Color Depth 0, 0, 0, 0, 0, 0, // Color Bits Ignored 0, // No Alpha Buffer 0, // Shift Bit Ignored 0, // No Accumulation Buffer 0, 0, 0, 0, // Accumulation Bits Ignored 24, // Z-Buffer (Depth Buffer) 0, // No Stencil Buffer 0, // No Auxiliary Buffer PFD_MAIN_PLANE, // Main Drawing Layer 0, // Reserved 0, 0, 0 // Layer Masks Ignored }; *(HWND*)this->windowHandle_HWND = *(HWND*)windowHandle; *(HDC*)this->deviceContext_HDC = GetDC(*(HWND*)this->windowHandle_HWND); if (*(HDC*)this->deviceContext_HDC == 0) return false; this->pixelFormatIndex = ChoosePixelFormat(*(HDC*)this->deviceContext_HDC, &pixelFormatDescriptor); if (this->pixelFormatIndex == 0) return false; if(!SetPixelFormat(*((HDC*)this->deviceContext_HDC), this->pixelFormatIndex, &pixelFormatDescriptor)) return false; *(HGLRC*)this->renderContext_HGLRC = wglCreateContext(*(HDC*)this->deviceContext_HDC); if (*(HGLRC*)this->renderContext_HGLRC == 0) return false; if (!wglMakeCurrent(*(HDC*)this->deviceContext_HDC, *(HGLRC*)this->renderContext_HGLRC) != 0) return false; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_CULL_FACE); glFrontFace(GL_CW); //glFrontFace(GL_CCW); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); //glDisable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); //glEnable(GL_LIGHT0); //glDisable(GL_LIGHTING); //glLightfv(GL_LIGHT0, GL_AMBIENT, this.floatGL); //glLightfv(GL_LIGHT0, GL_DIFFUSE, this.floatGL); //glLightfv(GL_LIGHT0, GL_SPECULAR, this.floatGL); glDisable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); this->pixelFormat = MwPixelFormat(4, 4, 8, 8, 8, 8, MwPixelFormat::ChannelIdRed, MwPixelFormat::ChannelIdGreen, MwPixelFormat::ChannelIdBlue, MwPixelFormat::ChannelIdAlpha); return true; }
int main () { assert (restart_gl_log ()); assert (start_gl ()); // tell GL to only draw onto a pixel if the shape is closer to the viewer glEnable (GL_DEPTH_TEST); // enable depth-testing glDepthFunc (GL_LESS); // depth-testing interprets a smaller value as "closer" glClearColor (0.2, 0.2, 0.2, 1.0); GLfloat points[] = { 0.0f, 0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, -0.5f, 0.0f }; GLfloat colours[] = { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f }; GLuint points_vbo; glGenBuffers (1, &points_vbo); glBindBuffer (GL_ARRAY_BUFFER, points_vbo); glBufferData (GL_ARRAY_BUFFER, 9 * sizeof (GLfloat), points, GL_STATIC_DRAW); GLuint colours_vbo; glGenBuffers (1, &colours_vbo); glBindBuffer (GL_ARRAY_BUFFER, colours_vbo); glBufferData (GL_ARRAY_BUFFER, 9 * sizeof (GLfloat), colours, GL_STATIC_DRAW); GLuint vao; glGenVertexArrays (1, &vao); glBindVertexArray (vao); glBindBuffer (GL_ARRAY_BUFFER, points_vbo); glVertexAttribPointer (0, 3, GL_FLOAT, GL_FALSE, 0, NULL); glBindBuffer (GL_ARRAY_BUFFER, colours_vbo); glVertexAttribPointer (1, 3, GL_FLOAT, GL_FALSE, 0, NULL); glEnableVertexAttribArray (0); glEnableVertexAttribArray (1); char vertex_shader[1024 * 256]; char geometry_shader[1024 * 256]; char fragment_shader[1024 * 256]; assert (parse_file_into_str ("test_vs.glsl", vertex_shader, 1024 * 256)); assert (parse_file_into_str ("test_gs.glsl", geometry_shader, 1024 * 256)); assert (parse_file_into_str ("test_fs.glsl", fragment_shader, 1024 * 256)); GLuint vs = glCreateShader (GL_VERTEX_SHADER); const GLchar* p = (const GLchar*)vertex_shader; glShaderSource (vs, 1, &p, NULL); glCompileShader (vs); // check for compile errors int params = -1; glGetShaderiv (vs, GL_COMPILE_STATUS, ¶ms); if (GL_TRUE != params) { fprintf (stderr, "ERROR: GL shader index %i did not compile\n", vs); print_shader_info_log (vs); return 1; // or exit or something } // create geometry shader GLuint gs = glCreateShader (GL_GEOMETRY_SHADER); p = (const GLchar*)geometry_shader; glShaderSource (gs, 1, &p, NULL); glCompileShader (gs); // check for compile errors glGetShaderiv (gs, GL_COMPILE_STATUS, ¶ms); if (GL_TRUE != params) { fprintf (stderr, "ERROR: GL shader index %i did not compile\n", gs); print_shader_info_log (gs); return 1; // or exit or something } GLuint fs = glCreateShader (GL_FRAGMENT_SHADER); p = (const GLchar*)fragment_shader; glShaderSource (fs, 1, &p, NULL); glCompileShader (fs); // check for compile errors glGetShaderiv (fs, GL_COMPILE_STATUS, ¶ms); if (GL_TRUE != params) { fprintf (stderr, "ERROR: GL shader index %i did not compile\n", fs); print_shader_info_log (fs); return 1; // or exit or something } GLuint shader_programme = glCreateProgram (); glAttachShader (shader_programme, fs); // attach geometry shader too glAttachShader (shader_programme, gs); glAttachShader (shader_programme, vs); glLinkProgram (shader_programme); glGetProgramiv (shader_programme, GL_LINK_STATUS, ¶ms); if (GL_TRUE != params) { fprintf ( stderr, "ERROR: could not link shader programme GL index %i\n", shader_programme ); print_programme_info_log (shader_programme); return false; } assert (is_programme_valid (shader_programme)); glEnable (GL_CULL_FACE); // cull face glCullFace (GL_BACK); // cull back face glFrontFace (GL_CW); // GL_CCW for counter clock-wise while (!glfwWindowShouldClose (g_window)) { _update_fps_counter (g_window); // wipe the drawing surface clear glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport (0, 0, g_gl_width, g_gl_height); glUseProgram (shader_programme); glBindVertexArray (vao); // points drawing mode glDrawArrays (GL_POINTS, 0, 3); // update other events like input handling glfwPollEvents (); if (GLFW_PRESS == glfwGetKey (g_window, GLFW_KEY_ESCAPE)) { glfwSetWindowShouldClose (g_window, 1); } // put the stuff we've been drawing onto the display glfwSwapBuffers (g_window); } // close GL context and any other GLFW resources glfwTerminate(); return 0; }
// Initialization code void init() { // Initializes the glew library glewInit(); // Enables the depth test, which you will want in most cases. You can disable this in the render loop if you need to. glEnable(GL_DEPTH_TEST); // Create an std::vector and put our vertices into it. These are just hardcoded values here defined once. std::vector<VertexFormat> vertices;//our vertex positions vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.25), glm::vec4(1.0, 0.0, 0.0, 1.0), glm::vec3(0.0, 0.0, 1.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.25), glm::vec4(1.0, 0.0, 0.0, 1.0), glm::vec3(0.0, 0.0, 1.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.25), // 3 glm::vec4(1.0, 0.0, 0.0, 1.0), glm::vec3(0.0, 0.0, 1.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.25), glm::vec4(1.0, 0.0, 0.0, 1.0), glm::vec3(0.0, 0.0, 1.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.25), glm::vec4(1.0, 0.0, 0.0, 1.0), glm::vec3(0.0, 0.0, 1.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.25), // 6 end front face | NORMAL: (0.0, 0.0, 1.0) glm::vec4(1.0, 0.0, 0.0, 1.0), glm::vec3(0.0, 0.0, 1.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.25), glm::vec4(1.0, 1.0, 0.0, 1.0), glm::vec3(1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.25), glm::vec4(1.0, 1.0, 0.0, 1.0), glm::vec3(1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.75), // 9 glm::vec4(1.0, 1.0, 0.0, 1.0), glm::vec3(1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.25), glm::vec4(1.0, 1.0, 0.0, 1.0), glm::vec3(1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.75), glm::vec4(1.0, 1.0, 0.0, 1.0), glm::vec3(1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.75), // 12 end right face | NORMAL: (1.0, 0.0, 0.0) glm::vec4(1.0, 1.0, 0.0, 1.0), glm::vec3(1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.75), glm::vec4(1.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 0.0, -1.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.75), glm::vec4(1.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 0.0, -1.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.75), // 15 glm::vec4(1.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 0.0, -1.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.75), glm::vec4(1.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 0.0, -1.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.75), glm::vec4(1.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 0.0, -1.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.75), // 18 end back face | NORMAL: (0.0, 0.0, -1.0) glm::vec4(1.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 0.0, -1.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.75), glm::vec4(0.0, 1.0, 0.0, 1.0), glm::vec3(-1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.75), glm::vec4(0.0, 1.0, 0.0, 1.0), glm::vec3(-1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.25), // 21 glm::vec4(0.0, 1.0, 0.0, 1.0), glm::vec3(-1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.75), glm::vec4(0.0, 1.0, 0.0, 1.0), glm::vec3(-1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.25), glm::vec4(0.0, 1.0, 0.0, 1.0), glm::vec3(-1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.25), // 24 end left face | NORMAL: (-1.0, 0.0, 0.0) glm::vec4(0.0, 1.0, 0.0, 1.0), glm::vec3(-1.0, 0.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.25), glm::vec4(0.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.75), glm::vec4(0.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.75), // 27 glm::vec4(0.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, 0.25, -0.25), glm::vec4(0.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.75), glm::vec4(0.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, 0.25, -0.25), // 30 end top face | NORMAL: (0.0, 1.0, 0.0) glm::vec4(0.0, 0.0, 1.0, 1.0), glm::vec3(0.0, 1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.25), glm::vec4(0.0, 1.0, 1.0, 1.0), glm::vec3(0.0, -1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.25), glm::vec4(0.0, 1.0, 1.0, 1.0), glm::vec3(0.0, -1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.75), // 33 glm::vec4(0.0, 1.0, 1.0, 1.0), glm::vec3(0.0, -1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.25), glm::vec4(0.0, 1.0, 1.0, 1.0), glm::vec3(0.0, -1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(0.25, -0.25, -0.75), glm::vec4(0.0, 1.0, 1.0, 1.0), glm::vec3(0.0, -1.0, 0.0))); vertices.push_back(VertexFormat(glm::vec3(-0.25, -0.25, -0.75), // 36 end back face | NORMAL: (0.0, -1.0, 0.0) glm::vec4(0.0, 1.0, 1.0, 1.0), glm::vec3(0.0, -1.0, 0.0))); // This generates buffer object names // The first parameter is the number of buffer objects, and the second parameter is a pointer to an array of buffer objects (yes, before this call, vbo was an empty variable) // (In this example, there's only one buffer object.) glGenBuffers(1, &vbo); // Binds a named buffer object to the specified buffer binding point. Give it a target (GL_ARRAY_BUFFER) to determine where to bind the buffer. // There are several different target parameters, GL_ARRAY_BUFFER is for vertex attributes, feel free to Google the others to find out what else there is. // The second paramter is the buffer object reference. If no buffer object with the given name exists, it will create one. // Buffer object names are unsigned integers (like vbo). Zero is a reserved value, and there is no default buffer for each target (targets, like GL_ARRAY_BUFFER). // Passing in zero as the buffer name (second parameter) will result in unbinding any buffer bound to that target, and frees up the memory. glBindBuffer(GL_ARRAY_BUFFER, vbo); // Creates and initializes a buffer object's data. // First parameter is the target, second parameter is the size of the buffer, third parameter is a pointer to the data that will copied into the buffer, and fourth parameter is the // expected usage pattern of the data. Possible usage patterns: GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, // GL_DYNAMIC_READ, or GL_DYNAMIC_COPY // Stream means that the data will be modified once, and used only a few times at most. Static means that the data will be modified once, and used a lot. Dynamic means that the data // will be modified repeatedly, and used a lot. Draw means that the data is modified by the application, and used as a source for GL drawing. Read means the data is modified by // reading data from GL, and used to return that data when queried by the application. Copy means that the data is modified by reading from the GL, and used as a source for drawing. glBufferData(GL_ARRAY_BUFFER, sizeof(VertexFormat) * 36, &vertices[0], GL_STATIC_DRAW); // By default, all client-side capabilities are disabled, including all generic vertex attribute arrays. // When enabled, the values in a generic vertex attribute array will be accessed and used for rendering when calls are made to vertex array commands (like glDrawArrays/glDrawElements) // A GL_INVALID_VALUE will be generated if the index parameter is greater than or equal to GL_MAX_VERTEX_ATTRIBS glEnableVertexAttribArray(0); // Defines an array of generic vertex attribute data. Takes an index, a size specifying the number of components (in this case, floats)(has a max of 4) // The third parameter, type, can be GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_FIXED, or GL_FLOAT // The fourth parameter specifies whether to normalize fixed-point data values, the fifth parameter is the stride which is the offset (in bytes) between generic vertex attributes // The fifth parameter is a pointer to the first component of the first generic vertex attribute in the array. If named buffer object is bound to GL_ARRAY_BUFFER (and it is, in this case) // then the pointer parameter is treated as a byte offset into the buffer object's data. glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(VertexFormat), (void*)16); // You'll note sizeof(VertexFormat) is our stride, because each vertex contains data that adds up to that size. // You'll also notice we offset this parameter by 16 bytes, this is because the vec3 position attribute is after the vec4 color attribute. A vec4 has 4 floats, each being 4 bytes // so we offset by 4*4=16 to make sure that our first attribute is actually the position. The reason we put position after color in the struct has to do with padding. // For more info on padding, Google it. // This is our color attribute, so the offset is 0, and the size is 4 since there are 4 floats for color. glEnableVertexAttribArray(1); glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(VertexFormat), (void*)0); // This is our normal attribute, so the offset is 16(4*4) + 12(4*3) = 28 glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, sizeof(VertexFormat), (void*)28); // Read in the shader code from a file. std::string vertShader = readShader("VertexShader.glsl"); std::string fragShader = readShader("FragmentShader.glsl"); // createShader consolidates all of the shader compilation code vertex_shader = createShader(vertShader, GL_VERTEX_SHADER); fragment_shader = createShader(fragShader, GL_FRAGMENT_SHADER); // A shader is a program that runs on your GPU instead of your CPU. In this sense, OpenGL refers to your groups of shaders as "programs". // Using glCreateProgram creates a shader program and returns a GLuint reference to it. program = glCreateProgram(); glAttachShader(program, vertex_shader); // This attaches our vertex shader to our program. glAttachShader(program, fragment_shader); // This attaches our fragment shader to our program. // This links the program, using the vertex and fragment shaders to create executables to run on the GPU. glLinkProgram(program); // End of shader and program creation // Tell OpenGL to use the shader program you've created. glUseProgram(program); // This gets us a reference to the uniform variable in the vertex shader, which is called "trans". // We're using this variable as a 4x4 transformation matrix // Only 2 parameters required: A reference to the shader program and the name of the uniform variable within the shader code. uniTrans = glGetUniformLocation(program, "trans"); // We'll also need references to the rest of our uniforms too. uniNumLights = glGetUniformLocation(program, "numLights"); // Because there are so many different uniforms for the Light struct, we'll want a function to make this easier. setUniformAttrib(uniLightPosition, "position"); setUniformAttrib(uniLightColor, "diffuseColor"); setUniformAttrib(uniLightConeDir, "coneDirection"); setUniformAttrib(uniLightConeAng, "coneAngle"); setUniformAttrib(uniLightAttenuation, "attenuation"); setUniformAttrib(uniLightAmbient, "ambientCoefficient"); // Set the number of lights in your shader. glUniform1i(uniNumLights, 3); // All the Z values passed into the shader are getting reversed somehow, so we will flip them in the shader code. // Alternatively, you can just remember to flip them beforehand. This example has it flipping them in the shader code, so don't flip them here too or you'll just // end up leaving them in the wrong direction. Light dirLight; dirLight.ambientCoefficient = 0.15f; // Passing in 0 for the W value identifies this as a directional light, thus the only relevant values are the position (direction), color, and ambientCoefficient. dirLight.position = glm::vec4(-0.2f, -0.2f, 1.0f, 0.0f); dirLight.diffuseColor = glm::vec4(0.10f, 0.10f, 0.10f, 1.0f); Light pointLight; pointLight.ambientCoefficient = 0.0f; pointLight.position = glm::vec4(-1.0f, 0.0f, 0.0f, 1.0f); // The Z value appears to be flipped for some reason, we'll have to look into that. pointLight.coneAngle = 360.0f; // Setting a coneAngle of 180 (I set 360 to be extra safe) guarantees that this will not be a spotlight. pointLight.diffuseColor = glm::vec4(0.15f, 0.15f, 0.15f, 1.0f); pointLight.attenuation = 0.25f; pointLight.coneDirection = glm::vec4(1.0f, 1.0f, 1.0f, 1.0f); // Since coneAngle is 180+, this value is irreleavant. Light spotLight; spotLight.ambientCoefficient = 0.0f; spotLight.position = glm::vec4(0.0f, 0.0f, -1.0f, 1.0f); // The Z value appears to be flipped for some reason, we'll have to look into that. spotLight.coneAngle = 7.0f; spotLight.diffuseColor = glm::vec4(0.5f, 0.5f, 0.5f, 1.0f); spotLight.attenuation = 0.25f; spotLight.coneDirection = glm::vec4(0.0f, 0.0f, 1.0f, 1.0f); // A function to help setup a given light. setLight(0, &dirLight); setLight(1, &pointLight); setLight(2, &spotLight); // This is not necessary, but I prefer to handle my vertices in the clockwise order. glFrontFace defines which face of the triangles you're drawing is the front. // Essentially, if you draw your vertices in counter-clockwise order, by default (in OpenGL) the front face will be facing you/the screen. If you draw them clockwise, the front face // will face away from you. By passing in GL_CW to this function, we are saying the opposite, and now the front face will face you if you draw in the clockwise order. // If you don't use this, just reverse the order of the vertices in your array when you define them so that you draw the points in a counter-clockwise order. glFrontFace(GL_CW); // This is also not necessary, but more efficient and is generally good practice. By default, OpenGL will render both sides of a triangle that you draw. By enabling GL_CULL_FACE, // we are telling OpenGL to only render the front face. This means that if you rotated the triangle over the X-axis, you wouldn't see the other side of the triangle as it rotated. glEnable(GL_CULL_FACE); // Determines the interpretation of polygons for rasterization. The first parameter, face, determines which polygons the mode applies to. // The face can be either GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK // The mode determines how the polygons will be rasterized. GL_POINT will draw points at each vertex, GL_LINE will draw lines between the vertices, and // GL_FILL will fill the area inside those lines. glPolygonMode(GL_FRONT, GL_FILL); }
int draw_persp(unsigned int i, float N, float F, int e, const float p[3]) { struct tile *T = get_tile(i); const int L = (T->flags & TILE_LEFT_EYE) ? 1 : 0; const int R = (T->flags & TILE_RIGHT_EYE) ? 1 : 0; if ((L == 0 && R == 0) || (L == 1 && e == 0) || (R == 1 && e == 1)) { float r[3]; float u[3]; float n[3]; float k; float M[16]; float I[16]; float p0[3]; float p1[3]; float p3[3]; /* Compute the screen corners. */ p0[0] = p[0] - T->o[0]; p0[1] = p[1] - T->o[1]; p0[2] = p[2] - T->o[2]; p1[0] = p[0] - T->r[0] - T->o[0]; p1[1] = p[1] - T->r[1] - T->o[1]; p1[2] = p[2] - T->r[2] - T->o[2]; p3[0] = p[0] - T->u[0] - T->o[0]; p3[1] = p[1] - T->u[1] - T->o[1]; p3[2] = p[2] - T->u[2] - T->o[2]; /* Configure the viewport. */ glViewport(T->win_x, T->win_y, T->win_w, T->win_h); glScissor (T->win_x, T->win_y, T->win_w, T->win_h); /* Compute the projection. */ r[0] = T->r[0]; r[1] = T->r[1]; r[2] = T->r[2]; u[0] = T->u[0]; u[1] = T->u[1]; u[2] = T->u[2]; cross(n, r, u); normalize(r); normalize(u); normalize(n); k = n[0] * (T->o[0] - p[0]) + n[1] * (T->o[1] - p[1]) + n[2] * (T->o[2] - p[2]); glMatrixMode(GL_PROJECTION); { double fL = N * (r[0] * p0[0] + r[1] * p0[1] + r[2] * p0[2]) / k; double fR = N * (r[0] * p1[0] + r[1] * p1[1] + r[2] * p1[2]) / k; double fB = N * (u[0] * p0[0] + u[1] * p0[1] + u[2] * p0[2]) / k; double fT = N * (u[0] * p3[0] + u[1] * p3[1] + u[2] * p3[2]) / k; /* Flip the projection if requested. */ if (T->flags & TILE_FLIP_X) swap(fL, fR); if (T->flags & TILE_FLIP_Y) swap(fB, fT); /* Apply the projection. */ glLoadIdentity(); glFrustum(fL, fR, fB, fT, N, F); /* Account for the orientation of the display. */ M[0] = r[0]; M[4] = u[0]; M[8] = n[0]; M[12] = 0.0f; M[1] = r[1]; M[5] = u[1]; M[9] = n[1]; M[13] = 0.0f; M[2] = r[2]; M[6] = u[2]; M[10] = n[2]; M[14] = 0.0f; M[3] = 0.0f; M[7] = 0.0f; M[11] = 0.0f; M[15] = 1.0f; load_inv(I, M); glMultMatrixf(I); /* Move the apex of the frustum to the origin. */ glTranslatef(-p[0], -p[1], -p[2]); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Rewind polygons if necessary. */ if (((T->flags & TILE_FLIP_X) ? 1 : 0) ^ ((T->flags & TILE_FLIP_Y) ? 1 : 0)) glFrontFace(GL_CW); else glFrontFace(GL_CCW); return 1; } return 0; }
/******************************************************************************* * Function Name : InitView * Inputs : * Returns : true if no error occured * Description : Code in InitView() will be called by the Shell upon a change * in the rendering context. * Used to initialize variables that are dependant on the rendering * context (e.g. textures, vertex buffers, etc.) *******************************************************************************/ bool OGLESOptimizeMesh::InitView() { SPVRTContext sContext; bool bRotate = PVRShellGet(prefIsRotated) && PVRShellGet(prefFullScreen); // Init Print3D to display text on screen if(m_Print3D.SetTextures(&sContext, PVRShellGet(prefWidth), PVRShellGet(prefHeight), bRotate) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Cannot initialise Print3D.\n"); return false; } /****************************** ** Create Textures ** *******************************/ if(PVRTTextureLoadFromPVR(c_szModelTexFile, &m_Texture) != PVR_SUCCESS) { PVRShellSet(prefExitMessage, "ERROR: Failed to load texture for model.\n"); return false; } /********************************* ** View and Projection Matrices ** *********************************/ // Get Camera info from POD file PVRTVec3 From, To; VERTTYPE fFOV; if(m_Model.nNumCamera) { // Get Camera data from POD Geometry File fFOV = m_Model.GetCameraPos(From, To, 0); fFOV = VERTTYPEMUL(fFOV, f2vt(0.75f)); // Convert from horizontal FOV to vertical FOV (0.75 assumes a 4:3 aspect ratio) } else { fFOV = f2vt(PVRT_PIf / 6); } // View m_mView = PVRTMat4::LookAtRH(From, To, PVRTVec3(f2vt(0.0f), f2vt(1.0f), f2vt(0.0f))); // Projection m_mProj = PVRTMat4::PerspectiveFovRH(fFOV, f2vt((float) PVRShellGet(prefWidth) / (float) PVRShellGet(prefHeight)), g_fCameraNear, g_fCameraFar, PVRTMat4::OGL, bRotate); glMatrixMode(GL_PROJECTION); myglLoadMatrix(m_mProj.f); /****************************** ** GENERIC RENDER STATES ** ******************************/ // The Type Of Depth Test To Do glDepthFunc(GL_LEQUAL); // Enables Depth Testing glEnable(GL_DEPTH_TEST); // Enables Smooth Color Shading glShadeModel(GL_SMOOTH); // Define front faces glFrontFace(GL_CW); // Sets the clear colour myglClearColor(f2vt(0.6f), f2vt(0.8f), f2vt(1.0f), f2vt(1.0f)); // Reset the model view matrix to position the light glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // Setup timing variables m_ui32LastTime = PVRShellGetTime(); m_ui32FPSFrameCnt = 0; m_fFPS = 0; m_fViewAngle = 0; m_ui32SwitchTimeDiff = 0; #ifndef ENABLE_LOAD_TIME_STRIP LoadVbos(); #endif return true; }