Jump to content
  • Advertisement
Sign in to follow this  
bionic_atom

Can someone please get me started

This topic is 4329 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 surface
void 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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!