opengl - glDrawPixels 不与 glfw 一起使用

标签 opengl glfw

我一直在尝试使用glDrawPixels直接绘制一些像素,但无法弄清楚出了什么问题。我看到了一些使用 glut 的代码示例,它正在工作。但使用 glfw 代替我无法使其工作。这是我正在使用的代码。任何帮助将不胜感激!

  float * computePixels(int iWidth, int iHeight) {
  float *pixels = new float[iWidth * iHeight * 4];
  int k = 0;
  for(int j = iHeight - 1; j >= 0 ; --j)
  {
    for(int i = 0; i < iWidth; ++i)
    {
      pixels[k++] = static_cast<float>(i) / static_cast<float>(iWidth);
      pixels[k++] = static_cast<float>(j) / static_cast<float>(iHeight);
      pixels[k++] = 0.5f;
      pixels[k++] = 0.5f;
    }
  }
  return pixels;
}

int main () {
  // Initialize GLFW (error check removed on purpose for this post!)
  glfwInit();

  // configure GLFW
  glfwWindowHint(GLFW_SAMPLES, 4); // 4x anti-aliasing
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // OpenGL 3.3
  glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); // OpenGL 3.3
  glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // for macos?
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // new OpenGL

  int width = 1024;
  int height = 768;

  GLFWwindow *window = glfwCreateWindow(width, height, "Tutorial 01", nullptr, nullptr);

  glfwMakeContextCurrent(window);

  // initialize GLEW
  glewExperimental = GL_TRUE;
  glewInit();

  float *pixels = computePixels(width, height);

  glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

  glClearColor(0.0f, 1.0f, 0.4f, 0.0f);

  do
  {
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //glWindowPos2i(0, 0);

    glDrawPixels(width, height, GL_RGBA, GL_FLOAT, pixels);

    glfwSwapBuffers(window);
    glfwPollEvents();
  }
  while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0);


  // Terminate GLFW
  glfwTerminate();

  return 0;
}

最佳答案

glDrawPixels 已从版本 3.2 的核心配置文件中删除。因此,如果您使用核心配置文件创建 OpenGL 上下文,则它不可用。

关于opengl - glDrawPixels 不与 glfw 一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37123200/

相关文章:

c++ - 这种模型失真的来源是什么

opengl - GLSL 扩展在应该可用时不可用

c++ - OpenGL 无法使用 VAO 过程更新顶点缓冲区

c++ - 在函数周围调用std::thread()的工作方式不同

c++ - 如何在 C++ 中创建 glfw 线程?

opengl - freeglut 与 glew 的区别?

java.io.IOException 将 "player"纹理添加到屏幕时出现困难

c++ - 将 Depthbuffer 和 TextureBuffer 发送到同一个 Fragment OpenGL3

c - 如何在考虑性能的情况下最好地用C编写体素引擎

OpenGL:渲染一批几何体的有效方法?