- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 lwjgl 3 并学习现代 opengl (3)。我想将统一矩阵发送到顶点着色器,以便我可以应用转换。我尝试过,但程序因此错误而崩溃
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000073a9820d, pid=8644, tid=2760
#
# JRE version: Java(TM) SE Runtime Environment (8.0_31-b13) (build 1.8.0_31-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.31-b07 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C [nvoglv64.DLL+0xd5820d]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# E:\Copy\Code\Personal\atei-graphics\GraphicsProject\hs_err_pid8644.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
显然我做错了什么。
问题似乎出在这行代码
glUniformMatrix4(uniformMatrixLocation, false, mvp.getBuffer());
如果我删除这行代码,程序执行时不会出错。
我尝试传递一个对角矩阵来检查问题是否出在矩阵本身,但我仍然得到了相同的结果
mvp 是我传递给着色器的对角矩阵。
uniformMatrixLocation 保存我用这行代码找到的位置
glGetUniformLocation(shaderProgram.programId, "MVP");
它不会返回负数,所以这里可能没有错误。
我正在将此库用于 Mat4 类
https://github.com/jroyalty/jglm
贝娄是我的代码的“工作”示例,尽可能小。
//glfw create windows and etc
int programId = glCreateProgram();
int vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(vertexShaderId, FileUtils.readFile("shaders/vertex.glsl"));
glCompileShader(vertexShaderId);
if (glGetShaderi(vertexShaderId, GL_COMPILE_STATUS) == GL_FALSE) {
throw new RuntimeException("Error creating vertex shader\n"
+ glGetShaderInfoLog(vertexShaderId, glGetShaderi(vertexShaderId, GL_INFO_LOG_LENGTH)));
}
glAttachShader(programId, vertexShaderId);
int fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShaderId, FileUtils.readFile("shaders/fragment.glsl"));
glCompileShader(fragmentShaderId);
if (glGetShaderi(fragmentShaderId, GL_COMPILE_STATUS) == GL_FALSE) {
throw new RuntimeException("Error creating vertex shader\n"
+ glGetShaderInfoLog(fragmentShaderId, glGetShaderi(fragmentShaderId, GL_INFO_LOG_LENGTH)));
}
glAttachShader(programId, fragmentShaderId);
glLinkProgram(programId);
if (glGetProgrami(programId, GL_LINK_STATUS) == GL_FALSE) {
throw new RuntimeException("Unable to link shader program:");
}
/*
Hold the location of the matrix in the shader
*/
int uniformMatrixLocation = glGetUniformLocation(programId, "MVP");
float[] vertices = {
+0.0f, +0.8f, 0,
-0.8f, -0.8f, 0,
+0.8f, -0.8f, 0
};
int vaoId = glGenVertexArrays();
glBindVertexArray(vaoId);
FloatBuffer verticesBuffer = BufferUtils.createFloatBuffer(vertices.length);
verticesBuffer.put(vertices).flip();
int vboId = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, vboId);
glBufferData(GL_ARRAY_BUFFER, verticesBuffer ,GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
glBindVertexArray(0);
glClearColor(0,0,0,1);
while (glfwWindowShouldClose(window) == GL_FALSE) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
glUseProgram(programId);
Mat4 mvp = new Mat4(1.0f);//diagonal matrix , should just show a triangle on the screen
/*
Crashes here
*/
//glUniformMatrix4(uniformMatrixLocation, false, mvp.getBuffer());
glBindVertexArray(vaoId);
glEnableVertexAttribArray(0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glBindVertexArray(0);
glUseProgram(0);
glfwPollEvents();
glfwSwapBuffers(window); // swap the color buffers
}
//dispose stuff no point showing them here
顶点着色器
#version 330 core
layout(location = 0) in vec3 position;
uniform mat4 MVP;
void main(){
gl_Position = MVP*vec4(position,1);
}
片段着色器
#version 330 core
out vec4 color;
void main()
{
color = vec4(1,1,1,1);
}
对不起,如果之前有人问过这个问题,我在网上搜索并没有找到任何有用的东西。预先感谢您。
最佳答案
崩溃很可能发生,因为您正在向 LWJGL 传递从 Mat4.getBuffer()
返回的堆上浮点缓冲区。 JWJGL requires that you pass it direct buffers :
LWJGL requires that all NIO buffers passed to it are direct buffers. Direct buffers essentially wrap an address that points to off-heap memory, i.e. a native pointer. This is the only way LWJGL can safely pass data from Java code to native code, and vice-versa, without a performance penalty. It does not support on-heap Java arrays (or plain NIO buffers, which wrap them) because arrays may be moved around in memory by the JVM's garbage collector while native code is accessing them. In addition, Java arrays have an unspecified layout, i.e. they are not necessarily contiguous in memory.
您可以使用 BufferUtils 类,就像您已经在顶点中使用的那样:
FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16).put(mvp.getBuffer()).flip();
...
glUniformMatrix4(uniformMatrixLocation, false, matrixBuffer);
如果这不起作用,请尝试以下方法:
FloatBuffer matrixBuffer = BufferUtils.createFloatBuffer(16).put(new float[] {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f}).flip();
关于java - lwjgl 3 , glUniformMatrix4 导致 jre 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61727093/
我正在尝试运行 servlet,因此我想知道要下载哪一个客户端 JRE 或服务器 JRE,因为 Oracle 网站上有两个可用的 JRE?我安装了 JDK 7。 最佳答案 服务器和客户端虚拟机之间的主
我无法理解 Java JRE 的一些基础知识。 我需要在嵌入式系统中运行 Java 代码,为此我需要在 Linux 内核中安装一个最小的 Java 运行时环境,也就是说,执行 Java 二进制文件所需
我正在编写 Java 小程序,想知道将其包含在网页中的最佳方式。 我希望它能提示用户安装 JRE(如果她还没有的话)。此功能应该(理想情况下)在运行 Java 的任何操作系统上跨浏览器工作。另一个要求
我希望使用 JRE 版本 1.6.0_14 加载我的小程序。我已经安装了更新 14、17、24 和 35。我正在使用 标记为 classid加载带有更新 14 的版本。 在这种情况下,小程序会加载更新
我正在配置构建路径,以便我的 Eclipse 项目之一使用与工作区默认值不同的 JRE。在 JRE System Library 窗口中,我看到了 3 个选项... 我知道我不想使用默认工作区,但执行
小程序在浏览器的 JRE 中运行。这是否意味着您不必在计算机上安装 JRE 即可运行小程序? 最佳答案 “浏览器的 JVM”是您安装在计算机上的 JRE。浏览器通常不会自带,它们只会使用您已经安装在系
JDK 中包含的 JRE(位于 jre 文件夹内)和独立的 JRE 有什么区别?有吗? 最佳答案 “独立 JRE”(有时也称为“公共(public) JRE”)通常不包含 HotSpot 的服务器版本
已结束。此问题不符合 Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 a specific programming problem, a software a
我进入 Eclipse 的首选项,将默认 JRE 更改为 Java SE 8,并将 Eclipse 的编译器设置更改为 1.8 JDK 合规性。我什至删除了其他 JRE。 但是,当我导入项目时,正如您
最近我将我的 Linux 机器中的 JRE 从 1.7 + JIT 升级到没有 JIT 的 1.8,并注意到性能大幅下降,即时编译 JVM 是否比带解释器的 JVM 快得多?谢谢, 最佳答案 JIT
我开发了一个 e4 应用程序,可以在 mac os x 和 windows 中运行 我正在使用 mac os x jre 中存在的一些类,但 Windows jre 中缺少它们 当我们从 window
我有一个项目 1 需要在 1.7 上运行,该项目依赖于另一个在 1.8 上构建的项目 2。 我试图在项目 1 内调用项目 2 中的类,但出现一个已知错误,该错误已在 1.8 中修复。如果我在 JRE
我正在编写一个 Java Swing 应用程序。我从 Oracle 网站下载了适用于 Linux 平台的 JRE,并将这个 JRE 捆绑到了我的应用程序中。 我已经给出了一个启动器脚本,其中我引用了捆
我正在通过 java 1.6 u_17 进行编程,但我安装了 JRE 版本 6 和 JRE 版本 7,那么如何从 JDK 1.6 运行我编译的程序以仅通过 JRE 6 运行? 默认情况下,它通过 JR
这个问题在这里已经有了答案: how to check jre version using java application (6 个答案) 关闭 7 年前。 我安装了多个 JRE(6、7、8,32
我已经在我的机器上安装了 Java 8 并用它启动了一个项目。但是,当我使用 @Override 注释时,代码带有红色下划线,并且出现错误 Syntax error, annotations are
我(作为一个非 Java 的人)对我的本地 JRE 10 安装需要更新感到困惑,但是在更新时,我得到了 JRE 8!这甚至在 https://java.com/en/download/more_inf
私有(private) jre 和公共(public) jre 有什么区别?有没有关于这个主题的官方论文? 我没有找到关于这个主题的任何问题。我也无法在周围找到令人满意的东西。 最佳答案 A JRE
Java JRE 混合代码安全性,从 JRE 1.6.0_19 及更高版本开始最初在 2010 年左右,使用 JDK/JRE 1.6.0_12 实现、构建和部署了一个主 jar Java Applet
我需要 JRE 来使用仅提供英文版本的 JRE 资源的翻译版本。 根据 ResourceBundle.java 文档,这很简单:添加具有正确语言环境后缀的本地化资源。例如,标准 XMLSchemaMe
我是一名优秀的程序员,十分优秀!