Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - KungFu97

Pages: [1]
1
Graphics / Re: Tile won't texture SFML 2.0
« on: October 28, 2012, 12:46:35 am »
I'll try that out, thanks!

2
Graphics / Re: Tile won't texture SFML 2.0
« on: October 27, 2012, 09:22:55 pm »
Yeah so apparently it can't find the file. I'm starting to think either I'm doing something slightly wrong or it's my laptop. I tried it on Visual C# 2010 by copying and pasting a random tile engine tutorial, yet I still can't manage to get the texture on that either. Is there something I have to specifically do except for writing that find file code to get it to work?

3
Graphics / Re: Tile won't texture SFML 2.0
« on: October 27, 2012, 06:53:47 pm »
Could you post an example? It keeps giving me errors.

4
Graphics / Re: Tile won't texture SFML 2.0
« on: October 27, 2012, 06:36:19 pm »
Main.cpp

#include <Windows.h>
#include "Engine.h"

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
        Engine* engine = new Engine();

        try
        {
                engine->Go();
        }
        catch(char* e)
        {
                MessageBoxA(NULL, e, "Exception Occured", MB_OK | MB_ICONERROR);
        }
}

5
Graphics / Re: Tile won't texture SFML 2.0
« on: October 27, 2012, 06:35:21 pm »
Engine.cpp and Engine.h

#include "Engine.h"
#include <SFML\Graphics.hpp>
#include "TextureManager.h"

Engine::Engine()
{

}

Engine::~Engine()
{
        {
delete window;
//this is so that the 'window = new sf::RenderWindow' is removed from memory when the engine stops)
delete textureManager;
//this is so that the texturemanager is also deleted once the engine is stopped
}

}

bool Engine::Init()
{
        // Setting up the window
        window = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "Vanity Engine V0.1");
        textureManager = new TextureManager();
        // If the window is already open, don't make a new one
        if(!window)
                return false;
       
        LoadTextures();
        return true;
}
void Engine::LoadTextures()
{
        sf::Texture texture;
        // Load tile textue
        texture.loadFromFile("grassTile.png");
        // Add the image to imageManager
        textureManager->AddTexture(texture);
        // Initialize grassTile as a new tile and set it's texture
        grassTile = new Tile(textureManager->GetTexture(0));
}

void Engine::RenderFrame()
{
        // Clear the window
        window->clear();
        // Draw the tile to X = 0, Y = 0 on the render window
        grassTile->Draw(0,0, window);
        // Render window displays the tile
        window->display();

}

void Engine::ProcessInput()
{
        // Initiate an event
        sf::Event evt;

        // Loop through all the window events
        while(window->pollEvent(evt))
        {
                // If the user closes the program the window closes
                if(evt.type == sf::Event::Closed)
                        window->close();
        }
}

void Engine::Update()
{

}

void Engine::MainLoop()
{
        //Loop until the window is closed
        while(window->isOpen())
        {
                ProcessInput();
                Update();
                RenderFrame();
        }
}

void Engine::Go()
{
        if(!Init())
                throw "Could not intialize Engine";

        MainLoop();
}

#ifndef _ENGINE_H
#define _ENGINE_H

#include <SFML\Graphics.hpp>
#include "TextureManager.h"
#include "Tile.h"

class Engine
{
private:
        // The window where everything is rendered
        sf::RenderWindow* window;
        // Adding instance of ImageManager
        TextureManager* textureManager;
        // Loads the images
        void LoadTextures();
        // Set up the tile
        Tile* grassTile;

        //Initialising the engine
        bool Init();
        //The main loop of the game
        void MainLoop();
        //Renders one frame
        void RenderFrame();
        //Processes any user input
        void ProcessInput();
        //Updates the internal processes of the Engine
        void Update();
public:
        //Constructer
        Engine();
        //Destructer
        ~Engine();

        //Starts the engine
        void Go();
};

#endif

6
Graphics / Re: Tile won't texture SFML 2.0
« on: October 27, 2012, 06:33:45 pm »
Tile.h and Tile.cpp

#ifndef _TILE_H
#define _TILE_H

#include <SFML\Graphics.hpp>

class Tile
{
private:
        // Initializing the sprite
        sf::Sprite baseSprite;

public:
        // Constructor
        Tile(sf::Texture& texture);
        // Destructor
        ~Tile();

        // Draws tile to the specifix co-ordinates and window
        void Draw(float x, float y, sf::RenderWindow* rw);
};

#endif

#include "Tile.h"
#include <SFML\Graphics.hpp>

Tile::Tile(sf::Texture& texture)
{
        // Setting the image of baseSprite
        baseSprite.setTexture(texture);
}

Tile::~Tile()
{

}

void Tile::Draw(float x, float y, sf::RenderWindow* rw)
{
        // Setting the position off the sprite
        baseSprite.setPosition(x, y);
        // The render window draws on the sprite
        rw->draw(baseSprite);
}
 

7
Graphics / Re: Tile won't texture SFML 2.0
« on: October 27, 2012, 06:32:55 pm »
There's quite a lot so I'll add it in different replies.

TextureManager.cpp and TextureManager.h

#include "TextureManager.h"
#include <vector>
#include <SFML\Graphics.hpp>

TextureManager::TextureManager()
{

}

TextureManager::~TextureManager()
{

}

void TextureManager::AddTexture(sf::Texture& texture)
{
        // Adds the image to the end of the vector
        textureList.push_back(texture);
}

sf::Texture& TextureManager::GetTexture(int index)
{
        // Return the index of the image being retrived
        return textureList[index];
}

#ifndef _TEXTUREMANAGER_H
#define _TEXTUREMANAGER_H

#include <vector>
#include <SFML\Graphics.hpp>
using namespace std;

class TextureManager
{
private:
        // Creting vector to hold images
        vector<sf::Texture> textureList;

public:
        //Constructor
        TextureManager();
        //Destructer
        ~TextureManager();

        // Adding an image
        void AddTexture(sf::Texture& texture);
        // Retrieving an image
        sf::Texture& GetTexture(int index);
};

#endif

8
Graphics / Re: Tile won't texture SFML 2.0
« on: October 27, 2012, 06:23:04 pm »
I didn't copy any code. I read an outdated tutorial about it, wrote everything and then updated it with SFML 2.0. I didn't copy and paste anything. Once again, I said I will provide any code that's asked for.

9
Graphics / Tile won't texture SFML 2.0
« on: October 27, 2012, 06:10:57 pm »
I'm creating a 2D tile engine with C++ and SFML 2.0. I have no errors yet when I build and run the code I just get a black render window. I'm probably doing something really stupid but help is really appreciated. I'm also not getting the "can't find file" error that should apparently pop up. I'll post code if needed/asked.

http://imgur.com/WQLQ1,XGXsL,XWWsQ

Those are 3 pictures. 1 of my project folder showing the texture, 2 showing the code where I try to get the image and 3 showing the black render window.

I thank you in advance for any help.

Pages: [1]