首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >glDrawPixels不适用于glfw

glDrawPixels不适用于glfw
EN

Stack Overflow用户
提问于 2016-05-10 02:45:36
回答 1查看 829关注 0票数 2

我一直在尝试使用glDrawPixels直接绘制一些像素,但找不到哪里出了问题。我看到了一些使用glut的代码示例,它正在工作。但是使用glfw我不能让它工作。这是我正在使用的代码。任何帮助都将不胜感激!

代码语言:javascript
复制
  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;
}
EN

回答 1

Stack Overflow用户

发布于 2016-05-10 03:54:34

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

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37123200

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档