OpenGL-GLFW Render window not created

Don't know if this is the right place to post this.

Well i have a problem with GLFW, i am trying to make a render window through a class which goes through another class. (You will see what i mean).

I have tried creating the code in one single main function, and it works. But when i split the code up into several functions, it suddently stops working.

Here are the involved classes/files

Main.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
#include "Game.hpp"

int main(int argc, char* argv[])
{
	Game app;

	if(!app.run())
		return -1;
	else
		return 1;
}


Game.hpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#ifndef _GAME_HPP_
#define _GAME_HPP_

#include "EEngine.hpp"

class Game
{
public:
	Game();
	~Game();
	bool run();

private:
	bool running;

	EEngine* engine;

};

#endif 


Game.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "Game.hpp"

Game::Game()
{
	engine = new EEngine();
}

Game::~Game()
{
	if(engine) delete engine;
}

bool Game::run()
{

	if(!engine->graphic->openWindow(800, 600, false, 0, 0, 0))
		return false;

	running = GL_TRUE;
	while(running == GL_TRUE)
	{
		engine->graphic->renderOneFrame();
		running = engine->graphic->isWindowOpen();
	}
	return true;
}


EEngine.hpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef _EENGINE_HPP_
#define _EENGINE_HPP_

#include <string>
#include "LogMgr.hpp"
#include "renderLayer.hpp"

class EEngine
{
public:
	EEngine();
	~EEngine();

	LogMgr* mLog;
	renderLayer* graphic;
	
private:

	EEngine(const EEngine&);
	EEngine& operator= (const EEngine&);
	std::string logName;
};

#endif 


EEngine.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "EEngine.hpp"

EEngine::EEngine()
{
	logName = "log.txt";
	mLog = new LogMgr(logName);
	mLog->logMessage(mLog->NORMAL, "Engine has started");

	graphic = new renderLayer(mLog);
}

EEngine::~EEngine()
{
	if(graphic) delete graphic;
	if(mLog->hasStarted == true) delete mLog;
}


renderLayer.hpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef _RENDER_LAYER_HPP_
#define _RENDER_LAYER_HPP_

#include "OGLAbstr.hpp"
#include "LogMgr.hpp"

class renderLayer
{
public:
	renderLayer(LogMgr* lg);
	~renderLayer();

	bool openWindow(int w = 800, int h = 600, bool fullscreen = false, int colourBits = 32, int depthBits = 0, int stencilBits = 0);
	bool isWindowOpen();
	bool renderOneFrame();

private:
	OGLAbstr* render;
	LogMgr* log;
};

#endif 


renderLayer.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "renderLayer.hpp"

renderLayer::renderLayer(LogMgr* lg)
{
	log = lg;
	log->logMessage(log->NORMAL, "RenderLayer Initialized");

	render = new OGLAbstr(log);
}

renderLayer::~renderLayer()
{
	log->logMessage(log->NORMAL, "Shutting down RenderLayer");
	if(render) delete render;
}

bool renderLayer::openWindow(int w, int h, bool fullscreen, int colourBits, int depthBits, int stencilBits)
{
	if(!render->createWindow(w, h, fullscreen, colourBits, depthBits, stencilBits))
	{
		return false;
	}
	else
		return true;
}

bool renderLayer::isWindowOpen()
{
	return render->isOpen();
}

bool renderLayer::renderOneFrame()
{
	render->renderOneFrame();
	return true;
}


OGLAbstr.hpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#ifndef _OGL_ABSTR_HPP_
#define _OGL_ABSTR_HPP_

#include <Windows.h>
#include <GL\glfw.h>
#include "LogMgr.hpp"
#include <glm\glm.hpp>


using namespace glm;

class OGLAbstr
{
public:
	OGLAbstr(LogMgr* log);
	~OGLAbstr();
	bool renderOneFrame();
	bool createWindow(int w = 800, int h = 600, bool fullscreen = false, int colourBits = 32, int depthBits = 0, int stencilBits = 0);
	bool isOpen();

private:
	LogMgr* mLog;

};

