我一直在尝试使用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;
}
答案 0 :(得分:3)
glDrawPixels
已从版本3.2中的核心配置文件中删除。因此,如果使用核心配置文件创建OpenGL上下文,则无法使用它。