Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

AdolphousC

Just Starting out... and I already have a problem

This topic is 5558 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

Hey all... I am just starting programming, and working with tutorials using SDL to start and I took this tutorial from Code3. You may know him, he has a MsgBoard on this Forum, which seems to be down at the moment. Anyway I am running Microsoft Visual C++ 6 and the code compiles fine, but I get no output, the screen is black, could someone take a look at the code, let me know if they have any tips or hints to make this work. ** The object of the program is to print out a background on the console and then put an image ontop of that background... thanks.

#include <stdio.h> #include <stdlib.h> #include <SDL/SDL.h> // SDL Surface Variables, Back-> Background, Image->Sprint Image // Global so all functions can use them // Probably Set up a Surface Class?? SDL_Surface *back; SDL_Surface *image; SDL_Surface *screen; // Used for the location of the image box int xpos=0,ypos=0; // Called fromt he DrawIMG functions to Blit our Sprite to the screen // src is the SCreen Surface to Blit the Sprite to int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); // *** Inline Functions... // Loads the BMP Files into the variables names // SDL_LoadBMP allows us to do that // The SDL_LoadBMP argumet is path of the picture int InitImages() { back = SDL_LoadBMP( "pics/pinstripe.bmp" ); image = SDL_LoadBMP( "pics/triangles.bmp" ); return 0; } // First of 2 DrawIMG functions // This is going to be where the img is going to be drawn on the surface void DrawIMG(SDL_Surface *img, int x, int y) { SDL_Rect dest; dest.x = x; dest.y = y; SDL_BlitSurface(img, NULL, screen, &dest); } // Second of 2 DrawIMG functions // I think this has to do with blitting an image on a part of the screen surface, notthe whole thing?? void DrawIMG(SDL_Surface *img, int x, int y, int w, int h, int x2, int y2) { SDL_Rect dest; dest.x = x; dest.y = y; SDL_Rect dest2; dest2.x = x2; dest2.y = y2; dest2.w = w; dest2.h = h; SDL_BlitSurface(img, &dest2, screen, &dest); } // Draws the background to the screen surface starting at x,y ( 0, 0 ) // No Screen Locking ( only with pixel manipulation ) void DrawBG() { DrawIMG(back, 0, 0); } // Actually draws our image on the background provided // DrawIMG is determined by the parameters // The two functions work together to make an image that // draws the img but deletes the trail void DrawScene() { DrawIMG(back, xpos-2, ypos-2, 132, 132, xpos-2, ypos-2); DrawIMG(image, xpos, ypos); SDL_Flip(screen); // Screen Update } int main(int argc, char *argv[]) { Uint8* keys; // Standard Init Stuff *** if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO) < 0 ) { printf("Unable to init SDL: %s\n", SDL_GetError()); exit(1); } atexit(SDL_Quit); screen=SDL_SetVideoMode(640,480,16,SDL_HWSURFACE|SDL_DOUBLEBUF); if ( screen == NULL ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); exit(1); } // *** End of standard stuff InitImages(); // Init Images, BG and IMG DrawBG(); // Draws the background to screen // Game Loop int done=0; while(done == 0) { SDL_Event event; while ( SDL_PollEvent(&event) ) { if ( event.type == SDL_QUIT ) { done = 1; } if ( event.type == SDL_KEYDOWN ) { if ( event.key.keysym.sym == SDLK_ESCAPE ) { done = 1; } } } // Key POsitions and Manipultaions keys = SDL_GetKeyState(NULL); if ( keys[SDLK_UP] ) { ypos -= 1; } if ( keys[SDLK_DOWN] ) { ypos += 1; } if ( keys[SDLK_LEFT] ) { xpos -= 1; } if ( keys[SDLK_RIGHT] ) { xpos += 1; } DrawScene(); // Hopefully that will draw the sceene } return 0; }

Share this post


Link to post
Share on other sites
Advertisement
NEVERMIND! I am such a dummy, the executables are two different files from the build directly from the Editor and the EXE is creates INSIDE the debug funtion... DOH!

Share this post


Link to post
Share on other sites
in the future put large code blocks in these tags

  
<source>
code...
code...
</source>
//using [ ] instead of < >



[edited by - ChildOfKordova on October 11, 2017 10:32:23 AM]
weird

Share this post


Link to post
Share on other sites
quote:
Original post by AdolphousC
NEVERMIND! I am such a dummy, the executables are two different files from the build directly from the Editor and the EXE is creates INSIDE the debug funtion... DOH!


I was doing a Linux port of a Half Life mod and couldn''t figure out why the math library wasn''t linking in as I had specified. I was getting all kinds of errors about this missing, that missing, everything.

I spent two hours trying to figure it out on my own and finally went into #tuxlinux (I think). The guy there tried helping me but we still couldn''t figure it out.

So finally I go to open the Makefile but I typo.. and type in makefile. There were two of them, separated only by case.. and gcc was using the lower case one while I had been editing the uppercase one.

God bless compilers.



Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!