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 - delio

Pages: [1]
1
General / Get size of content
« on: May 02, 2014, 03:55:22 pm »
At first, Content's width is 50 px.


Then, I zoom in. So contents are bigger. It's width is 100px


How can I get contents' width, when I've zoom?

I've try "view.getSize" .
but While Contents are bigger, "view.getSize.x" is lower.

delio

2
General / Algorithm help!
« on: April 15, 2014, 05:38:16 pm »
Hi,
I want to import bmp file to Tilemap.
but My tile map has only 40 colors.

This is my algorithm
1.Use SFML to convert color of bitmap to My Tilemap color.
2.read pixel of bitmap and store in array.
3.display Tilemap

Question is
1.How can I read pixel color in SFML?
2.How can I convert bmp color to nearest tilemap color by using SFML?

Sorry for bad explanation
Thanks,
delio

3
DotNet / [Solved]Tile map in C#
« on: April 05, 2014, 03:35:44 pm »
class TileMap : Drawable
        {

            public bool load(string tileset, SFML.Window.Vector2u tileSize, int[] tiles, uint width, uint height)
            {

                // resize the vertex array to fit the level size
                // m_vertices.PrimitiveType(Quads);
                m_vertices.Resize(width * height * 4);

                // populate the vertex array, with one quad per tile
                for (uint i = 0; i < width; ++i)
                {
                    for (uint j = 0; j < height; ++j)
                    {
                        // get the current tile number
                        int tileNumber = tiles[i + j * width];

                        // find its position in the tileset texture
                        long tu = tileNumber % (m_tileset.Size.X / tileSize.X);
                        long tv = tileNumber / (m_tileset.Size.X / tileSize.X);

                        // get a pointer to the current tile's quad
                        uint index = (i + j * width) * 4;

                        // define its 4 corners
                        m_vertices[index + 0] = new Vertex(new Vector2f(i * tileSize.X, j * tileSize.Y), new Vector2f(tu * tileSize.X, tv * tileSize.Y));
                        m_vertices[index + 1] = new Vertex(new Vector2f((i + 1) * tileSize.X, j * tileSize.Y), new Vector2f((tu + 1) * tileSize.X, tv * tileSize.Y));
                        m_vertices[index + 2] = new Vertex(new Vector2f((i + 1) * tileSize.X, (j + 1) * tileSize.Y), new Vector2f((tu + 1) * tileSize.X, (tv + 1) * tileSize.Y));
                        m_vertices[index + 3] = new Vertex(new Vector2f(i * tileSize.X, (j + 1) * tileSize.Y), new Vector2f(tu * tileSize.X, (tv + 1) * tileSize.Y));
                    }
                }

                return true;
            }

            void Drawable.Draw(SFML.Graphics.RenderTarget target, SFML.Graphics.RenderStates states)
            {
                // apply the transform
                //states.Transform *= getTransform();

                // apply the tileset texture
                states.Texture = m_tileset;

                // draw the vertex array
                target.Draw(m_vertices, states);
            }

            public SFML.Graphics.Texture m_tileset = new SFML.Graphics.Texture(@"d:/tileset.png");
            private SFML.Graphics.VertexArray m_vertices = new SFML.Graphics.VertexArray();

        }
This is my code
And problem is It display as dot, not areas.
like in the picture

What is the mistake?
Thanks

