//-----------------------------------------------------------------------
Console::Console() :
_open(false),
_frameCap(0),
_prevTime(0.0),
_frameTime(0.0),
_major(3),
_minor(0),
_width(800),
_height(600),
_visCursor(false),
_scene(0)
{
// Initialize GLFW
*this << "Initializing...\n";
if(glfwInit())
{
int maj, min, rev;
glfwGetVersion(&maj, &min, &rev);
*this << "GLFW Version " << maj << "." << min << "." << rev << " loaded.\n";
}
else *this << "Unable to load GLFW.\n";
}
............
//-----------------------------------------------------------------------
bool Console::openWindow(const int &width, const int &height, const char *title, bool resizeable)
{
//-----------------------------------------------------------------------
// Already open
if(_open) return false;
// Set properties
glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, _major);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, _minor);
glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, !resizeable);
// Set resolution
_width = width > 0 ? width : _width;
_height = height > 0 ? height : _height;
// Open window and set title
if(!glfwOpenWindow(_width, _height, 0,0,0,0, 32,0, GLFW_WINDOW)) return false;
glfwSetWindowTitle(title);
// Resize
glfwSetWindowSizeCallback(Utils::resize);
//-----------------------------------------------------------------------
// Get OpenGL Version
int major = glfwGetWindowParam(GLFW_OPENGL_VERSION_MAJOR);
int minor = glfwGetWindowParam(GLFW_OPENGL_VERSION_MINOR);
if(major < 3)
{
// Cannot go below 3.0
*this << "OpenGL Version 3.0 is not supported.\n";
closeWindow();
return false;
}
*this << "OpenGL Version " << major << "." << minor << " loaded.\n";
// Initialize GLEW, Normally I check for glewInit() != GLEW_OK
if(glewInit() == GLEW_ERROR_NO_GL_VERSION);
{
*this << "Unable to load GLEW.\n";
//closeWindow(); commented this for testing purposes
//return false;
}
*this << "GLEW Version " << glewGetString(GLEW_VERSION) << " loaded.\n";
//-----------------------------------------------------------------------
// Initialize OpenGL
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// Culling
glEnable(GL_CULL_FACE);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);
// Depth
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.0f, 1.0f);
glClearDepth(1.0);
// Set Open Flag
return _open = true;
}