Saturday, 14 September 2013

SFML Drawing Pixel Array

SFML Drawing Pixel Array

I found this (http://lodev.org/cgtutor/raycasting.html) tutorial on the
Internet and was interested and wanted to make my own. I wanted to do it
in SFML though, and I wanted to extend it, and make a 3D version, so there
could be different levels the player can walk on. Thus, you would need 1
ray for every pixel, and thus each pixel would have to be drawn
independently. I found this
(http://www.sfml-dev.org/tutorials/2.1/graphics-vertex-array.php)
tutorial, and it seemed easy enough to have the array be of individual
vertices. To start, I figured the best thing to do would be to create a
class that could read the pixels returned by the rays, and draw them to
the screen. I used the VertexArray, but things were not working for some
reason. I tried to isolate the problem, but I've had little success. I
wrote a simple vertex array of just green pixels that should fill up part
of the screen, and still there are problems. The pixels only show my code
and the pic. of what I mean.
#include "SFML/Graphics.hpp"
int main() {
sf::RenderWindow window(sf::VideoMode(400, 240), "Test Window");
window.setFramerateLimit(30);
sf::VertexArray pointmap(sf::Points, 400 * 10);
for(register int a = 0;a < 400 * 10;a++) {
pointmap[a].position = sf::Vector2f(a % 400,a / 400);
pointmap[a].color = sf::Color::Green;
}
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
window.draw(pointmap);
//</debug>
window.display();
}
return 0;
}
Apparently I can't post images or more links so here...
htt p://oi43.tinypic.com/s5d9aw.jpg
I meant for this to just fill in the top 10 rows with Green, but
apparently that is not what I did... I think if I can figure out what is
causing this not to work, I can probably fix the main problem. Also if you
think there is a better way to do this instead, you could let me know :)
Thanks!

No comments:

Post a Comment