4
DotNet / Change C++ to C# problem
« on: April 02, 2014, 03:42:39 pm »
Code: [Select]
class TileMap : public sf::Drawable, public sf::Transformable
{
public:

bool load(const std::string& tileset, sf::Vector2u tileSize, const int* tiles, unsigned int width, unsigned int height)
{

if (!m_tileset.loadFromFile(tileset))
return false;


m_vertices.setPrimitiveType(sf::Quads);
m_vertices.resize(width * height * 4);


for (unsigned int i = 0; i < width; ++i)
for (unsigned int j = 0; j < height; ++j)
{

int tileNumber = tiles[i + j * width];

int tu = tileNumber % (m_tileset.getSize().x / tileSize.x);
int tv = tileNumber / (m_tileset.getSize().x / tileSize.x);


sf::Vertex* quad = &m_vertices[(i + j * width) * 4];

quad[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
quad[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
quad[2].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);
quad[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);


quad[0].texCoords = sf::Vector2f(tu * tileSize.x, tv * tileSize.y);
quad[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x, tv * tileSize.y);
quad[2].texCoords = sf::Vector2f((tu + 1) * tileSize.x, (tv + 1) * tileSize.y);
quad[3].texCoords = sf::Vector2f(tu * tileSize.x, (tv + 1) * tileSize.y);
}

return true;
}

private:

virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const
{

states.transform *= getTransform();


states.texture = &m_tileset;


target.draw(m_vertices, states);
}

sf::VertexArray m_vertices;
sf::Texture m_tileset;
};
How can I change it to C# language?
like "sf::RenderWindow" in C++ change to "SFML.Graphics.RenderWindow"
What is a structure? Please guide me.

Thanks

5
General / Get SFML renderwindow on label problem
« on: April 01, 2014, 04:40:51 pm »
I want to get SFML renderwindow on label in WinForm.
But when I compiled, It gave me an error like this.


This is my code

Programing.cs
Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Form1.cs
Code: [Select]
using System;
using System.Windows.Forms;
using RibbonLib;
using RibbonLib.Interop;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SFML;
using SFML.Audio;
using SFML.Window;
using SFML.Graphics;

namespace _01_AddingRibbonSupport
{
    public partial class Form1 : Form, IRibbonForm
    {
        public class DrawingSurface : System.Windows.Forms.Control
        {
            protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
            {
                // don't call base.OnPaint(e) to prevent forground painting
                // base.OnPaint(e);
            }
            protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
            {
                // don't call base.OnPaintBackground(e) to prevent background painting
                //base.OnPaintBackground(pevent);
            }
        }
        private Ribbon _ribbon = new Ribbon();

        public Form1()
        {
            InitializeComponent();

            DrawingSurface rendersurface = new DrawingSurface(); // our control for SFML to draw on
            rendersurface.Size = new System.Drawing.Size(400, 400); // set our SFML surface control size to be 500 width & 500 height
            lblPlaceHolderDescription.Controls.Add(rendersurface); // add the SFML surface control to our form
            rendersurface.Location = new System.Drawing.Point(100, 100); // center our control on the form

            // initialize sfml
            SFML.Graphics.RenderWindow renderwindow = new SFML.Graphics.RenderWindow(rendersurface.Handle); // creates our SFML RenderWindow on our surface control

            // drawing loop
            while (lblPlaceHolderDescription.Visible) // loop while the window is open
            {
                System.Windows.Forms.Application.DoEvents(); // handle form events
                renderwindow.DispatchEvents(); // handle SFML events - NOTE this is still required when SFML is hosted in another window
                renderwindow.Clear(SFML.Graphics.Color.Yellow); // clear our SFML RenderWindow
                renderwindow.Display(); // display what SFML has drawn to the screen
            }
        }
       
        #region IRibbonForm Members

        public IntPtr WindowHandle
        {
            get
            {
                return this.Handle;
            }
        }

        public void RibbonHeightUpdated(int newHeight)
        {
            this.splitContainer1.SplitterDistance = newHeight;
        }

        #endregion

        private void Form1_Load(object sender, EventArgs e)
        {
            _ribbon.InitFramework(this);
        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            _ribbon.DestroyFramework();
        }
    }
}

6
Window / SFML Events in Qt creator
« on: March 21, 2014, 08:05:59 am »
I can't use mousewheel event in Qt.

This is my code
 while(RenderWindow::pollEvent(event)) {
if (event.type == sf::Event::MouseWheelMoved)
                           {
                           cout << "work" << endl;

                           }
}

When I scroll my mouse wheel, It won't cout "work".
How can I fix it
Thanks

7
Graphics / Zoom problem
« on: March 19, 2014, 01:43:24 pm »
#ifdef SFML_STATIC
#pragma comment(lib, "glew.lib")
#pragma comment(lib, "freetype.lib")
#pragma comment(lib, "jpeg.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "gdi32.lib")  
#endif // SFML_STATIC


#include <SFML/Graphics.hpp>

int posx, posy;
sf::View view1;

int main()
{
        sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
       

        sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);
        sf::View view1(sf::FloatRect(0, 0, window.getSize().x, window.getSize().y));
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                       

