Jump to content
  • Advertisement
Sign in to follow this  
ranmer

GLFW OpenWindow problem

This topic is 2492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to learn core OpenGL using this tutorial, but I'm porting to GLFW as I go since GLUT/FreeGLUT is supposedly no good for commercial level products, and I want to hit the ground running learning something better. It worked fine when I wasn't using shaders and just cleared the screen. When I added shaders, it crashed with an access violation when I called glCreateShader(). So, I added calls to glfwOpenWindowHint to specify version 3.3 and the core profile. There's no longer an access violation, but now glfwOpenWindow returns false and the program exits. My GPU is a Radeon HD 2400 XT, which I thought was supposed to support GL 3.3, but maybe not? I'm using Win 7 64 bit, compiling with VS 2010 Express, and using driver version 8.632.1.2000. Target is Win32 Console app. Here's the cpp file as it stands now:

#include "TestGLFW_C.h"
GLuint CreateShader (GLenum eShaderType, const std::string &strShaderFile) {
GLuint shader = glCreateShader(eShaderType);
const char *strFileData = strShaderFile.c_str();
glShaderSource(shader, 1, &strFileData, NULL);
glCompileShader(shader);
GLint status;
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (GL_FALSE == status) {
GLint infoLogLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar *strInfoLog = new GLchar[infoLogLength+1];
glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);
const char *strShaderType = NULL;
switch(eShaderType) {
case GL_VERTEX_SHADER: strShaderType = "vertex"; break;
case GL_GEOMETRY_SHADER: strShaderType = "geometry"; break;
case GL_FRAGMENT_SHADER: strShaderType = "fragment"; break;
}
fprintf (stderr, "Compile failure in %s shader:\n%s\n", strShaderType, strInfoLog);
delete []strInfoLog;
}
return shader;
}
GLuint CreateProgram (const std::vector<GLuint> &shaderList) {
GLuint program = glCreateProgram();
for (size_t iLoop = 0; iLoop < shaderList.size(); iLoop++) {
glAttachShader(program, shaderList[iLoop]);
}
glLinkProgram(program);
GLint status;
glGetProgramiv (program, GL_LINK_STATUS, &status);
if (GL_FALSE == status) {
GLint infoLogLength;
glGetProgramiv (program, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar *strInfoLog = new GLchar[infoLogLength+1];
glGetProgramInfoLog(program, infoLogLength, NULL, strInfoLog);
fprintf (stderr, "Linker failure: %s\n", strInfoLog);
delete []strInfoLog;
}
for (size_t iLoop = 0; iLoop < shaderList.size(); iLoop++) {
glDetachShader(program, shaderList[iLoop]);
}
return program;
}
GLuint theProgram;
const std::string strVertexShader (
"#version 330\n"
"layout(location = 0) in vec4 position;\n"
"void main()\n"
"{\n"
" gl_Position = position;\n"
"}\n"
);
const std::string strFragmentShader (
"#version 330\n"
"out vec4 outputColor;\n"
"void main()\n"
"{\n"
" outputColor = vec4(1.0f, 1.0f, 1.0f, 1.0f);\n"
"}\n"
);
void InitializeProgram() {
std::vector<GLuint> shaderList;
shaderList.push_back(CreateShader(GL_VERTEX_SHADER, strVertexShader));
shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, strFragmentShader));
theProgram = CreateProgram(shaderList);
std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
}
const float vertexPositions[] = {
0.75f, 0.75f, 0.0f, 1.0f,
0.75f, -0.75f, 0.0f, 1.0f,
-0.75f, -0.75f, 0.0f, 1.0f
};
GLuint positionBufferObject;
GLuint vao;
void InitializeVertexBuffer() {
glGenBuffers(1, &positionBufferObject);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositions), vertexPositions, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
}
void init() {
InitializeProgram();
InitializeVertexBuffer();
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
}
void render(void) {
glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT);
glUseProgram(theProgram);
glBindBuffer(GL_ARRAY_BUFFER, positionBufferObject);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
glDrawArrays(GL_TRIANGLES, 0, 3);
glDisableVertexAttribArray(0);
glUseProgram(0);
glfwSwapBuffers();
}
void GLFWCALL reshape (int w, int h) {
glViewport (0, 0, (GLsizei)w, (GLsizei)h);
}
void keyboard (unsigned char key, int x, int y) {
switch (key) {
case 27:
//glutLeaveMainLoop();
return;
}
}
int main(void)
{
int running = GL_TRUE;
if (!glfwInit()) {
exit (EXIT_FAILURE);
}

glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) {
glfwTerminate();
exit (EXIT_FAILURE);
}
//init();
GLuint testShader = glCreateShader(GL_VERTEX_SHADER);
glfwSetWindowSizeCallback(reshape);
while (running) {
glClear (GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
}
glfwTerminate();
exit (EXIT_SUCCESS);
}


and the header:

#include <gl/glew.h>
#include <gl/glfw.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <vector>


Anyone know what's going on?

Share this post


Link to post
Share on other sites
Advertisement
I figured it out, sort-of. I'm still a little hazy on the details, and I need to do some more reading and testing, but for the sake of other beginners, here's what I did:

It turns out my card only supports OpenGL 2.0, but if I remove the calls to glfwOpenWindowHint() and also use the GLEW library (call glewInit() immediately after opening the glfw window) I can then create and use shaders, but only up to shader language version 1.30. I think that's the max supported by GL 2.0, so I had to tweak the code in the examples to work with my older hardware.

The weird part is, I have another dev. machine, actually my home computer, that I've written pretty much the same program on. It also has an OpenGL 2.0 only card, but the behaviour is slightly different. I can leave the calls to glfwOpenWindowHint that specify the major and minor version of OpenGL, and it will still run fine on that machine. I still can't specify the core profile or forward compatibility though. The only thing I can think that would be significantly different is that on one machine, I've used a precompiled binary distribution of glfw, while on the other, I compiled it myself (the version that came with the tutorial source code). They're the same version, but maybe the code that came with the tutorial is tweaked somehow? Or maybe this is a subtle difference in the way the drivers interact with it? They're both Win 7 64bit machines using Radeon drivers, but maybe they're different versions of the driver.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!