Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/137.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ GLFW非响应全屏窗口_C++_Opengl_Graphics_Glfw - Fatal编程技术网

C++ GLFW非响应全屏窗口

C++ GLFW非响应全屏窗口,c++,opengl,graphics,glfw,C++,Opengl,Graphics,Glfw,我对GLFW的窗口创建有一些问题。我想有一个程序之间切换窗口和全屏模式的能力。要在GLFW 2.7.8中执行此操作,必须首先销毁活动窗口,然后创建一个新窗口。我听说3.0版支持多个窗口,但它仍在开发中 我提供了自己的功能来处理键盘输入。使用初始400 x 400窗口,程序按预期运行;它将在f或f上进入全屏,在按下退出键时退出,并在按下任何其他键时发出投诉 但是,当进入全屏模式时,窗口对我提供的键盘功能没有响应。它将继续在main()中的循环中运行,并将响应类似于glfwGetKey(GLFW\u

我对GLFW的窗口创建有一些问题。我想有一个程序之间切换窗口和全屏模式的能力。要在GLFW 2.7.8中执行此操作,必须首先销毁活动窗口,然后创建一个新窗口。我听说3.0版支持多个窗口,但它仍在开发中

我提供了自己的功能来处理键盘输入。使用初始400 x 400窗口,程序按预期运行;它将在f或f上进入全屏,在按下退出键时退出,并在按下任何其他键时发出投诉

但是,当进入全屏模式时,窗口对我提供的键盘功能没有响应。它将继续在main()中的循环中运行,并将响应类似于
glfwGetKey(GLFW\u KEY\u ESC)
测试的内容。无论是否启用鼠标光标,光标都不会出现

再次创建全屏窗口,
KeyboardCallback
函数返回主循环。我想了解为什么全屏窗口不能使用我的键盘功能,为什么不能正确显示

我并没有在窗口上绘制任何东西,因为我正试图获得一些使用各种窗口抽象库的经验。画一个简单的三角形并没有解决问题,全屏窗口仍然是黑色的

我的代码如下:

#include <stdio.h>
#include <stdlib.h>

// glfw32 - 2.7.8
#include <GL\glfw.h>

#pragma comment (lib, "GLFW.lib")
#pragma comment (lib, "opengl32.lib")

using namespace std;

// constants and globals
const int WINDOW_WIDTH=400, WINDOW_HEIGHT=400;
static bool fullscreen=false;

// function declarations
void GLFWCALL KeyboardCallback(int key, int action);
void FatalError(const char* msg) {
  fprintf(stderr, "ERROR: Failure in \"%s\"\n", msg);
  exit(1);
}


int main() {
  // ititialize GLFW
  glfwInit();
  glfwEnable(GLFW_MOUSE_CURSOR);
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
  glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);

  // initial window, 400x400 with 32-bit depth buffer in windowed mode
  glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 0,0,0,0, 32, 0, GLFW_WINDOW);
  glfwSetWindowTitle("Simple Title");
  glfwSetWindowPos(0, 0);

  // set custom keyboard callback
  glfwSetKeyCallback(KeyboardCallback);

  while (true) {  // loop until exit
    glClear(GL_COLOR_BUFFER_BIT);
    glfwSwapBuffers();  

    // debug
    //printf("Looping...\n");
    if ( glfwGetKey(GLFW_KEY_ESC) ) {break;} 
  }

  glfwTerminate();
  printf("\nHave a nice day\n");
  return 0;
}