                        if (event.type == sf::Event::MouseMoved)
                        {

                                posx = event.mouseMove.x ;
                                posy = event.mouseMove.y ;
                        }

                        if (event.type == sf::Event::MouseWheelMoved)
                        {

                                if (event.mouseWheel.delta >= 1)
                                {
                                        sf::View view1(sf::FloatRect(0.3f, 0.3f, window.getSize().x, window.getSize().y));
                                        view1.zoom(0.3f);
                                        view1.setCenter(posx, posy);
                                        window.setView(view1);
                                }
                                if (event.mouseWheel.delta <= -1)
                                {
                                        sf::View view1(sf::FloatRect(3.f, 3.f, window.getSize().x, window.getSize().y));
                                        view1.zoom(3.f);
                                        view1.setCenter(posx, posy);
                                        window.setView(view1);
                                }


                        }
                        if (event.type == sf::Event::Resized)
                        {
                                sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
                                window.setView(sf::View(visibleArea));
                        }
                }

                window.clear();
                window.draw(shape);
                window.display();
               
        }

        return 0;
}

My problem is, It not zoom to area that cursor point.
I have move center of view into right position but It still have problem.

And when I resize window, It will reset zoom and position. How can I still zoom and position when resize window?
Thanks

8
General / [Solved]SFML widget in Qt
« on: March 16, 2014, 09:03:23 am »
I've follow the tutorial below.
http://becomingindiedev.blogspot.com/2013/10/qt-5-and-sfml-20-integration.html

but It gives many errors. In the picture below


I have no idea, How can I do? So, Please suggest me.

Thanks,

Sorry for bad English

but it give many error.

So, Please suggest how to adjust this code

9
Graphics / [Unsolved see lastest rep.] View problem
« on: March 12, 2014, 05:05:00 am »
The picture below is when I zoom in.


The picture below is when I zoom out


When I zoom out I don't program display pink lines
display pink link only when I zoom in

How can I do it?

Thanks

Sorry for bad English

10
Graphics / Click and change fill color help!
« on: March 10, 2014, 10:10:56 am »
int x;
int y;

int main()
{
        while
                {
                        if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
                                {
                                        x = sf::Event::MouseButtonEvent::x;
                                        y = sf::Event::MouseButtonEvent::y;
                                }
                         //check that What rectangle which (x,y) is inside

                        (Rectangle that I clicked name).setFillColor(sf::Color::Green);
                }

}

This is my approximately code.
Is that Correct?
and Please tell me How can I check that What rectangle which (x,y) is inside

Thanks
Sorry for bad English
   



11
General / My vertex line is blinking
« on: March 09, 2014, 04:51:25 pm »
Here's my code

I want to create lines in every 40 px

cout << "enter width: ";
        cin >> x;
        cout << endl;
        cout << "enter height: ";
        cin >> y;

        sf::RenderWindow window(sf::VideoMode(x*4, y*4), "Window");
        /*sf::CircleShape shape(100.f);
        shape.setFillColor(sf::Color::Green);*/



        for (int i = 1; i <= x; ++i)
        {

                sf::Vertex outlinex[2] =
                {
                        sf::Vertex(sf::Vector2f(i * 40, 0), sf::Color::Blue),
                        sf::Vertex(sf::Vector2f(i * 40, 100), sf::Color::Blue)

                };
                window.draw(outlinex, 2, sf::Lines);
        }

                while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                }

                /*window.clear();*/
                /*window.draw(outlinex, 2, sf::Lines);*/
                window.display();
        }
       
        system("pause");

My problem is When I compiled, my lines is blinking
but when I delete for loop, it stop.

Thanks

12
General / How can I make zoomable square table in SFML?
« on: March 08, 2014, 06:21:27 pm »
I have 2 questions.

1.How can I make zoomable square table like in the picture below?





At first, there is no line of tile in squares. but when zoom in, line of tiles are slowly appear inside squares.

I'm very newbie. So, Please guide me how to get started.



2.How I can create paint bucket tool and use to fill my tile then store information into array?


Thanks, Sorry for bad English

Pages: [1]