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();
}
}