Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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 2503 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.

Online gouessej
« 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.

 

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

The first screenshot will be displayed as a thumbnail.

pw (13 views)
2014-07-24 01:59:36

Riven (11 views)
2014-07-23 21:16:32

Riven (12 views)
2014-07-23 21:07:15

Riven (13 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!