简体   繁体   English

在OpenGL中打开一个窗口:不会出现空白屏幕(改为无限复制)

[英]Opening a Window in OpenGL: Will not make Blank Screen (Makes infinite copies instead)

So I asked my professor to look at this already and he doesn't know why it doesn't work. 所以我请我的教授仔细研究一下,他不知道为什么它不起作用。 I am currently working from my laptop, which is having the issue. 我目前正在使用笔记本电脑工作,出现了问题。 I also tried running my program on a lab computer and it fully worked as intended. 我还尝试在实验室计算机上运行我的程序,该程序完全可以按预期运行。 I recently updated all of my graphics stuff. 我最近更新了我所有的图形内容。 Here is my code below: 这是我的代码如下:

#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
#include <FreeImage.h>

int main()
{
    if (glfwInit() == GL_FALSE)
        return -1;

    GLFWwindow* GLFWwindowPtr = glfwCreateWindow(800, 600, "Name Name DSA1 Engine", NULL, NULL);

    if (GLFWwindowPtr != nullptr)
        glfwMakeContextCurrent(GLFWwindowPtr);
    else
    {
        glfwTerminate();
        return -1;
    }

    if (glewInit() != GLEW_OK)
    {
        glfwTerminate();
        return -1;
    }

    while (!glfwWindowShouldClose(GLFWwindowPtr))
    {
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

All I am trying to do is make a blank window appear on my screen with openGL. 我要做的就是用openGL在屏幕上显示一个空白窗口。 It all runs fine and dandy, but when a window is drawn to my screen it copies whatever was behind it instead of being a blank white screen. 一切运行正常,但当在我的屏幕上绘制一个窗口时,它会复制它后面的内容,而不是白屏。 The most perplexing bit about this is that my professor has the same code on his laptop and it works fine, and it works for me when I run it on a lab machine. 最令人困惑的是,我的教授在他的笔记本电脑上使用了相同的代码,并且工作正常,并且在实验室机器上运行时对我也有效。

I initially thought it was something in my graphics drivers and such so I updated those but it still doesn't work. 最初,我认为这是图形驱动程序中的某些功能,因此我对其进行了更新,但仍然无法正常工作。 I have provided some of my system specs just in case that might help. 我提供了一些系统规格,以防万一。

Manufacturer MSI_NB 制造商MSI_NB

Model GT70 2OC/2OD 型号GT70 2OC / 2OD

Total amount of system memory 32.0 GB RAM 系统内存总量32.0 GB RAM

System type 64-bit operating system 系统类型64位操作系统

Number of processor cores 4 处理器核心数4

Display adapter type NVIDIA GeForce GTX 770M 显示适配器类型NVIDIA GeForce GTX 770M

Total available graphics memory 1824 MB 可用的总图形内存1824 MB

Dedicated graphics memory 192 MB 专用图形内存192 MB

Dedicated system memory 0 MB 专用系统内存0 MB

Shared system memory 1632 MB 共享系统内存1632 MB

Display adapter driver version 10.18.13.6200 显示适配器驱动程序版本10.18.13.6200

Primary monitor resolution 1920x1080 主显示器分辨率1920x1080

DirectX version DirectX 10 DirectX版本DirectX 10

I know this isn't really a code related question, but I would really appreciate anyone who can help me with this issue. 我知道这并不是一个与代码相关的问题,但是如果有人可以为我提供帮助,我将不胜感激。 If I need to provide any additional information I am more than happy to provide it! 如果我需要提供任何其他信息,我非常乐意提供!

The issue is that you never clear the screen or call glfwSwapBuffers . 问题是您永远不会清除屏幕或调用glfwSwapBuffers

When the window first appears, its client area is invalidated which means it needs to be redrawn. 第一次出现该窗口时,其客户区无效,这意味着需要重绘该窗口。 GLFW doesn't clear the screen automatically because it would just be overwritten with your graphics scene (so the extra clear would be redundant). GLFW不会自动清除屏幕,因为它只会被您的图形场景覆盖(因此额外的清除将是多余的)。 But since you don't draw anything, you're left with the equivalent of uninitialized data. 但是,由于您什么都没画,所以剩下的就是未初始化的数据。 Whether or not you get a blank screen or copies of windows behind it is configuration-dependent. 是否显示黑屏或背后的窗口副本取决于配置。

To fix this, you need to register a window refresh callback via glfwSetWindowRefreshCallback that does your rendering (in this case, just call glClear(GL_COLOR_BUFFER); ) and calls glfwSwapBuffers . 要解决此问题,您需要通过glfwSetWindowRefreshCallback 注册一个进行刷新的窗口刷新回调 (在这种情况下,只需调用glClear(GL_COLOR_BUFFER); )并调用glfwSwapBuffers

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM