Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 更换LWJGL中的glOrtho?_Java_Opengl_Lwjgl - Fatal编程技术网

Java 更换LWJGL中的glOrtho?

Java 更换LWJGL中的glOrtho?,java,opengl,lwjgl,Java,Opengl,Lwjgl,我正在从传统的OpenGL迁移到现代的OpenGL,但是我需要一个glOrtho的替代品,因为它现在已经被删除了。由于输入的不同,我无法准确地理解如何在爪哇中完成C++中的一些事情。p> 相关代码:GL11.glOrtho(0,Display.getWidth(),0,Display.getWidth(),100,-100) 这是我当前使用的ortho函数,以及现在未使用的旧的glEnable。如果您想在Java中使用OpenGL,我建议使用JOGL而不是LWJGL。因为LWJGL更像是一个“游

我正在从传统的OpenGL迁移到现代的OpenGL,但是我需要一个glOrtho的替代品,因为它现在已经被删除了。由于输入的不同,我无法准确地理解如何在爪哇中完成C++中的一些事情。p> 相关代码:
GL11.glOrtho(0,Display.getWidth(),0,Display.getWidth(),100,-100)

这是我当前使用的ortho函数,以及现在未使用的旧的glEnable。

如果您想在Java中使用OpenGL,我建议使用JOGL而不是LWJGL。因为LWJGL更像是一个“游戏引擎”。下面是一些示例代码

    final GL2 gl = drawable.getGL().getGL2();
    gl.glOrtho(left, right, bottom, top, near_val, far_val);
    gl.glEnable(cap);

好消息是,
glOrtho(…)
实现起来很简单,您甚至不需要像透视投影矩阵那样的任何三角函数

您需要按照如下方式构造LWJGL
Matrix4f


(来源:)
,给定:
(来源:)

请记住,此矩阵是主列,因此您可以按如下方式填充它:

Matrix4f.m00 = 2.0f/(right-left);
Matrix4f.m01 = 0.0f;
Matrix4f.m02 = 0.0f;
Matrix4f.m03 = 0.0f;

Matrix4f.m10 = 0.0f;
Matrix4f.m11 = 2.0f/(top-bottom);
Matrix4f.m12 = 0.0f;
Matrix4f.m13 = 0.0f;

Matrix4f.m20 = 0.0f;
Matrix4f.m21 = 0.0f;
Matrix4f.m22 = -2.0f/(far-near);
Matrix4f.m23 = 0.0f;

Matrix4f.m30 = -(right+left)/(right-left);
Matrix4f.m31 = -(top+bottom)/(top-bottom);
Matrix4f.m32 =   -(far+near)/(far-near);
Matrix4f.m33 = 1.0f;

这真的帮不了大忙,问题是如何从传统的OpenGL迁移到现代的OpenGL
glOrtho(…)
在现代OpenGL(3.2+内核)中仍然不可用,无论您使用LWJGL还是JOGL。我会在与glOrtho相同的位置使用它吗?还是我需要在每个循环中都应用它?@KenzieTogami:你正在转向“现代”OpenGL,对吗?实际上,你要做的就是把这个矩阵传递给GLSL程序矩阵。现代OpenGL消除了“当前”矩阵堆栈,因此没有与当前矩阵相乘的函数,而是将所有矩阵传递给着色器。好的,我想我明白了。谢谢