【发布时间】:2021-08-13 18:35:46
【问题描述】:
我想用openGL画点,我有一个32x32的屏幕尺寸,我想用红色填充它,但是我不明白glVertex2f(-1, 0.5)的参数是如何工作的
我的第一直觉是做这样的事情:
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(32, 32); // Set the window's initial width & height
glutDisplayFunc(displaySpectrogram); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the event-processing loop
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer (background)
glBegin(GL_POINTS);
glColor3f(1.0f, 0.0f, 0.0f); // Red
for (int i = 0; i < 32; i++)
{
for (int j = 0; j < 32; j++)
{
glVertex2f(i,j);
}
}
glEnd();
glFlush(); // Render now
但glVertex2f() 参数范围是 -1 到 1 我认为所以我不确定如何实现。
纹理还有另一种方法,但我不知道如何使用它们,并且没有在线教程
【问题讨论】:
-
您使用旧版 OpenGL 的任何原因?如果您没有理由坚持使用过时的技术,我建议您忘记这一点并学习 OpenGl3.x 或更新版本。那里有很多很好的教程。
-
哦,我没想太多,我是从一个有那个版本的旧教程安装的,我应该升级是的
-
你能给我一个好的教程吗?我刚刚升级到 OpenGl3,我该如何实现我的要求? @churill
-
“我有一个 32x32 的屏幕尺寸,我想用颜色填充它” - 那你为什么不画一个四边形呢?为什么不使用
glOrtho/Orthographic projection(无论点还是四边形)? -
因为这只是一个简单的例子,我的项目需要我用不同的颜色绘制每个像素@Rabbid76
标签: c++ image opengl draw opengl-compat