zoukankan      html  css  js  c++  java
  • opengl 学习tutorial01

    简介

    学习opengl。

    opengl 学习 之 first lesson

    link

    http://www.opengl-tutorial.org/uncategorized/2017/06/07/website-update/

    相关库的作用

    GLFW: handle the window and the keyboard

    GLM: We don’t actually need this one right now, but this is a library for 3D mathematics

    核心接口函数

    window = glfwCreateWindow( 1024, 768, "Tutorial 01", NULL, NULL);
    创建窗口

    code

    // Include standard headers
    #include <stdio.h>
    #include <stdlib.h>
    
    // Include GLEW
    #include <GL/glew.h>
    
    // Include GLFW
    #include <GLFW/glfw3.h>
    GLFWwindow* window;
    
    // Include GLM
    #include <glm/glm.hpp>
    using namespace glm;
    
    int main( void )
    {
    	// Initialise GLFW
    	if( !glfwInit() )
    	{
    		fprintf( stderr, "Failed to initialize GLFW
    " );
    		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 needed
    	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    
    	// Open a window and create its OpenGL context
    	window = 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.
    " );
    		getchar();
    		glfwTerminate();
    		return -1;
    	}
    	glfwMakeContextCurrent(window);
    
    	// Initialize GLEW
    	if (glewInit() != GLEW_OK) {
    		fprintf(stderr, "Failed to initialize GLEW
    ");
    		getchar();
    		glfwTerminate();
    		return -1;
    	}
    
    	// Ensure we can capture the escape key being pressed below
    	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
    
    	// Dark blue background
    	glClearColor(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 buffers
    		glfwSwapBuffers(window);
    		glfwPollEvents();
    
    	} // Check if the ESC key was pressed or the window was closed
    	while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
    		   glfwWindowShouldClose(window) == 0 );
    
    	// Close OpenGL window and terminate GLFW
    	glfwTerminate();
    
    	return 0;
    
    }
    
    
    

    image

    显示一个窗口

    Hope is a good thing,maybe the best of things,and no good thing ever dies.----------- Andy Dufresne
  • 相关阅读:
    android开发过程遇到的一些错误
    TCP/IP协议详解笔记——ARP协议和RARP协议
    TCP/IP协议详解笔记——IP协议
    C# Exchange发送邮件
    Echarts柱状图堆叠显示总数
    Git解决fatal: unable to connect to github.com问题
    IIS 413错误 解决方案
    C#启动外部Exe控制台程序并输入命令
    再看JavaScript
    Web Api(5)
  • 原文地址:https://www.cnblogs.com/eat-too-much/p/14061702.html
Copyright © 2011-2022 走看看