#endif 


OGLAbstr.cpp:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "OGLAbstr.hpp"

OGLAbstr::OGLAbstr(LogMgr* log)
{
	mLog = log;
	if(!glfwInit())
	{
		mLog->logMessage(mLog->CRITICAL, "COULD NOT INITIALIZE GLFW");
	}
	mLog->logMessage(mLog->NORMAL, "Starting up OpenGL-GLFW");
}

OGLAbstr::~OGLAbstr()
{
	glfwTerminate();
	mLog->logMessage(mLog->NORMAL, "Shutting down OpenGL-GLFW");
}

bool OGLAbstr::renderOneFrame()
{
	glfwSwapBuffers();
	return true;
}

bool OGLAbstr::createWindow(int w, int h, bool fullscreen, int colourBits, int depthBits, int stencilBits)
{
	glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.1
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
	glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

	if(!glfwOpenWindow( 800, 600, 0, 0, 0, 0, 32, 0, GLFW_WINDOW))
	{
		mLog->logMessage(mLog->CRITICAL, "COULD NOT CREATE RENDER WINDOW");
		glfwTerminate();
		return false;
	}
	else
	{
		mLog->logMessage(mLog->NORMAL, "Successfully created renderwindow");
		glfwSetWindowTitle("Engine");
		glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
		return true;
	}
}

bool OGLAbstr::isOpen()
{
	if(glfwGetWindowParam(GLFW_OPENED))
		return true;
	else
		return false;
}


If you wonder about the duplicate function, it is just the way i designed things.

The problem occurs at:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
bool OGLAbstr::createWindow(int w, int h, bool fullscreen, int colourBits, int depthBits, int stencilBits)
{
	glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.1
	glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
	glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

	if(!glfwOpenWindow( 800, 600, 0, 0, 0, 0, 32, 0, GLFW_WINDOW)) //<--HERE
	{
		mLog->logMessage(mLog->CRITICAL, "COULD NOT CREATE RENDER WINDOW");
		glfwTerminate();
		return false;
	}
	else
	{
		mLog->logMessage(mLog->NORMAL, "Successfully created renderwindow");
		glfwSetWindowTitle("Engine");
		glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
		return true;
	}
}


The render window is never created, i dont know why though. I designed the program to exit with the code -1 when something goes wrong. And it does.

I also have a log which logs everything. Here is the printout from the log:
##NORMAL## : Log has been created
##NORMAL## : Engine has started
##NORMAL## : RenderLayer Initialized
##NORMAL## : Starting up OpenGL-GLFW
###CRITICAL### : COULD NOT CREATE RENDER WINDOW
##NORMAL## : Shutting down RenderLayer
##NORMAL## : Shutting down OpenGL-GLFW


Also, as a side question. What amount of bits do you usually use in the depth buffer and stencil buffer?

Thanks in advance.
Last edited on
*bump*
closed account (DSLq5Di1)
Does window creation still fail if you comment out the hints for version/profile?
Yes it does, i added those after the problem arose, but they changed nothing.
does your graphics card support GLX_ARB_create_context_profile gl extension?
Reference: http://www.opengl.org/discussion_boards/showthread.php/176821-glfwOpenWindow()-is-failing
I have an XFX Radeon HD6870, so it should. I tried to switch the GLFW_OPENGL_VERSION_MAJOR to 4 and GLFW_OPENGL_VERSION_MINOR to 3, and i get a window. But the window closes right after. The conosle says unable to re-create window :/
Last edited on
Heh my bad, i set the GLFW_OPENGL_VERSION_MAJOR to 3 again and had GLFW_OPENGL_VERSION_MINOR to 3 too, and now it works. Thanks for the help, i was so lost in this. :D
you're welcome, it was the first link on google tho ^^
Well since i have not worked with OpenGL GLFW that much i did not know what to search for. I searched for "GLFW render window not opening" but got no relevant results.
My search was "glfwOpenWindow" and it was the 3rd link, sorry.
Topic archived. No new replies allowed.