Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: Rejcx/Ursa
base: ba0f66a19e
...
head fork: Rejcx/Ursa
compare: 13fc8164eb
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Showing with 236 additions and 9 deletions.
  1. +3 −0  Application.cpp
  2. +175 −0 Geometry.cpp
  3. +28 −0 Geometry.h
  4. +30 −9 main.cpp
3  Application.cpp
View
@@ -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 );
}
}
175 Geometry.cpp
View
@@ -0,0 +1,175 @@
+#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;
+}
+
+Geometry::Geometry( const sf::Vector3f& pos, const sf::Vector3f& dim )
+{
+ Setup( pos, dim );
+}
+
+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 );
+
+ DrawXY();
+ DrawXZ();
+ DrawYZ();
+
+ glEnd();
+}
+
+void Geometry::DrawXY()
+{
+ glColor3f( 1.0f, 1.0f, 1.0f );
+
+ 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 );
+
+
+ glTexCoord2f(1.0f, 1.0f);
+ glVertex3f( m_position.x,
+ m_position.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(1.0f, 0.0f);
+ glVertex3f( m_position.x,
+ m_position.y + m_dimensions.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y + m_dimensions.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(0.0f, 1.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y,
+ m_position.z + m_dimensions.z );
+}
+
+void Geometry::DrawXZ()
+{
+ glColor3f( 0.6f, 0.6f, 0.6f );
+
+ glTexCoord2f(0.0f, 1.0f);
+ glVertex3f( m_position.x,
+ m_position.y,
+ m_position.z );
+
+ glTexCoord2f(1.0f, 1.0f);
+ glVertex3f( m_position.x,
+ m_position.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(1.0f, 0.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y,
+ m_position.z );
+
+
+ glTexCoord2f(1.0f, 1.0f);
+ glVertex3f( m_position.x,
+ m_position.y + m_dimensions.y,
+ m_position.z );
+
+ glTexCoord2f(1.0f, 0.0f);
+ glVertex3f( m_position.x,
+ m_position.y + m_dimensions.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y + m_dimensions.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(0.0f, 1.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y + m_dimensions.y,
+ m_position.z );
+
+}
+
+void Geometry::DrawYZ()
+{
+ glColor3f( 0.4f, 0.4f, 0.4f );
+
+ glTexCoord2f(0.0f, 1.0f);
+ glVertex3f( m_position.x,
+ m_position.y,
+ m_position.z );
+
+ glTexCoord2f(1.0f, 1.0f);
+ glVertex3f( m_position.x,
+ m_position.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(1.0f, 0.0f);
+ glVertex3f( m_position.x,
+ m_position.y + m_dimensions.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex3f( m_position.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 );
+
+ glTexCoord2f(1.0f, 1.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(1.0f, 0.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y + m_dimensions.y,
+ m_position.z + m_dimensions.z );
+
+ glTexCoord2f(0.0f, 0.0f);
+ glVertex3f( m_position.x + m_dimensions.x,
+ m_position.y + m_dimensions.y,
+ m_position.z );
+}
+
+}
28 Geometry.h
View
@@ -0,0 +1,28 @@
+#ifndef _GEOMETRY
+#define _GEOMETRY
+
+#include <SFML/Graphics.hpp>
+
+namespace ursa
+{
+
+class Geometry
+{
+ public:
+ Geometry();
+ Geometry( const sf::Vector3f& pos, const sf::Vector3f& dim );
+ void Setup( const sf::Vector3f& pos, const sf::Vector3f& dim );
+ void Draw( const GLuint& texture );
+
+ private:
+ sf::Vector3f m_position;
+ sf::Vector3f m_dimensions;
+
+ void DrawXY();
+ void DrawXZ();
+ void DrawYZ();
+};
+
+}
+
+#endif
39 main.cpp
View
@@ -1,8 +1,12 @@
#include <iostream>
+#include <vector>
+
+#include <SFML/Graphics.hpp>
#include "Application.h"
#include "Camera.h"
#include "Input.h"
+#include "Geometry.h"
using namespace std;
@@ -10,9 +14,30 @@ int main()
{
ursa::Application app;
ursa::Camera camera;
- camera.Setup( sf::Vector3f( 0, 0, -100 ) );
+ camera.Setup( sf::Vector3f( 0, 0, -50 ) );
ursa::Input input;
+ vector<ursa::Geometry> lstBoxes;
+ lstBoxes.push_back( ursa::Geometry( sf::Vector3f( 0, 0, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
+ lstBoxes.push_back( ursa::Geometry( sf::Vector3f( 10, 0, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
+ lstBoxes.push_back( ursa::Geometry( sf::Vector3f( 10, 10, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
+ lstBoxes.push_back( ursa::Geometry( sf::Vector3f( 0, 10, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
+ lstBoxes.push_back( ursa::Geometry( sf::Vector3f( -10, -10, 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 +55,10 @@ 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();
+ for ( int i = 0; i < lstBoxes.size(); i++ )
+ {
+ lstBoxes[i].Draw( texture );
+ }
app.FinishDraw();
}

No commit comments for this range

Something went wrong with that request. Please try again.