我一直在尝试使用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;
}发布于 2016-05-10 03:54:34
在3.2版中,glDrawPixels已从核心概要文件中删除。因此,如果您使用核心概要文件创建OpenGL上下文,则它不可用。
https://stackoverflow.com/questions/37123200
复制相似问题