Skip to content
Browse files

Added Geometry class

  • Loading branch information...
1 parent ba0f66a commit 8a7eb7d945088466734b4a33eef5beb25b23508e @RachelJMorris committed
Showing with 87 additions and 9 deletions.
  1. +3 −0 Application.cpp
  2. +39 −0 Geometry.cpp
  3. +23 −0 Geometry.h
  4. +22 −9 main.cpp
View
3 Application.cpp
@@ -52,6 +52,8 @@ void Application::InitSFML( const std::string& title )
void Application::InitOpenGL()
{
// Init OpenGL
+
+ glEnable( GL_TEXTURE_2D );
glClearDepth( 1.0f );
glClearColor( 0.5f, 0.7f, 0.8f, 1.0f );
@@ -66,6 +68,7 @@ void Application::InitOpenGL()
glLoadIdentity();
gluPerspective( 90.0f, 1.0f, 1.0f, 1500.0f );
+ //glShadeModel( GL_FLAT );
}
}
View
39 Geometry.cpp
@@ -0,0 +1,39 @@
+#include "Geometry.h"
+
+namespace ursa
+{
+
+Geometry::Geometry()
+{
+ m_position.x = m_position.y = m_position.z = 0;
+ m_dimensions.x = m_dimensions.y = m_dimensions.z = 0;
+}
+
+void Geometry::Setup( const sf::Vector3f& pos, const sf::Vector3f& dim )
+{
+ m_position = pos;
+ m_dimensions = dim;
+}
+
+void Geometry::Draw( const GLuint& texture )
+{
+ glBegin( GL_QUADS );
+
+ glBindTexture( GL_TEXTURE_2D, texture );
+
+ glTexCoord2f(1.0f, 1.0f);
+ glVertex3f( m_position.x, m_position.y, m_position.z );
+
+ glTexCoord2f(1.0f, 0.0f);
+ glVertex3f( m_position.x, m_position.y + m_dimensions.y, m_position.z );
+
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex3f( m_position.x + m_dimensions.x, m_position.y + m_dimensions.y, m_position.z );
+
+ glTexCoord2f(0.0f, 1.0f);
+ glVertex3f( m_position.x + m_dimensions.x, m_position.y, m_position.z );
+
+ glEnd();
+}
+
+}
View
23 Geometry.h
@@ -0,0 +1,23 @@
+#ifndef _GEOMETRY
+#define _GEOMETRY
+
+#include <SFML/Graphics.hpp>
+
+namespace ursa
+{
+
+class Geometry
+{
+ public:
+ Geometry();
+ void Setup( const sf::Vector3f& pos, const sf::Vector3f& dim );
+ void Draw( const GLuint& texture );
+
+ private:
+ sf::Vector3f m_position;
+ sf::Vector3f m_dimensions;
+};
+
+}
+
+#endif
View
31 main.cpp
@@ -1,8 +1,11 @@
#include <iostream>
+#include <SFML/Graphics.hpp>
+
#include "Application.h"
#include "Camera.h"
#include "Input.h"
+#include "Geometry.h"
using namespace std;
@@ -10,9 +13,26 @@ int main()
{
ursa::Application app;
ursa::Camera camera;
- camera.Setup( sf::Vector3f( 0, 0, -100 ) );
+ camera.Setup( sf::Vector3f( 0, 0, -20 ) );
ursa::Input input;
+ ursa::Geometry box;
+ box.Setup( sf::Vector3f( 0, 0, 0 ), sf::Vector3f( 10, 10, 10 ) );
+
+ sf::Image imgTxt;
+ imgTxt.LoadFromFile( "assets/brick.png" );
+ imgTxt.SetSmooth( false );
+
+ GLuint texture;
+ glGenTextures( 1, &texture );
+ glBindTexture( GL_TEXTURE_2D, texture );
+ glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA,
+ imgTxt.GetWidth(), imgTxt.GetHeight(),
+ 0, GL_RGBA, GL_UNSIGNED_BYTE, imgTxt.GetPixelsPtr() );
+
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+
while ( !app.Quit() )
{
// Get Events
@@ -30,14 +50,7 @@ int main()
glRotatef( camera.RY(), 0.0f, 1.0f, 0.0f );
glRotatef( camera.RZ(), 0.0f, 0.0f, 1.0f );
- glBegin( GL_QUADS );
-
- glVertex3f( 0, 0, 0 );
- glVertex3f( 100, 0, 0 );
- glVertex3f( 100, 100, 0 );
- glVertex3f( 0, 100, 0 );
-
- glEnd();
+ box.Draw( texture );
app.FinishDraw();
}

0 comments on commit 8a7eb7d

Please sign in to comment.
Something went wrong with that request. Please try again.