Permalink
Browse files

Base SFML/OpenGL Application class

  • Loading branch information...
1 parent 76896f4 commit a78f142942b38fadd047ef793c6d8a5ae7c3443a @RachelJMorris committed Mar 10, 2013
Showing with 214 additions and 0 deletions.
  1. +71 −0 Application.cpp
  2. +39 −0 Application.h
  3. +15 −0 Camera.h
  4. +52 −0 OglRpg.cbp
  5. +37 −0 main.cpp
View
@@ -0,0 +1,71 @@
+#include "Application.h"
+
+namespace ursa
+{
+
+Application::Application()
+{
+ m_quit = false;
+
+ InitSFML( "OpenGL" );
+ InitOpenGL();
+}
+
+Application::Application( const std::string& title )
+{
+ m_quit = false;
+
+ InitSFML( title );
+ InitOpenGL();
+}
+
+Application::~Application()
+{
+ m_window.Close();
+}
+
+void Application::PrepDraw()
+{
+ m_window.SetActive();
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+}
+
+void Application::FinishDraw()
+{
+ m_window.Display();
+}
+
+void Application::InitSFML( const std::string& title )
+{
+ m_settings.DepthBits = 24;
+ m_settings.StencilBits = 8;
+ m_window.Create(
+ sf::VideoMode( 640, 480, 32 ),
+ title, sf::Style::Close, m_settings
+ );
+ m_window.SetFramerateLimit( 60 );
+}
+
+void Application::InitOpenGL()
+{
+ // Init OpenGL
+ glClearDepth( 1.0f );
+ glClearColor( 0.5f, 0.7f, 0.8f, 1.0f );
+
+ // Z-buffer read/write
+ glEnable( GL_DEPTH_TEST );
+ glDepthMask( GL_TRUE );
+ glAlphaFunc( GL_GREATER, 0.5f );
+ glEnable( GL_ALPHA_TEST );
+
+ // Perspective projection
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ gluPerspective( 90.0f, 1.0f, 1.0f, 1500.0f );
+
+}
+
+}
View
@@ -0,0 +1,39 @@
+#ifndef _APPLICATION
+#define _APPLICATION
+
+#include <SFML/Window.hpp>
+
+#include <string>
+
+namespace ursa
+{
+
+class Application
+{
+ public:
+ Application();
+ Application( const std::string& title );
+ ~Application();
+
+ void PrepDraw();
+ void FinishDraw();
+
+ bool Quit() { return m_quit; }
+ void Quit( bool val ) { m_quit = val; }
+
+ const sf::Input& GetInput() { return m_window.GetInput(); }
+
+ private:
+ void InitSFML( const std::string& title );
+ void InitOpenGL();
+
+ sf::Window m_window;
+ sf::WindowSettings m_settings;
+
+ bool m_quit;
+};
+
+}
+
+#endif
+
View
@@ -0,0 +1,15 @@
+#ifndef _CAMERA
+#define _CAMERA
+
+#include <SFML/System.hpp>
+
+class Camera
+{
+ public:
+
+ private:
+ sf::Vector3f m_position;
+ sf::Vector3f m_rotation;
+};
+
+#endif
View
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="OglRpg" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="Debug">
+ <Option output="bin/Debug/OglRpg" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Debug/" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-g" />
+ </Compiler>
+ </Target>
+ <Target title="Release">
+ <Option output="bin/Release/OglRpg" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Release/" />
+ <Option type="0" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add option="-Wall" />
+ </Compiler>
+ <Linker>
+ <Add library="GL" />
+ <Add library="X11" />
+ <Add library="/usr/lib/libsfml-audio.so" />
+ <Add library="/usr/lib/libsfml-graphics.so" />
+ <Add library="/usr/lib/libsfml-system.so" />
+ <Add library="/usr/lib/libsfml-window.so" />
+ </Linker>
+ <Unit filename="Application.cpp" />
+ <Unit filename="Application.h" />
+ <Unit filename="Appliccation.h" />
+ <Unit filename="Camera.h" />
+ <Unit filename="main.cpp" />
+ <Extensions>
+ <code_completion />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
View
@@ -0,0 +1,37 @@
+#include <iostream>
+
+#include "Application.h"
+#include "Camera.h"
+
+int main()
+{
+ ursa::Application app;
+
+ while ( !app.Quit() )
+ {
+ // Get Events
+ const sf::Input& input = app.GetInput();
+ if ( input.IsKeyDown( sf::Key::Q ) )
+ {
+ app.Quit( true );
+ }
+
+ // Render
+ app.PrepDraw();
+
+ glTranslatef( 0, 0, -100 );
+
+ glBegin( GL_QUADS );
+
+ glVertex3f( 0, 0, 0 );
+ glVertex3f( 100, 0, 0 );
+ glVertex3f( 100, 100, 0 );
+ glVertex3f( 0, 100, 0 );
+
+ glEnd();
+
+ app.FinishDraw();
+ }
+
+ return 0;
+}

0 comments on commit a78f142

Please sign in to comment.