@markheng
2016-03-12T04:42:31.000000Z
字数 1784
阅读 3655
计算机图形学 OpenGL-Tutorial OpenGL教程
http://www.opengl-tutorial.org/ OpenGL-tutorial
有中文版的但是中文版的代码部分有些注释有遗漏
头文件
#include <stdio.h>#include <stdlib.h>// Include GLEW#include <GL/glew.h>// Include GLFW#include <glfw3.h>GLFWwindow* window;// Include GLM#include <glm/glm.hpp>//matrix calculate header#include <glm/gtc/matrix_transform.hpp>using namespace glm;//loading GLSL files#include <common/shader.hpp>
main函数
int main( void ){// Initialise GLFWif( !glfwInit() ){fprintf( stderr, "Failed to initialize GLFW\n" );getchar();return -1;}glfwWindowHint(GLFW_SAMPLES, 4);glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be neededglfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);// Open a window and create its OpenGL contextwindow = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);if( window == NULL ){fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );getchar();glfwTerminate();return -1;}glfwMakeContextCurrent(window);// Initialize GLEWif (glewInit() != GLEW_OK) {fprintf(stderr, "Failed to initialize GLEW\n");getchar();glfwTerminate();return -1;}// Ensure we can capture the escape key being pressed belowglfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);// Dark blue backgroundglClearColor(0.0f, 0.0f, 0.4f, 0.0f);do{// Clear the screen. It's not mentioned before Tutorial 02, but it can cause flickering, so it's there nonetheless.glClear( GL_COLOR_BUFFER_BIT );// Draw nothing, see you in tutorial 2 !// Swap buffersglfwSwapBuffers(window);glfwPollEvents();} // Check if the ESC key was pressed or the window was closedwhile( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&glfwWindowShouldClose(window) == 0 );// Close OpenGL window and terminate GLFWglfwTerminate();return 0;}