Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
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  
  [LWJGL3] Nothing is rendering to screen  (Read 634 times)
0 Members and 1 Guest are viewing this topic.
Offline Hermasetas

Senior Devvie


Medals: 6
Projects: 2
Exp: 7 years


I do gamez, yes!


« Posted 2018-07-31 10:10:27 »

Hi All

I have been looking at this problem for hours now, so I'm taking it to you and maybe someone can help me.

I have been porting my 2d graphics library from LWJGL2 to LWJGL3 the past few days.
I have set up the screen and everything, but nothing is rendering.

The function
1  
glClear(GL_COLOR_BUFFER_BIT);
is working as intended and clears the screen to the desired color.

I have not changed any of my gl code when I ported and I receive no errors in Eclipse.
Neither do I get any errors from
1  
glGetError()
or from the openGL debug mode.

I am using
1  
glDrawElements(GL_TRIANGLES)
for my rendering where I update the buffers every frame.
This worked perfectly before but not now.

If i disable my shaders and use
1  
2  
3  
4  
5  
6  
7  
8  
glBegin(GL_TRIANGLES);
            glColor3f(1f, 0f, 0f);
            glVertex3f(-0.6f, -0.4f, 0f);
            glColor3f(0f, 1f, 0f);
            glVertex3f(0.6f, -0.4f, 0f);
            glColor3f(0f, 0f, 1f);
            glVertex3f(0f, 0.6f, 0f);
            glEnd();
it works..


My render code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
      if(numberOfVerticies == 0)
         return;
     
      glUseProgram(shaderProgramID);
     
      int numberOfIndecies = indexBuffer.position();
     
      glBindVertexArray(vaoID);
     
      buffer.flip();
      glBindBuffer(GL_ARRAY_BUFFER, vboID);
      glBufferSubData(GL_ARRAY_BUFFER, 0, buffer);
     
      indexBuffer.flip();
      glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ivboID);
      glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexBuffer);
     
      glDrawElements(GL_TRIANGLES, numberOfIndecies, GL_UNSIGNED_SHORT, 0);
     
      buffer.clear();
      indexBuffer.clear();
      numberOfVerticies = 0;


My shaders:
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  
#version 150

uniform mat4 projMatrix;

in vec3 position;
in vec4 color;

out vec4 pass_color;

void main()
{  
   gl_Position = projMatrix * vec4(position, 1.0);
   
   pass_color = color;
}


#version 150

in vec4 pass_color;

out vec4 out_color;

void main()
{  
   out_color = pass_color;
}


I also tried setting my projection matrix to the identity matrix just to see if that would make any difference, but no.

If anyone has any ideas to what might be the problem I would be so grateful for your help!
I have checked every single line of code that I thought might be the problem but nothing is working for me Sad
Offline KaiHH

JGO Kernel


Medals: 636



« Reply #1 - Posted 2018-07-31 12:06:07 »

Download LWJGLX/debug and run your application with the additional JVM argument -javaagent:/path/to/lwjglx-debug-1.0.0.jar and see whether it outputs any errors or warnings.
If not, please provide the complete code showing:
- how you setup and enable the vertex attributes
- how you load shaders
- how you set uniforms in the shaders
Offline Hermasetas

Senior Devvie


Medals: 6
Projects: 2
Exp: 7 years


I do gamez, yes!


« Reply #2 - Posted 2018-07-31 15:44:55 »

Thank you for the suggestion.

