Shows the basic usage of OGLplus with GLUT and GLEW.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/glut.h>
class Example
{
private:
public:
Example(void)
{
using namespace oglplus;
vs.Source(" \
#version 330\n \
void main(void) { } \
");
vs.Compile();
gs.Source(" \
#version 330\n \
layout (points) in; \
layout (triangle_strip, max_vertices=4) out;\
out vec3 geomColor; \
void main(void) \
{ \
gl_Position = vec4(-1.0,-1.0, 0.0, 1.0); \
geomColor = vec3(0.0, 0.0, 0.0); \
EmitVertex(); \
gl_Position = vec4(-1.0, 1.0, 0.0, 1.0); \
geomColor = vec3(1.0, 0.0, 0.0); \
EmitVertex(); \
gl_Position = vec4( 1.0,-1.0, 0.0, 1.0); \
geomColor = vec3(0.0, 1.0, 0.0); \
EmitVertex(); \
gl_Position = vec4( 1.0, 1.0, 0.0, 1.0); \
geomColor = vec3(0.0, 0.0, 1.0); \
EmitVertex(); \
EndPrimitive(); \
} \
");
gs.Compile();
fs.Source(" \
#version 330\n \
in vec3 geomColor; \
out vec3 fragColor; \
void main(void) \
{ \
fragColor = geomColor; \
} \
");
fs.Compile();
}
void Display(void)
{
using namespace oglplus;
}
};
class SingleExample
{
private:
static Example*& SingleInstance(
void)
{
return test;
}
SingleExample(const SingleExample&);
public:
SingleExample(void)
{
assert(!SingleInstance());
}
~SingleExample(void)
{
assert(SingleInstance());
delete SingleInstance();
SingleInstance() = nullptr;
}
static void Display(void)
{
assert(SingleInstance());
SingleInstance()->Display();
glutSwapBuffers();
}
};
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(800, 600);
glutInitWindowPosition(100,100);
glutCreateWindow("OGLplus+GLUT+GLEW");
if(glewInit() == GLEW_OK) try
{
glGetError();
SingleExample example;
glutDisplayFunc(&SingleExample::Display);
glutMainLoop();
return 0;
}
{
std::cerr <<
"Error (in " << pbe.
GLSymbol() <<
", " <<
pbe.what() << ": " <<
std::endl;
}
{
std::cerr <<
"Error (in " << err.
GLSymbol() <<
", " <<
err.what() <<
" [" << err.
File() <<
":" << err.
Line() <<
"] ";
std::cerr << std::endl;
err.Cleanup();
}
return 1;
}