Drawing textured quads using shaders + OpenGL bindings

Started by Screendead, October 07, 2017, 00:45:20

Previous topic - Next topic

Screendead

I'm pretty new to LWJGL, and I realise I'm biting off a huge chunk very quickly, but please be patient.
I'm trying to render a quad to the window (just one for now, but eventually I'll be displaying many), and I get a nasty error from the JRE:
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000689d4750, pid=8696, tid=0x0000000000001e8c
#
# JRE version: Java(TM) SE Runtime Environment (8.0_144-b01) (build 1.8.0_144-b01)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.144-b01 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  [nvoglv64.DLL+0x814750]
#
# 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:
# F:\Eclipse Projects\Deserted\hs_err_pid8696.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

The full error log is attached.

I have also attached a .zip file with all of the source code for the project in it.
Any help would be greatly appreciated.
Thanks!

spasi

The MasterRenderer::render method looks very wrong:

- You're mixing generic vertex attributes (glVertexAttrib) with fixed-function attributes (glVertex, glTexCoord). You should use one or the other, depending on what your vertex shader accesses.
- You're trying to bind the GL_ELEMENT_ARRAY_BUFFER to vertex attrib 1? Vertex attributes are for data, not indices.
- You're unbinding the GL_ELEMENT_ARRAY_BUFFER_ARB before the glDrawElements call.

I recommend setting up a GL error callback (you can use GLUtil.setupDebugMessageCallback()) and if that doesn't help, use the LWJGLX/debug agent.

Screendead

Okay, now it actually draws something, which is good.
I don't understand why it messes up the textures?
And I'm sorry, but I used GLUtil.setupDebugMessageCallback() and it gives me several errors:
[LWJGL] OpenGL debug message
	ID: 0x502
	Source: API
	Type: ERROR
	Severity: HIGH
	Message: GL_INVALID_OPERATION error generated. No active program.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 1 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 2 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 3 (bound to GL_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.
[LWJGL] OpenGL debug message
	ID: 0x20071
	Source: API
	Type: OTHER
	Severity: NOTIFICATION
	Message: Buffer detailed info: Buffer object 4 (bound to GL_ELEMENT_ARRAY_BUFFER_ARB, usage hint is GL_STATIC_DRAW) will use VIDEO memory as the source for buffer object operations.


As I am new to LWJGL, I have been following several tutorials online, all of which seem to do different things, so I don't understand your three points. Could you please clarify why those things are bad practice?
I've included the complete source code and resources for my project.

KaiHH

You are not new to LWJGL, you are new to OpenGL.

Like BDL on Stackoverflow told you, you should look for tutorials.
In case you searched for tutorials/articles/videos about LWJGL, don't do this. Instead, look for tutorials about OpenGL.
You will have to get comfortable reading C/C++ code for that, since all good OpenGL tutorials use C/C++ in code examples.
Just google for "OpenGL tutorial" and work your way through the links on the first result page.

Lastly: OpenGL is one of the most complex/complicated/very-hard-to-learn APIs in the world. And it is veeery old (21 years) and changed a lot in this time. Nothing you'll find will be "the definitive way of doing things". There are lots of ways to do anything in OpenGL, partly because hardware evolved heavily over the last two decades and the API had to account for that. You gonna have to have a lot of patience and learn through many many maaany tutorials and small toy projects. At some point, you even need to look up the OpenGL Specification. It'll obviously contain the most detailed and exact information about everything.