I get the following output in the console:
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  
[LWJGL] Version: 3.1.6 build 14
[LWJGL]     OS: Windows 10 v10.0
[LWJGL]    JRE: 1.8.0_181 amd64
[LWJGL]    JVM: Java HotSpot(TM) 64-Bit Server VM v25.181-b13 by Oracle Corporation
[LWJGL] Loading library (system): lwjgl
[LWJGL]    Using SharedLibraryLoader...
[LWJGL]    Found at: C:\Users\Mathias\AppData\Local\Temp\lwjglMathias\3.1.6-build-14\lwjgl.dll
[LWJGL]    Loaded from org.lwjgl.librarypath: C:\Users\Mathias\AppData\Local\Temp\lwjglMathias\3.1.6-build-14\lwjgl.dll
[LWJGL] MemoryUtil accessor: MemoryAccessorUnsafe
[LWJGL] MemoryUtil allocator: DebugAllocator
[LWJGL] Loading library: glfw
[LWJGL]    Using SharedLibraryLoader...
[LWJGL]    Found at: C:\Users\Mathias\AppData\Local\Temp\lwjglMathias\3.1.6-build-14\glfw.dll
[LWJGL]    Loaded from org.lwjgl.librarypath: C:\Users\Mathias\AppData\Local\Temp\lwjglMathias\3.1.6-build-14\glfw.dll
[LWJGL] Loading library (system): lwjgl_opengl
[LWJGL]    Using SharedLibraryLoader...
[LWJGL]    Found at: C:\Users\Mathias\AppData\Local\Temp\lwjglMathias\3.1.6-build-14\lwjgl_opengl.dll
[LWJGL]    Loaded from org.lwjgl.librarypath: C:\Users\Mathias\AppData\Local\Temp\lwjglMathias\3.1.6-build-14\lwjgl_opengl.dll
[LWJGL] Loading library: opengl32
[LWJGL]    opengl32.dll not found in org.lwjgl.librarypath=C:\Users\Mathias\AppData\Local\Temp\lwjglMathias\3.1.6-build-14
[LWJGL]    Loaded from system paths
[LWJGL] [GL] GL_ARB_shader_subroutine was reported as available but an entry point is missing.
[LWJGL] [GL] Using KHR_debug for error logging.
Exception in thread "main" java.lang.NoSuchMethodError: org.lwjgl.opengl.GL43.glGetInteger(I)I
   at org.lwjglx.debug.opengl.GLUtil.setupDebugMessageCallback(GLUtil.java:134)
   at org.lwjglx.debug.opengl.GLUtil.setupDebugMessageCallback(GLUtil.java:41)
   at org.lwjglx.debug.opengl.GL.createCapabilities(GL.java:36)
   at org.lwjglx.debug.$Proxy$13.createCapabilities7(Unknown Source)
   at display.Display.create(Display.java:61)
   at main.Main.main(Main.java:27)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x2350000
   at org.lwjgl.system.Callback.create(Callback.java:133)
   at org.lwjgl.system.Callback.<init>(Callback.java:83)
   at org.lwjgl.glfw.GLFWErrorCallback.<init>(GLFWErrorCallback.java:60)
   at org.lwjgl.glfw.GLFWErrorCallback$1.<init>(GLFWErrorCallback.java:97)
   at org.lwjgl.glfw.GLFWErrorCallback.createPrint(GLFWErrorCallback.java:97)
   at org.lwjglx.debug.$Proxy$13.createPrint2(Unknown Source)
   at display.Display.create(Display.java:38)
   at main.Main.main(Main.java:27)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x1C780000
   at org.lwjgl.system.Callback.create(Callback.java:133)
   at org.lwjgl.system.CallbackI.address(CallbackI.java:34)
   at org.lwjgl.opengl.GLDebugMessageCallback.create(GLDebugMessageCallback.java:54)
   at org.lwjglx.debug.opengl.GLUtil.setupDebugMessageCallback(GLUtil.java:109)
   at org.lwjglx.debug.opengl.GLUtil.setupDebugMessageCallback(GLUtil.java:41)
   at org.lwjglx.debug.opengl.GL.createCapabilities(GL.java:36)
   at org.lwjglx.debug.$Proxy$13.createCapabilities7(Unknown Source)
   at display.Display.create(Display.java:61)
   at main.Main.main(Main.java:27)
[LWJGL] 16 bytes leaked, thread 1 (main), address: 0x24B0000
   at org.lwjgl.system.Callback.create(Callback.java:133)
   at org.lwjgl.system.Callback.<init>(Callback.java:83)
   at org.lwjgl.glfw.GLFWErrorCallback.<init>(GLFWErrorCallback.java:60)
   at org.lwjglx.debug.glfw.GLFW$1.<init>(GLFW.java:50)
   at org.lwjglx.debug.glfw.GLFW.glfwInit(GLFW.java:50)
   at org.lwjglx.debug.$Proxy$13.glfwInit4(Unknown Source)
   at display.Display.create(Display.java:41)
   at main.Main.main(Main.java:27)


