Hello,
I am playing with GLSL with LWJGL. I tried to render textures via shaders. It worked, but it only works when I don't call glUniform.., and when I call
glUniform.. it crashes:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x56781c67, pid=4032, tid=3204
#
# JRE version: Java(TM) SE Runtime Environment (8.0_05-b13) (build 1.8.0_05-b13)
# Java VM: Java HotSpot(TM) Client VM (25.5-b02 mixed mode windows-x86 )
# Problematic frame:
# C [ig7icd32.dll+0x171c67]
#
# 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:
# C:\Users\Admin\workspace\GLSL\hs_err_pid4032.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
I don't know how can it work when I don't even set an uniform...
Anyway, here's my code:
try {
t = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("bird2.png"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ShaderLoader shaders = new ShaderLoader("shader.vs", "shader.fs");
glActiveTexture(GL_TEXTURE0);
t.bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
while (!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shaders.useProgram();
//glUniform1i(glGetUniformLocation(shaders.shaderProgram, "texture"), GL_TEXTURE0);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 1.0f);
glVertex2f(-0.5f, -0.5f);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(0.5f, -0.5f);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(0.5f, 0.5f);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glUseProgram(0);
Display.update();
Display.sync(60);
}
shaders.delete();
t.release();
ShaderLoader is my class that loads shaders, links and validates the program...
So how does it work without glUniform and why it crashes with glUniform?
Sorry if this is a dumb question, I am still a beginner with GLSL....
Thanks,
MatejaS
EDIT:
Sorry, I forgot to add my shader code.. Maybe it'll help someone...
Vertex shader:
void main() {
gl_Position = ftransform();
gl_TexCoord[0] = gl_MultiTexCoord0;
}
Fragment shader:
uniform sampler2D texture;
void main() {
gl_FragColor = texture2D(texture, gl_TexCoord[0].st);
}