Permalink
Browse files

Able to set block textures now using the # keys

  • Loading branch information...
1 parent cf3bfa8 commit 213d5e0df5384fe53af424c1d98ccc5b15fa95e6 @RachelJMorris committed Mar 16, 2013
View
@@ -6,12 +6,9 @@ using namespace std;
namespace ursa
{
-Geometry::Geometry()
-{
-}
-
Geometry::Geometry( const sf::Vector3f& pos, const sf::Vector3f& dim, const sf::Vector3i& index )
{
+ m_texture = NULL;
Setup( pos, dim, index );
}
@@ -31,9 +28,14 @@ void Geometry::Setup( const sf::Vector3f& pos, const sf::Vector3f& dim, const sf
m_lstPoints.push_back( sf::Vector3f( pos.x, pos.y + dim.y, pos.z + dim.z ) );
}
-void Geometry::Draw( const GLuint& texture )
+void Geometry::SetTexture( GLuint& texture )
+{
+ m_texture = &texture;
+}
+
+void Geometry::Draw()
{
- glBindTexture( GL_TEXTURE_2D, texture );
+ glBindTexture( GL_TEXTURE_2D, *m_texture );
glEnable( GL_TEXTURE_2D );
glBegin( GL_QUADS );
@@ -48,7 +50,7 @@ void Geometry::Draw( const GLuint& texture )
DrawLines();
}
-void Geometry::CheckCursor( const sf::Vector3f& cursor )
+bool Geometry::CheckCursor( const sf::Vector3f& cursor )
{
if ( (int)(cursor.x) == m_index.x &&
(int)(cursor.y) == m_index.y &&
@@ -60,6 +62,7 @@ void Geometry::CheckCursor( const sf::Vector3f& cursor )
{
m_cursorOn = false;
}
+ return m_cursorOn;
}
void Geometry::DrawXY()
View
@@ -13,16 +13,17 @@ namespace ursa
class Geometry
{
public:
- Geometry();
Geometry( const sf::Vector3f& pos, const sf::Vector3f& dim, const sf::Vector3i& );
void Setup( const sf::Vector3f& pos, const sf::Vector3f& dim, const sf::Vector3i& );
- void Draw( const GLuint& texture );
- void CheckCursor( const sf::Vector3f& cursor );
+ void Draw();
+ bool CheckCursor( const sf::Vector3f& cursor );
+ void SetTexture( GLuint& texture );
private:
std::vector<sf::Vector3f> m_lstPoints;
sf::Vector3i m_index;
bool m_cursorOn;
+ GLuint* m_texture;
void DrawXY();
void DrawXZ();
View
@@ -6,7 +6,7 @@ using namespace std;
namespace ursa
{
-void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBlocks, sf::Vector3f& cursor )
+void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBoxes, sf::Vector3f& cursor, int activeBox, GLuint lstTextures[5] )
{
sf::Event event;
@@ -16,7 +16,28 @@ void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>
HandleAppControls( input, app );
HandleCameraControls( input, app, camera );
- HandleMouseControls( input, app, lstBlocks );
+ HandleMouseControls( input, app, lstBoxes );
+
+ if ( input.IsKeyDown( sf::Key::Num0 ) )
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[0] );
+ }
+ else if ( input.IsKeyDown( sf::Key::Num1 ) )
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[1] );
+ }
+ else if ( input.IsKeyDown( sf::Key::Num2 ) )
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[2] );
+ }
+ else if ( input.IsKeyDown( sf::Key::Num3 ) )
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[3] );
+ }
+ else if ( input.IsKeyDown( sf::Key::Num4 ) )
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[4] );
+ }
if ( input.IsKeyDown( sf::Key::Numpad8 ) )
{
View
@@ -15,7 +15,9 @@ namespace ursa
class Input
{
public:
- void HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBlocks, sf::Vector3f& cursor );
+ void HandleInput( Application& app, Camera& camera,
+ std::vector<Geometry>& lstBlocks, sf::Vector3f& cursor,
+ int activeBox, GLuint lstTextures[5] );
private:
void HandleCameraControls( const sf::Input& input, Application& app, Camera& camera );
View
@@ -41,8 +41,12 @@
</Linker>
<Unit filename="Application.cpp" />
<Unit filename="Application.h" />
- <Unit filename="Appliccation.h" />
+ <Unit filename="Camera.cpp" />
<Unit filename="Camera.h" />
+ <Unit filename="Geometry.cpp" />
+ <Unit filename="Geometry.h" />
+ <Unit filename="Input.cpp" />
+ <Unit filename="Input.h" />
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -11,7 +11,8 @@
using namespace std;
-//void LoadTextures( std::vector<ursa::Texture>& lstTextures );
+void LoadTextures( GLuint* lstTextures );
+void LoadTexture( const std::string& filename, GLuint& texture );
int main()
{
@@ -20,17 +21,15 @@ int main()
camera.Setup( sf::Vector3f( -50, 30, -115 ), sf::Vector3f( 52, 0, 0 ) );
ursa::Input input;
- GLuint lstIntTextures[2];
- glGenTextures( 2, lstIntTextures );
-
- std::vector<ursa::Texture> lstTextures;
- lstTextures.push_back( ursa::Texture( "assets/wood.png", lstIntTextures[0] ) );
- lstTextures.push_back( ursa::Texture( "assets/brick.png", lstIntTextures[1] ) );
+ GLuint lstTextures[5];
+ glGenTextures( 5, lstTextures );
+ LoadTextures( lstTextures );
const int mapWidth = 10;
const int mapDepth = 10;
vector<ursa::Geometry> lstBoxes;
+ int activeBox = 0;
for ( int z = 0; z < mapDepth; z++ )
{
for ( int x = 0; x < mapWidth; x++ )
@@ -40,12 +39,17 @@ int main()
}
}
+ for ( int i = 0; i < lstBoxes.size(); i++ )
+ {
+ lstBoxes[i].SetTexture( lstTextures[0] );
+ }
+
sf::Vector3f cursor(0, 0, 0);
while ( !app.Quit() )
{
// Get Events
- input.HandleInput( app, camera, lstBoxes, cursor );
+ input.HandleInput( app, camera, lstBoxes, cursor, activeBox, lstTextures );
if ( cursor.x >= mapWidth )
{
cursor.x = 0;
@@ -63,11 +67,12 @@ int main()
cursor.z = mapDepth - 1;
}
-
-
for ( int i = 0; i < lstBoxes.size(); i++ )
{
- lstBoxes[i].CheckCursor( cursor );
+ if ( lstBoxes[i].CheckCursor( cursor ) )
+ {
+ activeBox = i;
+ }
}
// Render
@@ -76,7 +81,7 @@ int main()
for ( int i = 0; i < lstBoxes.size(); i++ )
{
- lstBoxes[i].Draw( *lstTextures[i%2].m_texture );
+ lstBoxes[i].Draw();
}
app.FinishDraw();
@@ -85,25 +90,27 @@ int main()
return 0;
}
-//void LoadTextures( std::vector<ursa::Texture>& lstTextures )
-//{
-// ursa::Texture txtGrass;
-// txtGrass.Load( "assets/grass.png" );
-// lstTextures.push_back( txtGrass );
-//
-// ursa::Texture txtBrick;
-// txtBrick.Load( "assets/brick.png" );
-// lstTextures.push_back( txtBrick );
-//
-// ursa::Texture txtWood;
-// txtWood.Load( "assets/wood.png" );
-// lstTextures.push_back( txtWood );
-//
-// ursa::Texture txtSand;
-// txtSand.Load( "assets/sand.png" );
-// lstTextures.push_back( txtSand );
-//
-// ursa::Texture txtWater;
-// txtWater.Load( "assets/water.png" );
-// lstTextures.push_back( txtWater );
-//}
+void LoadTextures( GLuint* lstTextures )
+{
+ LoadTexture( "assets/wood.png", lstTextures[0] );
+ LoadTexture( "assets/brick.png", lstTextures[1] );
+ LoadTexture( "assets/grass.png", lstTextures[2] );
+ LoadTexture( "assets/water.png", lstTextures[3] );
+ LoadTexture( "assets/sand.png", lstTextures[4] );
+}
+
+void LoadTexture( const std::string& filename, GLuint& texture )
+{
+ sf::Image image;
+ image.LoadFromFile( filename );
+
+ glBindTexture( GL_TEXTURE_2D, texture );
+
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_MODULATE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image.GetWidth(), image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.GetPixelsPtr());
+}

0 comments on commit 213d5e0

Please sign in to comment.