Hello Guest

LWJGL 3 - Creating context/profile -

  • 1 Replies
LWJGL 3 - Creating context/profile -
« on: March 27, 2018, 22:25:08 »
Having originally began learning GLSL shaders using this tutorial
A lot of what I learnt was out of date.
I am currently reading a more up-to-date book, but noticed it was using a couple of deprecated methods.

I recalled the section named Deprecation, Core, and Compatibility in the following OpenGL summary I read a few weeks ago.

It talks about how OpenGL historically introduced a deprecation model and several profiles.
After having looked at the origins of OpenGL, and learning GLSL I wanted to learn about the most up to date style.
I want what I'm learning to be future proof and so I can use it for a long time.

My aim is to set the OpenGL profile to "Forward Compatible", so that I will be notified when using deprecated methods from the following book.

I decided to use glStart(GL_QUADS) to test what I was attempting was working.
However, even though the JavaDoc mentions this method as deprecated, the program unfortunately still compiles and runs fine.

I followed this video to set the context. Right at the beginning he talks about the context.
Am I missing something?
Code: [Select]
if ( !glfwInit() )
throw new IllegalStateException("Unable to initialize GLFW");

// Configure GLFW
glfwDefaultWindowHints(); // optional, the current window hints are already the default
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable

// Create the window
window = glfwCreateWindow(300, 300, "Hello World!", NULL, NULL);
if ( window == NULL )
throw new RuntimeException("Failed to create the GLFW window");


// Setup a key callback. It will be called every time a key is pressed, repeated or released.
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop

// Get the thread stack and push a new frame
try ( MemoryStack stack = stackPush() ) {
IntBuffer pWidth = stack.mallocInt(1); // int*
IntBuffer pHeight = stack.mallocInt(1); // int*

// Get the window size passed to glfwCreateWindow
glfwGetWindowSize(window, pWidth, pHeight);

// Get the resolution of the primary monitor
GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());

// Center the window
(vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2
} // the stack frame is popped automatically

// Make the OpenGL context current
// Enable v-sync

// Make the window visible

                // This line is critical for LWJGL's interoperation with GLFW's
// OpenGL context, or any context that is managed externally.
// LWJGL detects the context that is current in the current thread,
// creates the GLCapabilities instance and makes the OpenGL
// bindings available for use.

Thanks for the help :)
P.s. If anyone knows a newer/better GLSL book than the one I'm currently reading OR
a GLSL book tailored for LWJGL, I'd be extremely greatful.
« Last Edit: March 27, 2018, 22:30:13 by bawat »


Offline spasi

  • *****
  • 1972
    • WebHotelier
Re: LWJGL 3 - Creating context/profile -
« Reply #1 on: March 30, 2018, 14:07:57 »
The program may compile and run fine, but that doesn't mean it doesn't raise OpenGL errors. Try this:

Code: [Select]
// before glfwCreateWindow()

// ...

// after GL.createCapabilities()