Getting into OpenGL 3.2 +

bastiaanolij wrote on Saturday, November 15, 2014:

Hi all,

Sorry if this has been dealt with before but I couldn’t find any helpful info on it. I’ve been tinkering away at a little hobby project of mine. I’m developing on a Macbook Pro, now have the latest Xcode installed (though I’m oldskool compiling all through command line) and running 10.10.

I have a working setup with GLFW and its all happy and honky dori but I’ve reached a point where I start needing functionality that requires OpenGL 3.2. These are my first steps however and I’m getting stuck and I hope someone can help me out of my misery:)

I’ve added the following lines before calling glfwCreateWindow:

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

That bit seems to work, but a little further down the line I start setting up an offscreen frame buffer (I use a deferred lighting approach) and the program crashes as soon as it reaches this, though I’m not getting enough info back to know exactly on what. I’m guessing I’m calling functions no longer supported in OpenGL 3 that require a different approach.

The code where I think things are crashing is:

GLint	internalFormats[] = { GL_RGB32F_ARB, GL_RGBA, GL_RGB, GL_RED};
GLenum	format[] = { GL_RGB, GL_RGBA, GL_RGB, GL_RED };

// create our frame buffer
glGenFramebuffers(1, &mFBO);

// create our texture objects
glGenTextures(GBUFFER_NUM_TEXTURES, mTextures);
glGenTextures(1, &mDepthTexture);

// bind our frame buffer
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);

// init our textures
for (int i = 0; i < GBUFFER_NUM_TEXTURES; i++) {
  glBindTexture(GL_TEXTURE_2D, mTextures[i]);
  glTexImage2D(GL_TEXTURE_2D, 0, internalFormats[i], mWidth, mHeight, 0, format[i], GL_FLOAT, NULL); 
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i, GL_TEXTURE_2D, mTextures[i], 0);
};

// init our depth buffer
glBindTexture(GL_TEXTURE_2D, mDepthTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32F, mWidth, mHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, mDepthTexture, 0);

// and finalize our frame buffer
GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
glDrawBuffers(4, drawBuffers);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if (status != GL_FRAMEBUFFER_COMPLETE) {
  gLog->addLine("Couldn't init framebuffer (errno = %i)\r\n", status);
  lvSuccess = false;
} else {
  gLog->addLine("Created gbuffer %i, %i", mWidth, mHeight);
};

// unbind our frame buffer and texture
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

return lvSuccess;

Thanks,

Bastiaan Olij

bastiaanolij wrote on Friday, November 21, 2014:

I’m using GLEW, turns out all it needed was an extra switch…
glewExperimental=true;