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

Pages: 1 ... 8 9 [10] 11 12
136
Python / Re: VertexArray & Vertex's tilemap nightmare
« on: January 28, 2013, 10:48:36 pm »
Things get clearer now :p Thanks for the tip! :)

137
Python / Re: VertexArray & Vertex's tilemap nightmare
« on: January 28, 2013, 10:10:18 pm »
Woaw, that's very interesting! I'm quite new to OpenGL, how do you set many textures to be all drawn in one call ? (I assumed you have one texture per tile.)

138
Python / Re: VertexArray & Vertex's tilemap nightmare
« on: January 28, 2013, 07:47:57 pm »
I tried to understand the C++ code (about tile rendering using Vertex and VertexArray) but couldn't figure out why it would faster thus, sorry, I cannot help you about that.

By the way, seems you're mastering drawing shapes/tiles at hand, once you understand everything I won't mind a feedback :p

139
Python / Re: python-sfml2
« on: January 28, 2013, 07:40:53 pm »
I recently renamed all sfml packages and dropped the "2" so just remove the "2" from all package name. :)

libsfml2-dev -> libsfml-dev
python-sfml2 -> python-sfml
sfml2-examples -> sfml-example

The package repository name have also been renamed: use "sonkun/sfml-stable" for stable SFML releases (sfml2-RC included) and "sonkun/sfml-development" for the latest versions (in development).

These repositories contain works based on SFML as well such the Python bindings, sfeMovie, its Python binding and TGUI (v4.2). Soon, they will contain Aurora, Thor and SFGUI libraries.

By the way, what Ubuntu version do you use?

I wanted my Fedora packages ready before announcing this recent change, so I'm sorry to be late on this. :s

Let me know how it goes :)

140
Python / Re: VertexArray & Vertex's tilemap nightmare
« on: January 24, 2013, 09:19:01 pm »
This topic is rather related to how OpenGL work to render 2d vertices and its documentation might help you understand. Because SFML just provides wrappers to make things more convenient.

You're right, the fifth vertex is not necessary (and shouldn't even exist).

It's quite easy to understand, just keep things simple: you define 2d vertices (location + color), then tell OpenGL how to draw them (sf.PrimitiveType.QUAD is what you need here).

OpenGL will fill your shape with the colors you gave to your vertices. If you used four red vertices, your shape will be red. If you used multiple colors, you'll get a gradient color.

Additionally you can fill your shape with a texture as your screenshot shows it.

But now you can combine both and you'll get this result.


Now, use tex_coords to use the top left corner of your texture by replacing  86 with 46.
    v1 = sfml.Vertex(sfml.Vector2(10, 10), sfml.Color.RED, sfml.Vector2(0, 0))
    v2 = sfml.Vertex(sfml.Vector2(600, 50), sfml.Color.RED, sfml.Vector2(86, 0))
    v3 = sfml.Vertex(sfml.Vector2(450, 450), sfml.Color.RED, sfml.Vector2(86, 86))
    v4 = sfml.Vertex(sfml.Vector2(10, 300), sfml.Color.RED, sfml.Vector2(0, 86))
And you'll get this:


141
Python / Re: VertexArray & Vertex's tilemap nightmare
« on: January 24, 2013, 04:47:55 pm »
Unfortunately OpenGL doesn't support concave shape :D And by consequence, SFML neither :( But you can build them from multiple convex shapes if you really need (be warned, it's pain in the ass). But tiles are convex shapes so for your tile engine using Vertex and VertexArray, you're fine.

In your snipped code, you tried to construct a concave shape which renders badly, so you should try with a rectangle to start. This shape is built from vertices which all have a color, so your shape is filled with a gradient color (interpolation).  Then, you applied a texture on top of that which merges the texture and the gradient color and give you at the end a weird shape :). The third argument in Vertex constructor tex_coords tells OpenGL what part of your texture is used to fill the shape.

To experiment:

1) Start with a rectangle without texture
2) Then, try with white color points and a texture
3) Make your shape convex (other than a rectangle)
3) Modify tex_coords to fill your shape with different part of your texture

#!/usr/bin/env python2
# coding: utf-8

import sfml

class Mapa(sfml.Drawable):
    def __init__(self, texture):
        sfml.Drawable.__init__(self)
        self.vertexarray = sfml.VertexArray(sfml.PrimitiveType.QUADS)
        self.texture = texture
       
    def draw(self, target, states):
        states.texture = self.texture
        target.draw(self.vertexarray, states)
       
def main():
    wn = sfml.RenderWindow(sfml.VideoMode(800, 800), "Prueba de Vertexs")
    wn.vertical_synchronization = True
    wn.framerate_limit = 60
   
    textura = sfml.Texture.from_file("textura.png")
    mapa = Mapa(textura)

    # Creamos una serie de vertexs conforme al mapa
    v1 = sfml.Vertex(sfml.Vector2(10, 10), sfml.Color.WHITE, sfml.Vector2(0, 0))
    v2 = sfml.Vertex(sfml.Vector2(600, 50), sfml.Color.WHITE, sfml.Vector2(86, 0))
    v3 = sfml.Vertex(sfml.Vector2(450, 450), sfml.Color.WHITE, sfml.Vector2(86, 86))
    v4 = sfml.Vertex(sfml.Vector2(10, 300), sfml.Color.WHITE, sfml.Vector2(0, 86))
    v5 = sfml.Vertex(sfml.Vector2(10, 10), sfml.Color.WHITE, sfml.Vector2(0, 0))

    # Existen más baldosas pero lo dejare hasta ahí
    for vertex in [v1, v2, v3, v4, v5]:
        mapa.vertexarray.append(vertex)
       
    while wn.is_open:
        for event in wn.events:
            if isinstance(event, sfml.CloseEvent):
                wn.close()
               
        wn.clear(sfml.Color.WHITE)
        wn.draw(mapa)
        wn.display()
       
