Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to develop simple RPG with ray casting rendering. I chose SDL for graphics and input. The problem is there is no native line drawing in it, which I need to start prototyping a ray casting engine.

I know about SDL_gfx, which can do this, but I am asking if there is any alternative to SDL with primitives drawing functions for C++, which is easy to learn, and is also used by indie game developers?

share|improve this question
    
You need no graphics libraries for raycasting. Read my answer. I have written two raycaster prototype renderers without the use of graphics libraries, just basic SDL. –  Nick Wiggill Nov 8 '11 at 16:40
    
Allegro may be also an alternative. That one has built-in functions for drawing several types of lines. –  ChrisC Nov 8 '11 at 21:16
add comment

2 Answers

up vote 3 down vote accepted

Rasterisation is not a requirement for raycasting. Since generally you are casting a ray per pixel, pixel-plotting is all you need:

void SurfaceUtils::putPixel32( SDL_Surface *surface, int x, int y, Uint32 pixel )
{
    //Convert the pixels to 32 bit
    Uint32 *pixels = (Uint32 *)surface->pixels;

    //Set the pixel
    pixels[ ( y * surface->w ) + x ] = pixel;
}

(...from the SDL docs.)

Since I'm assuming you want a raycaster in the Doom/Wolfenstein style, all you need to do is plot pixels up or down each vertical scanline till you reach the end of the screen. If you're aiming for a per-pixel raycaster instead, warning: this is slow.

PS. I've a working per-pixel voxel raycaster and heightmap voxel raycaster, both written using SDL. No extra graphics libs were needed.

share|improve this answer
add comment

You basically have three options. You can use OpenGL in addition to SDL (OpenGL has support for drawing lines, and is a fairly commonly used API for graphics. You can install and use SDL_gfx or some other library for SDL that includes line drawing. Or you can try SFML, which has support for drawing lines, and is designed for C++, as opposed to SDL, which is designed for C.

share|improve this answer
    
Raycasting doesn't use rasterisation. It uses a scanline approach. If OP's going to draw polygons, then OpenGL by all means. But that's a totally different approach to rendering to what's been asked. –  Nick Wiggill Nov 8 '11 at 15:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.