OpenGL不会让我画任何东西
OpenGL won't let me draw a thing
我在代码中遇到了一个奇怪的错误,它不允许我绘制任何东西。。。
void render(void) {
glClear(GL_COLOR_BUFFER_BIT);
glLineWidth(4.0);
glPointSize(4.0);
glColor3i(0, 1, 1);
glBegin(GL_POINTS);
glVertex2i(0, 0);
glVertex2i(2, 2);
glVertex2i(3, 3);
glEnd();
glutSwapBuffers();
}
int main(int argc, char **argv) {
int Largura, Altura;
//width
Largura = (abs(Plano::MinX) * Plano::EspacoPix) + (abs(Plano::MaxX) * Plano::EspacoPix);
//height
Altura = (abs(Plano::MinY) * Plano::EspacoPix) + (abs(Plano::MaxY) * Plano::EspacoPix);
// these are cartesian coordinates,
// at class Plano: enum Dimension {MinY=-50, MaxY=50, MinX=-50, MaxX=50, EspacoPix=5};
glutInit(&argc, argv);
glutInitWindowPosition(-1, -1);
glutInitWindowSize(Largura, Altura);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glClearColor(1, 1, 1, 1);
glutCreateWindow("Graphix");
glMatrixMode(GL_PROJECTION);
//glEnable(GL_POINT_SMOOTH);
//glEnable(GL_LINE_SMOOTH);
gluOrtho2D(Plano::MinX, Plano::MaxX, Plano::MinY, Plano::MaxY); // left, right, bottom, top
glutDisplayFunc(render);
glutIdleFunc(render);
std::cout << "[Dbg] Dimensions: Height=" << Altura << "px Width=" << Largura << "px " << std::endl;
std::cout << "[Dbg] Ortho: Left=" << Plano::MinX << ", Right=" << Plano::MaxX << ", Bottom=" << Plano::MinY << ", Top=" << Plano::MaxY << std::endl;
//glGet with argument GL_COLOR_CLEAR_VALUE
float cores[4] = {-1, -1, -1, -1}; // defaults
glGetFloatv(GL_COLOR_CLEAR_VALUE, cores);
std::cout << "[Dbg] Color Buffer: R=" << cores[0] << " G=" << cores[1] << " B=" << cores[2] << " A=" << cores[3] << std::endl;
glutMainLoop();
return(0);
}
我得到的只是一个黑色的屏幕,颜色缓冲区,我认为应该是1,1,1实际上是0,0,0…如果我错了,请纠正我,但屏幕的中心是,因为gluOrtho2D调用,x=0,y=0,对吧?对吗?:)
glClearColor必须在glutCreateWindow之后调用,因为OpenGL上下文尚未创建。
还要注意,您正在学习过时的OpenGL编程技术。
glColor、glBegin、glEnd、glVertex*、glColor*glMatrixMode、gluOrtho2D、glu*现在都是不推荐使用的函数。
有些人认为他们可能更容易学习,但我认为这不会太多,这都是你必须忘记的东西。
glBegin()和glEnd()会导致一次绘制对象1个顶点,这非常缓慢。
新的方法包括将坐标放入一个浮动数组中,并将其发送到图形卡中,以便一次绘制所有坐标。自从OpenGL 1.1(1997年发布)支持顶点阵列(尽管它们现在也被弃用,取而代之的是顶点缓冲区对象(或VBO),这些对象在功能上类似,并且自OpenGL 1.5(2005年发布)以来一直存在于OpenGL中)以来,没有理由将这些旧东西用作一切。
我建议你看看http://www.opengl-tutorial.org/对于初学者来说并不难的更新教程。
我在这里的答复是:https://gamedev.stackexchange.com/questions/32876/good-resources-for-learning-modern-opengl-3-0-or-later/32917#32917
我以前没有做过太多OpenGL 2编码,但我认为在调用glBegin之前需要调用glLoadIdentity(),在调用glMatrixMode之前需要调用glLoadIdentity。
- OpenGL 着色器不绘制任何东西 - 糟糕的精灵类
- 透视视图的任何解决方案 openGL qt.
- 我可以使用QT的OpenGL功能而没有任何小部件
- OpenGL程序不显示任何图片
- OpenGL 3.3不能绘制任何东西
- OpenGL + SDL + glew 在成功初始化后不会绘制任何内容
- 自定义 OpenGL 缓冲区类不显示任何内容
- 为什么我的 openGL 顶点缓冲区对象不会绘制任何内容?
- 有关如何在OpenGL中正确旋转/翻译对象的任何建议,以实现以下效果
- OpenGL根本不渲染任何东西
- OpenGL 3.3不会渲染任何纹理(黑色纹理、C++、GLFW/SOIL)
- Opengl 3.3 不会绘制任何东西。使用 GLSL 330 内核
- 是否有任何计划或现有项目将OpenGL API移植到C++
- OpenGL - 重新绑定 glBindVertexArray 不会在屏幕上绘制任何内容
- OpenGL不会让我画任何东西
- 为什么我的OpenGL引擎中没有从MyGUI获得任何屏幕输出
- Qt 5.5和OpenGL:程序在没有任何明显原因的情况下表现得很奇怪
- OpenGL 2d HUD over 3d不会渲染任何内容
- 如何安全地确保char*类型将根据OpenGL规范正确实现(在任何平台上)
- 无法编译任何opengl/freeglut/glut源代码