不能创建opengl窗口_使用OpenGL创建窗口 C ++

不能创建opengl窗口Basic step to make any program on OpenGL is created a window where all the code will work so how it we can create it? After installing OpenGL libraries on your machine (OpenGL installation...
摘要由CSDN通过智能技术生成

不能创建opengl窗口

Basic step to make any program on OpenGL is created a window where all the code will work so how it we can create it? After installing OpenGL libraries on your machine (OpenGL installation guide for Ubuntu: How to install OpenGL in Ubuntu) we can begin.

在OpenGL上制作任何程序的基本步骤是创建一个窗口,所有代码都将在其中工作,因此我们如何创建它? 在您的机器上安装OpenGL库之后(Ubuntu的OpenGL安装指南: 如何在Ubuntu中安装OpenGL ),我们可以开始了。

Let’s first understand how to structure an OpenGL program?

首先让我们了解如何构建OpenGL程序吗?

  1. Place all initialization and related one-time parameter setting together preferably in functioninit().

    最好将所有初始化和相关的一次性参数设置放到functioninit()中 。

  2. Geometric description of the picture that we want to draw (display) in user-defined function which will be referenced in GLUT function, glutDisplayFunc().

    我们要在用户定义函数中绘制(显示)的图片的几何描述,这将在GLUT函数glutDisplayFunc()中引用。

  3. main function will contain GLUT function for setting up the display window and getting the image screen.

    主要功能将包含GLUT功能,用于设置显示窗口和获取图像屏幕。

Program:

程序:

Let’s get our ha

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
作为一个AI,我无法直接操作OpenGL,但我可以提供一些基本的代码帮助你创建两个窗口。以下是一个用glad创建两个窗口的示例: ```c++ #include <glad/glad.h> #include <GLFW/glfw3.h> #include <iostream> void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow* window); const unsigned int SCR_WIDTH = 800; const unsigned int SCR_HEIGHT = 600; int main() { // 初始化GLFW glfwInit(); // 配置GLFW glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 创建第一个窗口 GLFWwindow* window1 = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Window 1", NULL, NULL); if (window1 == NULL) { std::cout << "Failed to create GLFW window1" << std::endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window1); // 初始化GLAD if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } // 设置视口大小 glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT); // 注册窗口大小改变的回调函数 glfwSetFramebufferSizeCallback(window1, framebuffer_size_callback); // 创建第二个窗口 GLFWwindow* window2 = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Window 2", NULL, window1); if (window2 == NULL) { std::cout << "Failed to create GLFW window2" << std::endl; glfwTerminate(); return -1; } glfwMakeContextCurrent(window2); // 初始化GLAD if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { std::cout << "Failed to initialize GLAD" << std::endl; return -1; } // 设置视口大小 glViewport(0, 0, SCR_WIDTH, SCR_HEIGHT); // 注册窗口大小改变的回调函数 glfwSetFramebufferSizeCallback(window2, framebuffer_size_callback); // 循环渲染 while (!glfwWindowShouldClose(window1) && !glfwWindowShouldClose(window2)) { // 处理输入 processInput(window1); processInput(window2); // 清除颜色缓冲区 glClear(GL_COLOR_BUFFER_BIT); // 交换缓冲区 glfwSwapBuffers(window1); glfwSwapBuffers(window2); // 检查并调用事件 glfwPollEvents(); } // 清理所有资源 glfwTerminate(); return 0; } void framebuffer_size_callback(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); } void processInput(GLFWwindow* window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); } ``` 这个示例中创建了两个窗口,第一个窗口为主窗口,第二个窗口作为第一个窗口的子窗口。两个窗口的渲染和输入处理是分开的,但它们共享OpenGL上下文。在这个示例中,同时按下Esc键会关闭两个窗口

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值