Hello Guest

LWJGL 3 - Creating context/profile -

  • 1 Replies
  • 659 Views
LWJGL 3 - Creating context/profile -
« on: March 27, 2018, 22:25:08 »
Having originally began learning GLSL shaders using this tutorial
https://www.opengl.org/sdk/docs/tutorials/TyphoonLabs/
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.
http://openglbook.com/chapter-0-preface-what-is-opengl.html

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.
https://www.packtpub.com/game-development/opengl-4-shading-language-cookbook-second-edition

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.
https://youtu.be/WvVog06bLEY?t=105
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
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);


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

glfwMakeContextCurrent(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
glfwSetWindowPos(
window,
(vidmode.width() - pWidth.get(0)) / 2,
(vidmode.height() - pHeight.get(0)) / 2
);
} // the stack frame is popped automatically

// Make the OpenGL context current
glfwMakeContextCurrent(window);
// Enable v-sync
glfwSwapInterval(1);

// Make the window visible
glfwShowWindow(window);

                // 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.
GL.createCapabilities();

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

  • *****
  • 2053
    • 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()
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE);

// ...

// after GL.createCapabilities()
GLUtil.setupDebugMessageCallback();