我刚开始阅读蓝皮书的初始章节,并理解投影矩阵可用于修改我们所需坐标系到真实坐标系的映射。它可以用于重置的坐标系和由以下(作为一个例子)
在OpenGL中设置绘图的坐标系
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //With 1's in the diagonal of the identity matrix, the coordinate system is rest from -1 to 1 (and the drawing should happen then inside those coordinates which be mapped later to the screen)
又如它从-1更改为1上左,右,顶和底:(宽度:1024,身高:768,屏幕比例:1.33),并改变坐标系统,做到:
glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 100.0, 100.0, 1000.0);
我预期的坐标系对OpenGL更改为-133在左边,133在右边,-100在底部和100顶上。使用这些坐标,我知道绘图将在这些坐标内完成,而这些坐标之外的任何内容都将被裁剪。
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100 * aspectRatio, 100 * aspectRatio, -100, 100, 100, 1000);
glMatrixMode(GL_MODELVIEW);
glRectf(-50.0, 50.0, 200, 100);
但是,上述命令在屏幕上没有给出任何输出。我在这里错过了什么?
您不应该使用弃用的API!在当前的API中,坐标系统的设置有很大的不同(你必须自己完成),学习已弃用的API是浪费时间的恕我直言。 – 2013-05-12 11:41:08
@FelixK。 :你能指出最新的正确方法吗?我甚至不确定它是什么。 – user1240679 2013-05-12 11:47:25
也许你没有设置颜色。我建议为OpenGL 3或更高版本做一些教程,以获得一些东西。 – 2013-05-12 11:53:59