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

Pages: [1]
Graphics / Isometric Depth?
« on: December 20, 2012, 10:37:45 am »
I am working on a map engine for isometric tile based maps. I am thinking on how to draw the sprites and map tiles in the right depth order.

I have made my own implementation of a vertex array with all kinds of extra features just for drawing isometric tile maps such as being able to draw for Y[0] to Y[1] so i was thinking i could store each drawable object in the game in some kind of depth sorting class that divides the screen into screen height / tileStepY (if a isometric diamond is say 32 pixels height then the step is 16 pixels) and then sorts the sprites by their bottom of their shape (the feet) into a bunch of arrays for each depth division. This way when i move a sprite in the map i just have to give its new foot position to the depth sorting class and it would move it to the correct depth division.

This would allow me to draw the map tiles for each depth division and then the sprites that need to be drawn next then goes to the next depth and draws the tiles of the map for that division then the draw that depths sprites. I can optimize this to detect depth divisions with no sprites so i can draw multiple depth divisions of the map tiles at once.

My question is, as i have no idea how this is normally implemented and have come to this style on my own, is this a bad idea or are there any problems anyone can see that i may run into later? I am not sure as well if i should store all active sprites in a overall array and then use its indices or something as an ID and use that to reference that drawable/sprite in the depth arrays or what but that is another issue.

How would you do isometric depth sorting/drawing?

D / Destroy destructor crashes?
« on: December 16, 2012, 03:40:49 pm »
Ok i am trying to wrap some classes in d with the csfml derelict bindings and naturally i want to destroy the sfml object with destructor however when i do that it crashes.

If i where to remove the destructor and have a manual destruction method to the class it doesnt crash if i where not to have a destructor or a destroy method and just leave the memory around it still works but the moment i use the destroy in a destructor it crashes.

It crashes with this error as reported by mago debugger:
First-chance exception: core.exception.InvalidMemoryOperationError

I dont understand why this happens inside a destructor but not in a method that does the same thing. Here is my test code about as minimal as i can make it to demonstrate:

module main;

import derelict.sfml2.system;
import derelict.sfml2.window;
import derelict.sfml2.graphics;
pragma(lib, "derelictUtil.lib");
pragma(lib, "derelictSFML2.lib");

class Image {
        sfImage* image;

        this(uint width, uint height) {
                image = sfImage_create(width, height);

        ~this() {

        void destroy() {

void main() {

        auto image = sfImage_create(100, 100);

        auto myimage = new Image(100, 100);

Can anyone tell my why this is happening and or how to fix it?

C / [Solved] RenderState proper usage?
« on: November 21, 2012, 10:26:25 am »
Heyo quick question about sfRenderState in the C bindings. I know in the C++ bindings you can provide a shader for example rather then the entire RenderState when drawing something but in CSFML you have to provide i complete sfRenderState or null.

My question is what should be in that sfRenderState along with the shader, following the example, to make it work. I have been trying to get a shader to work myself in CSFML but no matter what i do it crashes when i call the draw function so i thought that it may actually be the sfRenderState that is causing the crash.

Appreciated, Nekroze.

Graphics / Shader Lighting? Newbie here.
« on: November 08, 2012, 06:56:55 pm »
Firstly apologies for likely rather dim/broad questions here but i have never once developed anything with shaders and i am new to sfml2 (i am using CSFML).

I currently have a function that, once a frame, goes over every pixel in an sfImage that is half the size of the screen. There is a base color (depending on the time of day this changes) that is drawn to each pixel of the image unless one of the given light sources is within range, in which case it adds that light's color to the current pixel color with a gradient depending on the distance from the light source divided by the light sources range.

Once the image has been updated over each pixel i then update a texture from that image then draw it to the screen with a sprite using a scale of 2.

For reference this is the function i am using to give you a bit of an idea:
        void calculateLights(DDLight*[] lights = []) {
                sfColor color;
                float distance;
                int pos;

                for (int y = 0; y < Size.y; y++) {
                        for (int x = 0; x < Size.x; x++) {
                                color = Color;
                                foreach (DDLight* light; lights) {
                                        distance = light.getDistance(x * 2, y * 2);
                                        if (distance != 0.0) {
                                                        color = interpolateColor(color, light.Color,
                                                                                 (distance / light.Range * 1.0));
                                sfImage_setPixel(Image, x, y, color);
                sfTexture_updateFromImage(Texture, Image, 0, 0);

Now this works fine visually and even on my high end computer the performance impact is negligible. However i do believe that with enough lights and with the later stages of my game running at once this performance will likely be a problem. Also along with the desire to work for the first time with shaders I would love to make this into a shader rather then run it entirely on the CPU.

So i have looked around the web for information on how to shaders in 2d for this kind of thing but i am having a problem finding anything useful to me for multiple reasons:

They require some knowledge of shaders already and explain little bar an outline of the theory of doing lighting.

They often have examples showing how it can be done but seems to depend heavily on using openGL directly but i am using ONLY sfml2 and no openGL calls at all.

Or the information plainly doesn't tell me anything about 2d.

So here i am asking can anyone give me any information on how to actually setup sfml2 to draw a texture to the screen that is generated by a shader. Also how would i begin to implement this kind of shader.

Thanks for the read, please forgive the green-ness of my questions.

Graphics / Flipping RenderTexture
« on: November 06, 2012, 09:36:44 pm »
Hello, a few forewords, i am very new to SFML, i am using CSFML2(although my problem doesnt seem to be with the C bindings at all) and not using any openGL directly.

I am working on a little system that takes a bunch of sprites that are tiles for a map and draws them to the screen in chunks of 32 by 32 tiles at a time.

Previously i had been storing a position for each chunk in screen coordinates and each frame looping over each tile and re positioning the sprite for that tile to the chunkPosition + (tilesize * chunkTilePosition) then drawing each tile.

I know not the most efficient way of doing it but it works fine on my main computer but there is a bit of slowing on my little laptop so i thought of a better, obvious but new to me, way to do it.

My idea was to use a RenderTexture and instead of drawing the sprites onto the screen each frame, just draw the sprites to the RenderTexture once and then just draw the RenderTexture to the screen with a sprite at the chunk position and you have your entire chunk generated into a static image once and drawn easily.

Now this works on its own and i am getting the tiles onto the screen some of the chunks, not all, seem to be flipped and i cannot figure out why.

I am using the exact same loop to draw the sprites as i did with the first method just removed adding the chunks position to the tile position and drawing onto the RenderTexture rather then the screen.

I cant for the life of me figure out why the chunk would be flipped at all, can anyone help me out with this or even have some tips?

Thanks in advance to anyone kind enough to lend assistance.

EDIT: haha, this was in the hopes to increase performance atleast on the only computer i have that isnt way to fast to do performance testing... the version that uses RenderTexture causes it to BSOD upon launch of the app. I guess RenderTexture has a problem with the intelGPU then, is that documented?

quick demonstration of problem, first picture is what i want and how it works when i render to the screen, the second is rendering to RenderTexture. Although the next chunk down doesnt appear to be flipped but the one to its left does, and as far as i can see, neither in any predictable direction but i may be wrong there as the tiles are generated proceduraly off of the same seed, i don't know them that intimately nor are they so unique to me to be able to instantly tell if they are all flipped in one direction or something.

Pages: [1]