if __name__ == "__main__":
    main()

142
Python / Re: Compilations errors
« on: January 23, 2013, 03:07:38 am »
The binding is not yet updated to the latest SFML version. You could temporarily downgrade your SFML version to commit 38da3f4338e3b2b11e3dff2726a62104cf27fa73 or wait until the update.

143
Python / Re: VertexArray & Vertex's tilemap nightmare
« on: January 23, 2013, 03:01:57 am »
Hello!

I see you wrote that four days ago, so sorry to be late on this. Don't hesitate to ask your questions via my private email address (in case I don't answer soon and you should get faster answers too :p). I'll make an effort to check the forum more often.

I'm aware there are performance issues (#65) when doing intensive computation with vectors (since they're still handled at Python level) but I don't think this is your case. Note: this issue should be fixed soon since fused type Cython feature is now fixed in last stable release.

About Vertex and VertexArray:
First I would suggest to read the documentation, Vertex and VertexArray, but I admit this is not enough to apprehend what is really going on and thus, write efficient code.

SFML is based on OpenGL. Basically, OpenGL only knows vertices location. Then you tell OpenGL to draw these vertices and how to link them to make shapes. E.g: You'll need four vertices to make a rectangle. Note that SFML use Vertex and VertexArray internally to draw your shapes, your sprites, etc.

As sf.VertexArray inherits from sf.Drawable, once you have defined your vertices and stored them in a VertexArray, you'll be able to draw as a traditional drawable (sprite, shape, text):
window.draw(vertex_array)

To try it out:
import sfml as sf
window = sf.RenderWindow(sf.VideoMode(640, 480), "pysfml")
lines = sf.VertexArray(sf.PrimitiveType.LINES_STRIP, 2)
lines[0].position = (10, 10)
lines[1].position = (100, 10)

lines.append(sf.Vertex((100, 100)))

lines.resize(4)
lines[3].position = (10, 100)

window.clear()
window.draw(lines)
window.display()
raw_input()
 

I'm glad you have animations working :) and hope you'll get your performance issues solved quickly!

144
Python / Re: python-sfml2
« on: January 11, 2013, 01:30:37 pm »
I do but I haven't published anything yet. If you want, we could discuss the theory in private as I've been working on them for more than two years now, you might be interested :)

145
Python / Re: How do I Inheritance from sfml.TransformableDrawable??
« on: January 11, 2013, 01:24:13 pm »
Thanks, I fix that!

146
Python / Re: python-sfml2
« on: January 07, 2013, 05:26:44 pm »
The license is updated now, thanks.

I'm glad to hear you love them :) and by the way check out the new release 1.2 which should be announced soon.

147
Python / Re: How do I Inheritance from sfml.TransformableDrawable??
« on: January 07, 2013, 05:22:31 pm »
The segmentation fault is a bug that has been fixed a while ago. Please update your bindings to the latest version (1.2). I still need to announce 1.2 release and should be done as soon as I figure out how to build sfeMovie for amd64 architecture.

About using sf.TransformableDrawable, you should prefer using sf.Drawable and use a sf.Transformable internally as mentioned in the documentation: http://python-sfml.org/1.2/tutorials.html#drawable

The reason I introduced sf.TransformableDrawable is because Python doesn't allow to subclass from two built-in classes at the same time. But using sf.Drawable is fine but requires to (re)create accessors for each sf.Transformable's accessors. For speed writing, use sf.TransformableDrawable but for elegance, use sf.Drawable and sf.Transformable.

148
General / Re: SFML 2.0 from apt-get
« on: October 24, 2012, 09:07:53 pm »
I just packaged sfeMovie. :-)

libsfemovie
libsfemovie-dev

apt-get install libsfemovie libsfemovie-dev

I first packaged with the single example under the name sfemovie-example but it seems the example fails to compile. Here is the buildlog. I couldn't figure it out why so I removed it from the package, I'll add it later back later.


149
General / Re: SFML 2.0 from apt-get
« on: October 23, 2012, 03:34:46 pm »
Voilà.

I upgraded the packages to Quantal and sent them to launchpad, they should be available as soon as launchpad build them. :)

(i386 already available, the amd64 one will be in 4 hours)

150
General / Re: SFML 2.0 from apt-get
« on: October 18, 2012, 06:17:28 pm »
I just realized a new Ubuntu version is out thus if you're looking for packages for the latest version, mine may not work, (haven't tried yet) but if you're on 12.04l, that's okay.

Pages: 1 ... 8 9 [10] 11 12