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?

closed as off-topic by Alexandre Vaillancourt, DMGregory, Maximus Minimus, Gnemlock, Tyyppi_77 Aug 28 '17 at 12:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about "how to get started," "what to learn next," or "which technology to use" are discussion-oriented questions which involve answers that are either based on opinion, or which are all equally valid. Those kinds of questions are outside the scope of this site. Visit our help center for more information." – Alexandre Vaillancourt, DMGregory, Maximus Minimus, Gnemlock, Tyyppi_77
If this question can be reworded to fit the rules in the help center, please edit the 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. – Arcane Engineer 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
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.

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.

  • 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. – Arcane Engineer Nov 8 '11 at 15:22

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