Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shaders - compile and linking errors  (Read 1806 times)
0 Members and 1 Guest are viewing this topic.
Offline Irbis

Senior Newbie





« Posted 2011-05-19 20:42:14 »

Hello! I have a problem with checking the linking errors. My program works but my function still prints a linker error and I don't have any ideas what is wrong (printing errors for vertex and fragment shader works correctly). However when I use gl = new DebugGL3(gl); I get some errors (refer to gl.glGetShaderiv(shaderProgramID, GL3.GL_LINK_STATUS, IntBuffer.wrap(statusLinker))) and the program doesn't start:


Exception in thread "Timer-0" javax.media.opengl.GLException: javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glGetShaderiv(<int> 0x1, <int> 0x8B82, <java.nio.IntBuffer> java.nio.HeapIntBuffer[pos=0 lim=1 cap=1]): GL_INVALID_OPERATION ( 1282 0x502),


My initShaders function:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
    private void initShaders(GL3 gl)
    {
       
        shaderProgramID = gl.glCreateProgram();

        int vertexShaderID = gl.glCreateShader(GL3.GL_VERTEX_SHADER);
        gl.glShaderSource(vertexShaderID, 1, new String[]{vertexShader}, null);
        gl.glCompileShader(vertexShaderID);
        int statusVertexShader[] = new int[1];
        gl.glGetShaderiv(vertexShaderID, GL3.GL_COMPILE_STATUS, IntBuffer.wrap(statusVertexShader));
        if(statusVertexShader[0] == GL3.GL_FALSE)
        {
            int infoLogLenght[] = new int[1];
            gl.glGetShaderiv(vertexShaderID, GL3.GL_INFO_LOG_LENGTH, IntBuffer.wrap(infoLogLenght));
            ByteBuffer infoLog = Buffers.newDirectByteBuffer(infoLogLenght[0]);
            gl.glGetShaderInfoLog(vertexShaderID, infoLogLenght[0], null, infoLog);
            byte[] infoBytes =new byte[infoLogLenght[0]];
            infoLog.get(infoBytes);
            String out =new String(infoBytes);
            System.out.println("Vertex shader error:\n" + out);
        }
        gl.glAttachShader(shaderProgramID, vertexShaderID);
        gl.glDeleteShader(vertexShaderID);

        int fragmentShaderID = gl.glCreateShader(GL3.GL_FRAGMENT_SHADER);
        gl.glShaderSource(fragmentShaderID, 1, new String[]{fragmentShader}, null);
        gl.glCompileShader(fragmentShaderID);
        int statusFragmentShader[] = new int[1];
        gl.glGetShaderiv(fragmentShaderID, GL3.GL_COMPILE_STATUS, IntBuffer.wrap(statusFragmentShader));
        if(statusFragmentShader[0] == GL3.GL_FALSE)
        {
            int infoLogLenght[] = new int[1];
            gl.glGetShaderiv(fragmentShaderID, GL3.GL_INFO_LOG_LENGTH, IntBuffer.wrap(infoLogLenght));
            ByteBuffer infoLog = Buffers.newDirectByteBuffer(infoLogLenght[0]);
            gl.glGetShaderInfoLog(fragmentShaderID, infoLogLenght[0], null, infoLog);
            byte[] infoBytes =new byte[infoLogLenght[0]];
            infoLog.get(infoBytes);
            String out =new String(infoBytes);
            System.out.println("Fragment shader error:\n" + out);
        }
        gl.glAttachShader(shaderProgramID, fragmentShaderID);
        gl.glDeleteShader(fragmentShaderID);
       
       
        gl.glLinkProgram(shaderProgramID);
        gl.glValidateProgram(shaderProgramID);
       
        int statusLinker[] = new int[1];
        gl.glGetShaderiv(shaderProgramID, GL3.GL_LINK_STATUS, IntBuffer.wrap(statusLinker));
        if(statusLinker[0] == GL3.GL_FALSE)
        {
            int infoLogLenght[] = new int[1];
            gl.glGetShaderiv(shaderProgramID, GL3.GL_INFO_LOG_LENGTH, IntBuffer.wrap(infoLogLenght));
            ByteBuffer infoLog = Buffers.newDirectByteBuffer(infoLogLenght[0]);
            gl.glGetShaderInfoLog(shaderProgramID, infoLogLenght[0], null, infoLog);
            byte[] infoBytes =new byte[infoLogLenght[0]];
            infoLog.get(infoBytes);
            String out =new String(infoBytes);
            System.out.println("Linker error:\n" + out);
        }
       
    }
Offline lhkbob

JGO Knight


Medals: 32



« Reply #1 - Posted 2011-05-19 22:20:01 »

According to http://www.opengl.org/sdk/docs/man/xhtml/glGetShader.xml, GL_INVALID_OPERATION is generated if the shader id isn't a shader, and if you're within a glBegin()/glEnd() pair.

At the bottom of your code, you're passing your program id into the glGetShader call.  Since the program id isn't a shader object, this will always fail.  Instead for program queries, use glGetProgram and glGetProgramInfoLog.

Offline gouessej

JGO Ninja


Medals: 33
Projects: 1


TUER


« Reply #2 - Posted 2011-05-23 11:49:43 »

According to http://www.opengl.org/sdk/docs/man/xhtml/glGetShader.xml, GL_INVALID_OPERATION is generated if the shader id isn't a shader, and if you're within a glBegin()/glEnd() pair.

At the bottom of your code, you're passing your program id into the glGetShader call.  Since the program id isn't a shader object, this will always fail.  Instead for program queries, use glGetProgram and glGetProgramInfoLog.
I found a program with the same mistake when I began using shaders lol. Irbis seems to have used the same source of inspiration than me.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (93 views)
2013-05-17 21:29:12

alaslipknot (101 views)
2013-05-16 21:24:48

gouessej (131 views)
2013-05-16 00:53:38

gouessej (126 views)
2013-05-16 00:17:58

theagentd (137 views)
2013-05-15 15:01:13

theagentd (125 views)
2013-05-15 15:00:54

StreetDoggy (166 views)
2013-05-14 15:56:26

kutucuk (188 views)
2013-05-12 17:10:36

kutucuk (191 views)
2013-05-12 15:36:09

UnluckyDevil (198 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.623 seconds with 22 queries.