I can't see what the problem is...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline KaiHH

JGO Kernel


Medals: 636



« Reply #3 - Posted 2018-07-31 15:46:44 »

Oh yeah, please do use the latest version of LWJGL, 3.2.0.

EDIT: Now it suffices if you just re-download: LWJGLX/debug
Offline Hermasetas

Senior Devvie


Medals: 6
Projects: 2
Exp: 7 years


I do gamez, yes!


« Reply #4 - Posted 2018-08-01 07:25:01 »

I found the problem!
Thank you for your help! Cheesy

Although I found the problem and how to solve it, I don't really understand it.. Maybe you could explain it to me?

The problem was in my uniform projection matrix.
I have the code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
   public void resize(Matrix4f m)
   {
      FloatBuffer buf = BufferUtils.createFloatBuffer(16);
      m.get(buf);
      buf.flip();      
     
      glUseProgram(shaderProgramID);
      glUniformMatrix4fv(projMatrixID, false, buf);
   }

And for some reason the m.get(buf) does not move the position of the buffer, so when I flip the buffer it sets the limit to 0.
Is this a bug in Matrix4f.get? I'm using JOML 1.9.10 btw.

If I remove the buf.flip() then the rendering works! Smiley
But I thought you had to flip a buffer before reading from it..
Offline KaiHH

JGO Kernel


Medals: 636



« Reply #5 - Posted 2018-08-01 08:19:24 »

JOML does not follow Java NIO's behaviour with its relative Buffer.get() methods.
This irritates most people that are used to the behaviour of NIO's relative Buffer methods.

However:
1. Matrix4f.get(Buffer) is not a NIO buffer method (it just takes a Buffer as parameter). It might be irritating that the method is called "get" and that it therefore reminds people of a relative NIO Buffer method with the same name
2. having get() modify the buffer position and requiring the user to call flip() is just cumbersome. It's better to leave the buffer position as is
3. when you call OpenGL methods that read from or write to a NIO buffer, such as glTexSubImage2D, glBufferData or glReadPixels, you would also not rewind/flip the buffer afterwards, would you, because you assume that those methods do not modify the buffer position and they don't

LWJGLX/debug would also throw an exception if you tried to flip a buffer with position 0:
1  
2  
3  
Exception in thread "main" java.lang.IllegalStateException: calling flip() on a buffer with position = 0. Check if you called a method that actually modifies the buffer position.
   at your.package.and.TheClass.withTheMethod(TheClass.java:123)
   ...


For more common pitfalls like this, see: https://github.com/JOML-CI/JOML/wiki/Common-Pitfalls
Your particular problem is described here: https://github.com/JOML-CI/JOML/wiki/Common-Pitfalls#methods-taking-a-nio-buffer-do-not-modify-the-buffer-position

The behaviour of Matrix4f.get(FloatBuffer) is also described in its JavaDoc, which you can see here
Quote
This method will not increment the position of the given FloatBuffer.
I recommend you attach the sources jar to your project to have JavaDoc ready in your IDE for all JOML classes/methods.

I also recommend you use LWJGL's MemoryStack class to more efficiently allocate the very-short-lived Buffer, like so:
1  
2  
3  
4  
5  
6  
  public void resize(Matrix4f m) {
    glUseProgram(shaderProgramID);
    try (MemoryStack frame = MemoryStack.stackPush()) {
      glUniformMatrix4fv(projMatrixID, false, m.get(frame.mallocFloat(16)));
    }
  }

For more information on efficient memory-management in LWJGL3, read: https://blog.lwjgl.org/memory-management-in-lwjgl-3/
Pages: [1]
  ignore  |  Print  
 
 

 
hadezbladez (13 views)
2018-11-16 13:46:03

hadezbladez (19 views)
2018-11-16 13:41:33

hadezbladez (6 views)
2018-11-16 13:35:35

hadezbladez (6 views)
2018-11-16 13:32:03

EgonOlsen (1880 views)
2018-06-10 19:43:48

EgonOlsen (1904 views)
2018-06-10 19:43:44

EgonOlsen (1261 views)
2018-06-10 19:43:20

DesertCoockie (1706 views)
2018-05-13 18:23:11

nelsongames (1392 views)
2018-04-24 18:15:36

nelsongames (2007 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!