Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  Programmable pipeline  (Read 990 times)
0 Members and 1 Guest are viewing this topic.
Offline steg90

Senior Member


Medals: 1



« Posted 2013-05-10 19:12:01 »

Hi,

I've tried to use OGL2.0 with a vertex shader, doing it with LWJGL - fails on compiling the vertex shader which is fine as the shader compiles fine when I use ARB extensions - could it be my gfx card which is a intel hd 3000 on my macbook pro?

1  
2  
3  
4  
5  
6  
7  
vertex shader:

varying vec4 vertColor;
void main(){
           gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
           vertColor = vec4(0.0, 0.0, 1.0, 1.0);
}

Thanks for any help
Offline davedes
« Reply #1 - Posted 2013-05-10 21:21:04 »

What is the error? You can query the log with the following code, post-link:

1  
2  
int len = glGetProgrami(programHandle, GL_INFO_LOG_LENGTH);
String errLog = glGetProgramInfoLog(programHandle, len);


For a full tutorial on compiling your own shaders, see here:
https://github.com/mattdesl/lwjgl-basics/wiki/ShaderProgram-Utility

Offline steg90

Senior Member


Medals: 1



« Reply #2 - Posted 2013-05-10 21:48:11 »

Thanks,

What is the programHandle parameter?

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-05-10 23:20:31 »

The handle for your shader program object which you created with glCreateProgram().

Read the docs and tutorial and you will see... Smiley

Offline quew8

JGO Coder


Medals: 29



« Reply #4 - Posted 2013-05-11 13:08:53 »

Perhaps it is that you are not specifying the GLSL version you wanted. The ARB extension may only cater for the early versions of GLSL so it doesn't matter, but the core defaults to the newest.
Try sticking:
#version 120  (No semi-colon)
on the very first line of your shader.
Offline steg90

Senior Member


Medals: 1



« Reply #5 - Posted 2013-05-12 18:08:54 »

Hi,

Here is the code that seems to cause the crash:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
private static boolean printLogInfo(int obj) {
        IntBuffer iVal = BufferUtils.createIntBuffer(1);
        glGetProgram(obj, GL_INFO_LOG_LENGTH, iVal);   // <-- THIS LINE CAUSES CRASH, IF I REMOVE THEN OK

        int length = iVal.get();
        if (length > 1) {
            // We have some info we need to output.
           ByteBuffer infoLog = BufferUtils.createByteBuffer(length);
            iVal.flip();
            glGetProgramInfoLog(obj, iVal, infoLog);
            byte[] infoBytes = new byte[length];
            infoLog.get(infoBytes);
            String out = new String(infoBytes);
            System.out.println("Info log:\n" + out);
        } else return true;
        return false;
    }


Thanks,
Steve
Offline davedes
« Reply #6 - Posted 2013-05-12 19:13:36 »

What is the crash? If it is an exception, post the stack trace.

And why are you using that horribly convoluted method? Look at the code I posted earlier:

1  
2  
int len = glGetProgrami(programHandle, GL_INFO_LOG_LENGTH);
String errLog = glGetProgramInfoLog(programHandle, len);


Don't rely on the String to determine whether compilation was successful (sometimes a log will exist even if the shader is valid). Instead do something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
   ... compile shaders and attach them ...

   //link our program
  glLinkProgram(program);

   //grab our info log
  String infoLog = glGetProgramInfoLog(program, glGetProgrami(program, GL_INFO_LOG_LENGTH));
   
   //if some log exists, print it to sys err
  if (infoLog!=null && infoLog.trim().length()!=0)
      System.err.println(infoLog);
   
   //if the link failed, throw some sort of exception
  if (glGetProgrami(program, GL_LINK_STATUS) == GL_FALSE)
      throw new LWJGLException(
            "Failure in linking program. Error log:\n" + infoLog);


Like I said... Read the link I posted. Roll Eyes

Offline steg90

Senior Member


Medals: 1



« Reply #7 - Posted 2013-05-12 19:33:00 »

Thanks,

Stack trace:

1  
2  
3  
4  
5  
6  
7  
8  
9  
Exception in thread "main" org.lwjgl.opengl.OpenGLException: Invalid operation (1282)
   at org.lwjgl.opengl.Util.checkGLError(Util.java:59)
   at org.lwjgl.opengl.GL20.glGetProgram(GL20.java:551)
   at Square.printLogInfo(ShaderBox2.java:219)
   at Square.createVertShader(ShaderBox2.java:192)
   at Square.<init>(ShaderBox2.java:127)
   at ShaderBox2.init(ShaderBox2.java:71)
   at ShaderBox2.<init>(ShaderBox2.java:26)
   at ShaderBox2.main(ShaderBox2.java:75)


My gfx card supports shading language upto 1.20 and OGL 3.0 (except shading language 1.30) - Using GLview it reports OpenGL version as 2.1 Apple-8.0.61.

Is there any tutorials which show rendering using a vertex shader, what I've seen they still use glBegin?!

Thanks

Offline matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #8 - Posted 2013-05-12 20:39:57 »

You really need to learn how to search for error fixes...

Whenever you get an OpenGLException, simply search for the name of the method which throws it, in this case
glGetProgram


Then open the OpenGL Reference page link (usually 1st in Google search (I searched "glGetProgram")), and the paper contains the point "Errors", where you see whats the problem with each type of Error:

Quote

Errors


GL_INVALID_VALUE is generated if program is not a value generated by OpenGL.
GL_INVALID_OPERATION is generated if program does not refer to a program object.
GL_INVALID_OPERATION is generated if pname is GL_GEOMETRY_VERTICES_OUT, GL_GEOMETRY_INPUT_TYPE, or GL_GEOMETRY_OUTPUT_TYPE, and program does not contain a geometry shader.
GL_INVALID_ENUM is generated if pname is not an accepted value.

We search for our error: In your stacktrace lwjgl tells us 'Invalid operation', and there in the manual page it is: GL_INVALID_OPERATION.

Now whats the problem? The error is generated, if the program does not refer to a program object.

You never called
glCreateProgram()
it seems. Or at least it's return value is not what you give to check the log info...
Try to print 'obj' in your code. If it's <= 0, then something is wrong.
Also, use davedes' code. Or try out his tutorial. He explains it very well.

<edit>Fixed 'glGetProgram' to 'glCreateProgram'...</edit>

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline davedes
« Reply #9 - Posted 2013-05-12 20:46:50 »

Also glGetProgram expects a program handle (from glCreateProgram). If you are trying to get the log of the shader object (from glCreateShader) you need to use glGetShaderi and glGetShaderInfoLog.

This is likely the source of your error since your stack trace is showing the glGetProgram call is coming from your createVertShader() method.

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 (24 views)
2014-07-24 01:59:36

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

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

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

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

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

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

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

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

Riven (55 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!