OGLplus (0.52.0) a C++ wrapper for OpenGL

standalone/002_triangle_compatibility.cpp

Shows usage of the ARB_compatibility and ARB_debug_output wrappers

002_triangle.png

Copyright 2008-2012 Matus Chochlik. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <cassert>
#include <iostream>
#include <GL/glew.h>
#include <GL/freeglut.h>
#include <oglplus/all.hpp>
class Example
{
private:
public:
Example(GLuint width, GLuint height)
: log_sink(
{
std::cout << "[" << data.id << "] '" <<
data.message << "'" << std::endl;
std::cout << " [source] '" <<
std::endl;
std::cout << " [type] '" <<
oglplus::EnumValueName(data.type) << "'" <<
std::endl;
std::cout << " [severity] '" <<
std::endl;
}
)
{
using namespace oglplus;
dbg.Control(
DebugOutputARBSource::DontCare,
DebugOutputARBType::DontCare,
DebugOutputARBSeverity::Low,
true
);
gl.ClearColor(1.0f, 1.0f, 1.0f, 0.0f);
gl.Viewport(width, height);
glc.MatrixMode(CompatibilityMatrixMode::Projection);
glc.LoadIdentity();
glc.MatrixMode(CompatibilityMatrixMode::Modelview);
glc.LoadIdentity();
}
void Display(void)
{
using namespace oglplus;
gl.Clear().ColorBuffer();
glc.Begin(CompatibilityPrimitiveType::Triangles);
glc.Color(1.0, 0.0, 0.0);
glc.Vertex(0.0f, 0.0f);
glc.Color(0.0, 1.0, 0.0);
glc.Vertex(1.0f, 0.0f);
glc.Color(0.0, 0.0, 1.0);
glc.Vertex(0.0f, 1.0f);
glc.End();
}
};
class SingleExample
{
private:
static Example*& SingleInstance(void)
{
static Example* test = nullptr;
return test;
}
SingleExample(const SingleExample&);
public:
SingleExample(GLuint width, GLuint height)
{
assert(!SingleInstance());
SingleInstance() = new Example(width, height);
}
~SingleExample(void)
{
assert(SingleInstance());
delete SingleInstance();
SingleInstance() = nullptr;
}
static void Display(void)
{
assert(SingleInstance());
SingleInstance()->Display();
glutSwapBuffers();
}
};
int main(int argc, char* argv[])
{
GLuint width = 800, height = 600;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitContextVersion(3, 1);
glutInitContextFlags(GLUT_DEBUG);
glutInitWindowSize(width, height);
glutInitWindowPosition(100,100);
glutCreateWindow("OGLplus+GLUT+GLEW");
if(glewInit() == GLEW_OK) try
{
glGetError();
SingleExample example(width, height);
glutDisplayFunc(&SingleExample::Display);
glutMainLoop();
return 0;
}
catch(oglplus::Error& err)
{
std::cerr
<< "Error (in "
<< err.GLFunc()
<< "'): "
<< err.what()
<< " ["
<< err.SourceFile()
<< ":"
<< err.SourceLine()
<< "] "
<< std::endl;
}
catch(std::exception& se)
{
std::cerr << "Error: " << se.what() << std::endl;
}
return 1;
}

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).