Today I will try to use GLFW library.
GLFW is a C library that lets you using an OpenGL context and window, display modes and inputs like keyboard, mouse, joystick and time.
GLFW supports Windows, Mac OS X and Unix, Linux and FreeBSD and any operating systems with the X Window System.
Also you can read more about this library here.
First install the library using root account.
# yum install libglfw-devel.i386
Now let’s see the source code.
First I includes all librarys I need.
/*
* File: main.cpp
* Author: free-tutorials.org
*
* Created on May 15, 2013, 2:54 PM
*/
#include
// my c++ include headers
#include
#include
#include
#include
#include
using namespace std;
In the main function I start to see if the library is working.
int main() {
if( !glfwInit() )
{
fprintf( stderr, "Failed to initialize GLFW Init \n" );
return -1;
}
The next step is to set some settings, see:
// 4x antialiasing because I use NVIDIA FX5500
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
… and also testing the desktop settings.
// get infos about desktop
GLFWvidmode desktop;
glfwGetDesktopMode( &desktop );
The settings it’s show on console with cout function.
// show infos about your desktop
cout << "Width : " << desktop.Width << "\n";
cout << "Height : " << desktop.Height << "\n";
cout << "RedBits : " << desktop.RedBits << "\n";
cout << "GreenBits : " << desktop.GreenBits << "\n";
cout << "BlueBits : " << desktop.BlueBits << "\n";
Now I make the window context using fullscreen option.
if ( !glfwOpenWindow(
desktop.Width,
desktop.Height,
desktop.RedBits,
desktop.GreenBits,
desktop.BlueBits,
32, // alpha bits
32, // depth bits
0, // stencil bits
GLFW_FULLSCREEN
) ) {
// error if failed
}
I set the title of the window.
glfwSetWindowTitle( "opengl-shader test" );
I enable the keys.
glfwEnable( GLFW_STICKY_KEYS );
do{
// draw something sexy
// Swap buffers need it
glfwSwapBuffers();
}
The next source code it’s close the window.
// When ESC key was pressed or the window was closed
while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
glfwGetWindowParam( GLFW_OPENED ) );
}
Testing with time command to see how fast working.
$ time ./opengl-shader
Width : 1280
Height : 1024
RedBits : 8
GreenBits : 8
BlueBits : 8
real 0m2.358s
user 0m0.341s
sys 0m1.240s
The netbeans IDE make the package in this path.
$cd /opengl-shader/dist/Debug/GNU-Linux-x86/package
I make RPM package for Fedora distro.
# rpm -ivh opengl-shader-1.0-1.i386.rpm
Preparing... ########################################### [100%]
1:opengl-shader ########################################### [100%]
I test my example and working well.