void GLFWCALL KeyboardCallback(int key, int action) {
  //printf("In keyboard function\n");

  if (action) {    // if key DOWN,
    switch(key) {  // do something...
      case 'f':
      case 'F':  {
        fullscreen = !fullscreen;
        printf("Toggle Fullscreen: %s\n", (fullscreen ? "On" : "Off"));
        glfwCloseWindow();

        if (! glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 0,0,0,0, 32, 0,
                             fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW)) {
          FatalError("toggle fullscreen");
        }
        glfwSetWindowTitle("New Title");
        break;
      }

      case GLFW_KEY_ESC:  {
        printf("\nGoodbye cruel world...\n");
        glfwTerminate();
        exit(0);
      }

      default:  {
        printf("Key not implemented: %c\n", key);
        break;
      }
    }
  }
  printf("Exiting keyboard function\n");
}
#包括
#包括
//glfw32-2.7.8
#包括
#pragma注释(lib,“GLFW.lib”)
#pragma注释(lib,“opengl32.lib”)
使用名称空间std;
//常数和全局
常数int窗宽=400,窗高=400;
静态布尔全屏=假;
//函数声明
void GLFWCALL键盘回调(int键,int操作);
无效FatalError(常量字符*消息){
fprintf(stderr,“错误:在\%s\“\n”中失败”,msg);
出口(1);
}
int main(){
//使GLFW透明化
glfwInit();
glfwEnable(GLFW_鼠标_光标);
glfwOpenWindowHint(GLFW_OPENGL_版本_专业版,3);
glfwOpenWindowHint(GLFW_OPENGL_版本_小调,3);
//初始窗口,400x400,带窗口模式下的32位深度缓冲区
glfwOpenWindow(窗宽、窗高、0,0,0,32,0、GLFW\u窗);
glfwSetWindowTitle(“简单标题”);
glfwSetWindowPos(0,0);
//设置自定义键盘回调
glfwSetKeyCallback(键盘回调);
while(true){//循环直到退出
glClear(GLU颜色缓冲位);
glfwSwapBuffers();
//调试
//printf(“循环…\n”);
if(glfwGetKey(GLFW_KEY_ESC)){break;}
}
glfwTerminate();
printf(“\n祝您愉快\n”);
返回0;
}
void GLFWCALL键盘回调(int键,int操作){
//printf(“键盘内功能\n”);
如果(操作){//如果按下键,
开关(键){//做点什么。。。
案例“f”:
案例“F”:{
全屏=!全屏;
printf(“切换全屏:%s\n”,(全屏?“打开”:“关闭”);
glfwCloseWindow();
如果(!glfwOpenWindow)(窗宽、窗高、0,0,0,32,0,
全屏?GLFW_全屏:GLFW_窗口){
FatalError(“切换全屏”);
}
glfwSetWindowTitle(“新标题”);
打破
}
案例GLFW\U键\U ESC:{
printf(“\nGoodbye残酷世界…\n”);
glfwTerminate();
出口(0);
}
默认值:{
printf(“未实现的密钥:%c\n”,密钥);
打破
}
}
}
printf(“退出键盘功能”);
}
我尝试了詹姆斯的方法,但没有效果。有我忘记设置的GLFW标志吗

编辑------5/20

我有一个想法。当窗口被破坏时,可能我的回调被取消注册。事实证明,在创建新窗口时重新注册我的函数会使窗口响应

虽然这解决了我原来的问题,但我现在面临一个新问题。我无法正确渲染到新窗口。我可以插入
glClear(GL\u颜色\u缓冲\u位)进入我的主循环,它将成功地为新窗口设置背景色。由于某些原因,它不会与我的数组和缓冲区交互以绘制图像。

编辑----5/21

我将代码转换为GLFW3.0.0。窗口管理更干净(尽管更复杂),我没有渲染问题。可能是因为我必须明确说明要使用的当前上下文


我仍然想解决渲染问题,出于好奇,如果/当我返回到2.7时,我想解决渲染问题。

现在GLFW的事件队列没有被抽取。您必须设置
GLFW_AUTO_POLL_EVENTS
选项,以便glfwSwapBuffers泵送事件队列,或者在主事件循环迭代开始时调用glfwPollEvents。

在再次调用glfwOpenWindow(..)之前是否尝试重置GLFW窗口提示?是。我将提示中断到
WindowPrep
函数中,并尝试在旧窗口被破坏和新窗口创建之间调用它。它对图像的渲染没有影响。您不应该从GLFW回调关闭GLFW窗口。我尝试了这两个选项。对
GLFW\u AUTO\u POLL\u事件使用
glfweenable()
标志没有任何作用。在循环开始时使用
glfwPollEvents()
会导致错误渲染的三角形(屏幕的1/8楔块),同时仍然对键盘回调函数没有响应。默认情况下,GLFW 2中的自动轮询处于启用状态。