sjcnh

 学习网站 learnopengl (英文网站自带中文翻译)

另有中文翻译网站 http://bullteacher.com/3-createawindow.html

=======================================================

配置glfw文件(干吗用的?提供把物品渲染到屏幕上的必要功能)(Glew配置看前面文章)

1.下载GLFW
把解压得到的include文件下的文件粘贴到vc2015文件夹VC\INCLUDE文件夹下。

解压得到的lib-vc2015文件夹下的lib文件粘贴到VS\lib文件夹下

将lib-vc2015文件夹下的dll文件粘贴到C:\windows\sysWow64下

 

写程序时,在工程的属性->链接器->输入->附加依赖项中添加glfw3.lib

或者在代码中加入:#pragma comment(lib , "glfw3.lib")

 

测试代码

#include <GL/glew.h>
#include <GL/glut.h>
#include <GLFW/glfw3.h>
#pragma comment (lib,"glew32.lib")
#pragma comment (lib,"glfw3.lib")


int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(480, 320, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window\'s context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Draw a triangle */
        glBegin(GL_TRIANGLES);

        glColor3f(1.0, 0.0, 0.0);    // Red
        glVertex3f(0.0, 1.0, 0.0);

        glColor3f(0.0, 1.0, 0.0);    // Green
        glVertex3f(-1.0, -1.0, 0.0);

        glColor3f(0.0, 0.0, 1.0);    // Blue
        glVertex3f(1.0, -1.0, 0.0);

        glEnd();

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

出现界面:

自此,头部预设:

#include <GL/glew.h>
#include <GL/glut.h>
#include <GLFW/glfw3.h>
#pragma comment (lib,"glew32.lib")
#pragma comment (lib,"glfw3.lib")

 

分类:

技术点:

相关文章:

  • 2021-10-03
  • 2021-03-31
  • 2021-12-07
  • 2021-07-30
  • 2021-08-24
  • 2022-12-23
  • 2021-11-19
  • 2021-12-03
猜你喜欢
  • 2022-01-06
  • 2021-08-31
  • 2022-01-22
  • 2021-10-07
  • 2021-12-31
  • 2021-06-27
  • 2021-09-11
相关资源
相似解决方案