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

Author Topic: sfRectangleShape doesn't render anything in an array.  (Read 4424 times)

0 Members and 1 Guest are viewing this topic.

pangaea

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
sfRectangleShape doesn't render anything in an array.
« on: November 15, 2013, 11:33:06 pm »
So I'm trying to render RectangleShapes in an array. However, it won't draw at all. I don't know what I'm doing wrong, I had a similar problem with sprites having to bind the texture before rendering.

So I have a array of sfRectangleShape*  and I render it to the screen, but I get just the player being render.

#include "serkill.h"

#include <SFML\Graphics.h>
#include <stdio.h>

enum terrain_num terrain[DUN_WIDTH][DUN_WIDTH];
sfRectangleShape* terrain_image[DUN_WIDTH][DUN_HEIGHT];

void init_map()
{
        sfVector2f position;
        int x;
        int y;
        sfVector2f scale;
        sfColor color;
        scale.x = 32;
        scale.y = 32;

        for(x=0; x<DUN_WIDTH; x++)
        {
                for(y=0; y<DUN_HEIGHT; y++)
                {
                        if(x==10 && y==0)
                        {
                                terrain[x][y] = WALL;
                        }
                        else
                        {
                                terrain[x][y] = FLOOR;
                        }
                }
        }

        for(x=0; x<DUN_WIDTH; x++)
        {
                for(y=0; y<DUN_HEIGHT; y++)
                {
                        terrain_image[x][y] = sfRectangleShape_create();
                }
        }

        for(x=0; x<DUN_WIDTH; x++)
        {
                for(y=0; y<DUN_HEIGHT; y++)
                {
                        position.x = x*32;
                        position.y = y*32;
                        sfRectangleShape_setPosition(terrain_image[x][y], position);
                        if(terrain[x][y] == WALL)
                        {
                                color = sfCyan;
                                sfRectangleShape_setFillColor(terrain_image[x][y],color);
                               
                        }
                        else
                        {
                                color = sfWhite;
                                sfRectangleShape_setFillColor(terrain_image[x][y],color);
                        }

                        sfRectangleShape_setScale(terrain_image[x][y], scale);
                }
        }
}

void terrain_render()
{
        int x=0;
        int y=0;
        sfColor color = sfWhite;

        for(x=0; x<DUN_WIDTH; x++)
        {
                for(y=0; y<DUN_HEIGHT; y++)
                {
                        sfRectangleShape_setFillColor(terrain_image[x][y],color);
                        window_display_rectangle(terrain_image[x][y]);
                        printf("%f \n", sfRectangleShape_getPosition(terrain_image[x][y]).x);
                }
        }
}

void window_display_rectangle(sfRectangleShape* shape)
{
        sfRenderWindow_drawRectangleShape(window, shape, NULL);
}

Main loop

void main_loop()
{
        enum game_cmd cmd;
        int i;
        sfEvent event;

        while(window_isOpen())
        {
                while(poll_window_event(&event))
                {
                        cmd = get_command(&event);

                        do_command(cmd);
                }

                window_clear();

                terrain_render();

                render_player();

                window_display();
        }

}

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: sfRectangleShape doesn't render anything in an array.
« Reply #1 on: November 16, 2013, 12:09:30 am »
I don't see you calling sfRectangle_setSize anywhere, in which case the RectangleShapes are using their default size of 0x0. I would try making sure they have some dimensions to them and then try it again.
DSFML - SFML for the D Programming Language.

pangaea

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: sfRectangleShape doesn't render anything in an array.
« Reply #2 on: November 16, 2013, 12:44:57 am »
Thanks Jebbs that worked. I thought I did put size of the rectangle, but I didn't.