Can someone please get me started

Started by
3 comments, last by TheAdmiral 17 years, 5 months ago
Hi, im a beginner C++ prgrammer. I know how to use pointers, arrays, all variables, construct classes, and functions, etc... But i have never figured out how to throw graphics, or draw graphics on the screen. I was told to go to libsdl.org and get a dev pack. So i went there and got the Amaltheia library for C++, but had problems linking the headers, and etc... All I want to accomplish today is throw graphics on a screen. Can anyone please help me. Im using Dev C++ 5.0 (beta edition) from bloodshed.net If ya need anymore information i'll give it. thanks, c.s. finch
Advertisement
Here is a link that has not only instructions to setup SDL ( which is one of many graphical API options, but the one I know best ) but also how to use it.

Direct link to dev-cpp setup instructions.

If you find you are having problems, please post the errors your compiler gives you. We cannot help you if we don't know what your problem actually is.
Allegro and SDL are probably the most common API choices. It seems you have already installed SDL though and an IDE as well. In order to create a window with a graphic like you want, all you have to do is add this code in a empty console project where you specify -lSDLmain and -lSDL as linker parameters in project->options.

#include <SDL/SDL.h>SDL_Surface *window;SDL_Surface *image; // image surface// function to blit surface on the window surfacevoid BlitSurface(int x, int y, SDL_Surface *img) {    SDL_Rect pos={x,y,0,0};    SDL_BlitSurface(img, NULL, window, &pos);}int main(int argc, char *argv[]) {    SDL_Init(SDL_INIT_VIDEO); // init SDL video subsystem    window = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE); // create the actual window    image = SDL_LoadBMP("image.bmp"); // load bmp file    while (1) {        BlitSurface(200, 200, image); // blit image on screen        SDL_Flip(window); // update screen buffer    }       SDL_FreeSurface(image); // free image surface    return 0;}


This code will create a window and show the image file "image.bmp" on the coordinates 200,200 (x,y), I added comments to each line so it should be fairly straightforward. This code will only work if you have installed SDL though.
I don't know what your plans are and the direction you'd like to go but can skip the rendering pipeline/API altogether if it's something you don't like. All you need to know is some basics about textures and models. With these you can pick an engine like Irrlicht or Ogre and start working your way up.

With Irrlicht you can get a model rendered on your screen with less than two pages of loose code. You just initialize the rendering engine and feed it with models and textures.

P.S: SDL is nice for 2D though so if that's what you like keep learning it.

My project`s facebook page is “DreamLand Page”

Quote:Original post by password
Allegro and SDL are probably the most common API choices.

That's a little misleading.
Allegro and SDL are probably the most common API choices among those who want to work in 2D without resorting to deprecated libraries. There are far more people working (in 2D) with DirectX and OpenGL (au naturelle).

While Direct3D doesn't offer the most user-friendly support for 2D graphics, there are still armies of people out there using DirectDraw.

SDL is great and all, but I think bionic_atom should be aware that if his primary aim is employment in the industry, then he may have to submit to the fascist adherence to DirectX or OpenGL that is so prevalent. I don't condone the superiority wars that are so common with API choice, but I do acknowledge their existence, and I'm all for education of truth [smile].

Regards
Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.

This topic is closed to new replies.

Advertisement