Skip to content
Overv edited this page Oct 3, 2012 · 4 revisions
#include <GL/OOGL.hpp>

int main()
{
	GL::Window window( 800, 600, "OpenGL Window", GL::WindowStyle::Close );
	GL::Context& gl = window.GetContext();

	GL::Shader vert( GL::ShaderType::Vertex, GLSL(
		in vec2 position;
		uniform mat4 trans;
		void main() {
			gl_Position = trans * vec4( position, 0.0, 1.0 );
		}
	) );
	GL::Shader frag( GL::ShaderType::Fragment, GLSL(
		out vec4 outColor;
		void main()
		{
			outColor = vec4( 1.0, 0.0, 0.0, 1.0 );
		}
	) );
	GL::Program program( vert, frag );

	float vertices[] = {
		-0.5f,  0.5f,
		0.5f,  0.5f,
		0.5f, -0.5f,
		-0.5f, -0.5f
	};
	GL::VertexBuffer vbo( vertices, sizeof( vertices ), GL::BufferUsage::StaticDraw );

	short indices[] = {
		0, 1, 2,
		2, 3, 0
	};
	GL::VertexBuffer ebo( indices, sizeof( indices ), GL::BufferUsage::StaticDraw );

	GL::VertexArray vao;
	vao.BindAttribute( program.GetAttribute( "position" ), vbo, GL::Type::Float, 2, 0, 0 );
	vao.BindElements( ebo );

	GL::Event ev;
	while ( window.IsOpen() )
	{
		while ( window.GetEvent( ev ) );

		GL::Mat4 model;
		model.RotateZ( gl.Time() );
		GL::Mat4 view = GL::Mat4::LookAt( GL::Vec3( 1, 1, 1 ), GL::Vec3( 0, 0, 0 ), GL::Vec3( 0, 0, 1 ) );
		GL::Mat4 proj = GL::Mat4::Perspective( GL::Rad( 60 ), 800.0f / 600.0f, 0.1f, 10.0f );

		program.SetUniform( program.GetUniform( "trans" ), proj * view * model );

		gl.Clear();

		gl.DrawElements( vao, GL::Primitive::Triangles, 0, 6, GL::Type::UnsignedShort );

		window.Present();
	}

	return 0;
}
![lol](http://i.imgur.com/DRMIe.png)