# OpenGL 3.x context creation in GLFW

## Recommended Posts

In the GLFW spec, it mentions window hints for both GLFW_OPENGL_FORWARD_COMPAT, and GLFW_OPENGL_CORE/COMPAT_PROFILE. What exactly is the difference? The core profile should only work in OpenGL 3.2 or greater, and I THINK shouldn't contain legacy code either (hence the existence of the *COMPAT_PROFILE). If that's the case, then why is GLFW_OPENGL_FORWARD_COMPAT even necessary, considering it's only relevant on contexts > 3.0? Is this just to provide some support for the fuzzy area between OpenGL 3.0 and OpenGL 3.2? Or am I missing something entirely?

Edit: The only thing I can immediately detect different is that setting GLFW_OPENGL_FORWARD_COMPAT to true causes an immediate crash on window creation due to stack corruption =/

##### Share on other sites
[quote name='ChugginWindex' timestamp='1306899279' post='4818143']
Edit: The only thing I can immediately detect different is that setting GLFW_OPENGL_FORWARD_COMPAT to true causes an immediate crash on window creation due to stack corruption =/
[/quote]

Are you sure it's a stack corruption? Playing with these hints as soon as I request a 3.0 context or use the core profile (or forward compat) it seems to crash on the first non-core function because it doesn't exist anymore (ie. the function pointer is 0).

##### Share on other sites
[quote name='Trienco' timestamp='1306902665' post='4818152']
Are you sure it's a stack corruption? Playing with these hints as soon as I request a 3.0 context or use the core profile (or forward compat) it seems to crash on the first non-core function because it doesn't exist anymore (ie. the function pointer is 0).
[/quote]

Yeah, I apply the hints and then try to call glfwOpenWindow(), which uses the hints that I've put in so far, but the function call fails.

This is what Visual Studio 2010 throws up when I call glfwOpenWindow():
[code]
Run-Time Check Failure #2 - Stack around the variable 'attribs' was corrupted.
[/code]

##### Share on other sites
I had this problem before, if I remember correctly, after debugginh into GLFW, it turned out to be a bug in their code, with them only allocating attribs[7], and needing like attribs[15]. After changing that and recompiling GLFW, it worked, but I cant remember if that was the real answer or just some hack I did at one point before finding something wrong in my code. Can you post all your GLFW init calls, and the order theyre called in? I know I also had a problem with accidently calling glfwHint multiple times.

According to Appendix E of the opengl 3.3 core spec, Forward compatable means that you cant use functions that are planned to be removed in later versions of openGL, to make applications compatable with future versions of the spec, and not just the current version. I hope I explained that well

##### Share on other sites
[quote name='zacaj' timestamp='1306957908' post='4818410']
I had this problem before, if I remember correctly, after debugginh into GLFW, it turned out to be a bug in their code, with them only allocating attribs[7], and needing like attribs[15]. After changing that and recompiling GLFW, it worked, but I cant remember if that was the real answer or just some hack I did at one point before finding something wrong in my code. Can you post all your GLFW init calls, and the order theyre called in? I know I also had a problem with accidently calling glfwHint multiple times.

According to Appendix E of the opengl 3.3 core spec, Forward compatable means that you cant use functions that are planned to be removed in later versions of openGL, to make applications compatable with future versions of the spec, and not just the current version. I hope I explained that well
[/quote]

Okay yeah that makes sense. I'm just kinda confused still on what the difference is there between that, and using the OpenGL 3.3 core profile, which should have already removed all the deprecated stuff...

Unless what they're saying is that even in the GL 3.3 core profile, there's stuff that they plan to remove from, say, 4.1? If so they're really churning through features fast!

Edit: Okay I just read up on the appendix E you mentioned in the 3.3 core spec. and I think I understand the difference between the core profile and the forward compatible mode. Looks like forward compatible mode achieved what I THOUGHT the core profile did by itself, but the core profile instead just manipulates some stuff with the ARB extensions to support features on 3.1 contexts instead of just 3.3. I guess the only question left is why GLFW hates it so much when I put it in forward compat mode. I'll post my code in a minute so you can take a look.

Code: This is essentially just a combination of two GLFW 2.7 examples that they distribute with the full source code, but there might be something funky none the less.
[code]#define MAX_NUM_MODES 400

int main() {
GLFWvidmode dtmode, modes[ MAX_NUM_MODES ];
int modecount, i;

// Initialize GLFW
if( !glfwInit() )
{
exit(EXIT_FAILURE);
}

// Show desktop video mode
glfwGetDesktopMode( &dtmode );
printf( "Desktop mode: %d x %d x %d\n\n",
dtmode.Width, dtmode.Height, dtmode.RedBits +
dtmode.GreenBits + dtmode.BlueBits );

// List available video modes
modecount = glfwGetVideoModes( modes, MAX_NUM_MODES );
printf( "Available modes:\n" );
for( i = 0; i < modecount; i ++ )
{
printf( "%3d: %d x %d x %d\n", i,
modes[i].Width, modes[i].Height, modes[i].RedBits +
modes[i].GreenBits + modes[i].BlueBits );
}

glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); //This is what fails for me, setting it to GL_FALSE works just fine

if (GL_TRUE != glfwOpenWindow(800, 600, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
{
fprintf(stderr, "ERROR: Unable to create the OpenGL context and associated window\n");
exit(EXIT_FAILURE);
}

printf("OpenGL Context: %d.%d\n", glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR), glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR));

while(true) {
if(!glfwGetWindowParam(GLFW_OPENED)) {
break;
}

glfwSwapBuffers();
}

// Terminate GLFW
glfwTerminate();

return 0;
}[/code]

[b]Final Edit: [/b]Well, that was dumb... I didn't realize until I said it here that I never considered the possibility that the two GLFW examples I was mixing together weren't BOTH GL 3.3 compliant (at least forward-compatibility-wise). That was the problem. I was mixing an example on how to open a GL 3.3 core profile context with an example on how to get video mode information back from the graphics card, which apparently can't be done in OpenGL 3.3 Core??? I guess this solves it, but it's also got me wondering how they expect anyone to query video format information in the new opengl...

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627661
• Total Posts
2978496
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 12
• 22
• 13
• 33