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.


Topics - pogrady

Pages: [1]
1
SFML projects / My current project using SFML
« on: January 25, 2013, 09:27:25 am »
Hello!

Wanted to share the current project I am working on entitled The Dungeon 2: The Key of Antioch.  Its a sequel to the first Dungeon, and the demo is really just a playable mini game of an aspect of the whole project.  Since I hit a milestone I thought it might be cool to whip up a little game and demonstrate what I have been working on.

So...

Take a gander at my web page, and download!


2
Graphics / Using the Alpha Value embedded in an image file
« on: January 22, 2013, 06:00:46 pm »
Hello,
How do I render an image that has RGBA values?  I would like to utilize the transparency i created in my paint program, but i am unsure how to use OpenGL. I know that there is a blend mode, and that utilization of OpenGL is simple in SFML since OpenGL is the backend, but i'm not sure which blend mode, or which function i should use.

I added this code after the ceation of my window:
sf::RenderWindow window(sf::VideoMode(800, 600, 32), "SFML works!");

        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_COLOR);
        window.pushGLStates();
 


If somebody has a link to a tutorial that would be awesome as I don't even know what this is called.  :(

3
Graphics / sf::Text Disappearing after displaying once
« on: December 20, 2012, 02:31:14 am »
Hello,

I am trying to display the frame rate of my loop, but the text keeps disappearing after displaying once.  Here is my initialization code:

    sf::Text text("hello");
        text.setFont(sf::Font::getDefaultFont());
        text.setCharacterSize(30);
        text.setStyle(sf::Text::Bold);
        text.setColor(sf::Color::Red);
        text.setPosition(10,10);
 

and the draw code:

        textcoords = text.getPosition();
                text.setPosition(window.convertCoords(sf::Vector2<int>((int)textcoords.x, (int)textcoords.y)));
                End = clock.getElapsedTime();
                ElapsedTime = (End.asMilliseconds() - Start.asMilliseconds())/1000;
                text.setString(ElapsedTime);
                window.draw(text);
 

I am under the impression that I need to convert the coordinates to local space, and I think I am doing this correctly. 

Thanks for the help.

Patrick

4
Graphics / Releasing the Texture
« on: December 17, 2012, 04:57:41 am »
Hello,

Lets say that I want to reuse the same texture object, but load anther texture from memory.  If I load another from memory, does the function release the existing texture?

sf::Texture t;
t.loadFromFile("pic.bmp");

//...stuff

t.loadFromFile("pic2.bmp");
 

does the second call to sf::Texture::loadFromFile(...) release the existing texture in memory?

Patrick

5
Graphics / Drawing sprites :-\
« on: December 12, 2012, 04:29:46 am »
Hello,

I am trying to draw a sprite array, but the screen comes white with no textures.  I'm wondering what I am doing wring:
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <fstream>
#include <iostream>



int main()
{
        std::ifstream file("hills.map");
        if(!file.good())
        {
                std::cout<<"failed to load map."<<std::endl;
                return 0 ;
        }
        int width = 0;
        int length = 0;

        file>>width;
        file>>length;

        char** Map = new char*[width];
        for(int i = 0; i < length; i++)
        {
                Map[i] = new char[length];
        }

        for(int x = 0; x < width; x++)
        {
                for(int y = 0; y < length; y++)
                {
                        Map[x][y] = file.get();
                }

                file.get(); //get the \n character
        }

        sf::Sprite** SpriteArray = new sf::Sprite*[width];
        for(int x = 0; x < width; x++)
        {
                SpriteArray[x] = new sf::Sprite[length];
        }

        //load the sprites into memory

        sf::Texture grass;
        sf::Texture road;

        if(!grass.loadFromFile("grass.png"))
                std::cout<<"failed to load grass from file."<<std::endl;

        if(!road.loadFromFile("road.png"))
                std::cout<<"Failed to load road from file."<<std::endl;

        for(int x = 0; x < width; x++)
        {
                for(int y = 0; y < length; y++)
                {
                        if(Map[x][y] == '#')
                                SpriteArray[x][y].setTexture(grass);
                        else
                                SpriteArray[x][y].setTexture(road);

                        SpriteArray[x][y].setPosition(float(x*64), float(y*64));
                }
        }


        file.close();

    sf::RenderWindow window(sf::VideoMode(800, 800), "SFML works!");
       
    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

                //clear the backbuffer
        window.clear();

                sf::Sprite t;
                //draw stuff
                for(int x = 0; x < width; x++)
                {
                        for(int y = 0; y < length; y++)
                        {
                                t = SpriteArray[x][y];
                                window.draw(t);
                        }
                }

                //display the contents
        window.display();
    }

        //free the memory that the program used
        for(int x = 0; x < width; x++)
        {
                delete[] Map[x];
                delete[] SpriteArray[x];
        }
        delete[] Map;
        delete[] SpriteArray;

    return 0;
}
 

thanks for any help you can provide.

Pages: [1]
anything