Skip to content

Instantly share code, notes, and snippets.

@ph4un00b
Last active December 22, 2015 08:38
Show Gist options
  • Save ph4un00b/6445843 to your computer and use it in GitHub Desktop.
Save ph4un00b/6445843 to your computer and use it in GitHub Desktop.
openGL / mac / 2.1 / glfw
// include standard stuff
#include <stdio.h>
#include <stdlib.h>
// include GLEW always before gl.h && glfw.h
#include <GL/glew.h>
// windows && keyboard
#include <GL/glfw.h>
// 3d math library
#include <glm/glm.hpp>
using namespace glm;
class Start
{
public:
// Start();
int windowAndKeyboard();
int setAntialiasing(int);
int setOpenGLVersion(int, int);
int createContext();
int initGlew();
int setWindowTitle(const char *);
// ~Start();
/* data */
};
int Start::windowAndKeyboard()
{
// init window && keyboard
if (! glfwInit())
{
fprintf(stderr, "fallo el initd\n");
return -1;
}
return 0;
}
int Start::setAntialiasing(int times)
{
// 4X antialiasing
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, times);
return 0;
}
int Start::setOpenGLVersion(int major, int minor)
{
// opengl 2.1
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, major);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, minor);
// fuck old opengl but MAC needs this sh!t!?!?
//glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
return 0;
}
int Start::createContext()
{
//open window && create context "width, heigth, r, g, b, a, depth, stencil, mode"
if (! glfwOpenWindow(600, 800, 0, 0, 0, 0, 64, 0, GLFW_WINDOW))
{
fprintf(stderr, "FAIL to open thw windows and create the ctx\n");
glfwTerminate();
return -1;
}
return 0;
}
int Start::initGlew()
{
// this is for core profile
glewExperimental = true;
if (glewInit() != GLEW_OK)
{
fprintf(stderr, "fail to init glew! \n");
return -1;
}
return 0;
}
int Start::setWindowTitle(const char * title)
{
glfwSetWindowTitle(title);
// enale keyboard
glfwEnable(GLFW_STICKY_KEYS);
return 0;
}
int main()
{
Start start;
start.windowAndKeyboard();
start.setAntialiasing(4);
start.setOpenGLVersion(2, 1);
start.createContext();
start.initGlew();
start.setWindowTitle("the fuck!ng window");
do {
// swap buffers
glfwSwapBuffers();
//check for "ESC" key || windows close
} while (glfwGetKey(GLFW_KEY_ESC) != GLFW_PRESS && glfwGetWindowParam(GLFW_OPENED));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment