Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, 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
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
175 Geometry.cpp
@@ -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 );
+}
+
+}
View
28 Geometry.h
@@ -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
View
39 main.cpp
@@ -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.