• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Programmer557

Program won't show picture OR stop when told

7 posts in this topic

  I am working through Lazy Foo's tutorials on SDL, and I was on lesson 4 (Event Driven Programming) and everything was going exactly how it should have been going, untill I tried to run my program.  The program would run like it was supposed to, meaning that there were no warnings about improper sintax or missing DLLs or anything like that, but all I was seeing was a blank window pop up. 

 

  The program is supposed to show a picture (in my case a tree but that isn't important), and stay open untill I hit the X in the upper right hand corner, but for some reason it's not doing either of those.  Like I said I'm seeing a blank screen, but the program also won't close when told to.  I'm able to close it through stopping the debug, but that's not how it's supposed to work. 

 

   I've attached the program file here: [attachment=14025:Events.zip] so that you can see if I've missed something there, and here is the code in case you can't open the files on your computer:

 

 

 

#include "SDL.h"
#include "SDL_image.h"
#include <string>

const int ScreenWidth = 640;
const int ScreenHeight = 480;
const int ScreenBPP = 32;

SDL_Surface* Image = NULL;
SDL_Surface* Screen = NULL;

//SDL event structure
SDL_Event Event;

SDL_Surface* load_image(std::string filename)
{
    //Load Image
    SDL_Surface* LoadedImage = NULL;

    //Optimize
    SDL_Surface* OptimizedImage = NULL;

    //load image with SDL image
    LoadedImage = IMG_Load(filename.c_str());

    //if the image loaded fine
    if (LoadedImage != NULL)
    {
        //create the optimized image
        OptimizedImage = SDL_DisplayFormat(LoadedImage);

        //free the old image
        SDL_FreeSurface(LoadedImage);
    }

    //return the optimized image
    return OptimizedImage;
}

void ApplySurface(int x, int y, SDL_Surface* Source, SDL_Surface* Destination)
{
    //temp rectangle to hold offsets
    SDL_Rect offset;

    //get the offsets
    offset.x;
    offset.y;

    //blit to the surface
    SDL_BlitSurface(Source,NULL,Destination,&offset);
}

bool Init()
{
    //terminate program if init fails
    if(SDL_Init(SDL_INIT_EVERYTHING) == -1)
    {
        return false;
    }

    //set up the screen
    Screen = SDL_SetVideoMode(ScreenWidth, ScreenHeight, ScreenBPP, SDL_SWSURFACE);

    //if the screen failed to start
    if(Screen == NULL)
    {
        return false;
    }

    //Set the window caption
    SDL_WM_SetCaption("Event Test",NULL);

    //if everything went fine
    return true;
}

bool LoadFiles()
{
    //load the image
    Image = load_image("Tree.png");

    //if there was an error
    if (Image == NULL)
    {
        return false;
    }

    //if everything loaded properly
    return true;
}

void Cleanup()
{
    //free the image
    SDL_FreeSurface(Image);

    //quit SDL
    SDL_Quit();
}

int main (int argc, char* args[])
{
    //make sure the program doesn't terminate immediately
    bool Quit = false;

    //initialize
    if (Init() == false)
    {
        return 1;
    }

    //load the image
    if (LoadFiles() == false)
    {
        return 1;
    }

    //apply the surface
    ApplySurface(0,0,Image,Screen);

    //update the screen
    if (SDL_Flip(Screen) == -1)
    {
        return 1;
    }

    //start main loop
    while (Quit == false)
    {
        //get input of some kind
        while (SDL_PollEvent(&Event))
        {
            //if user X's out
            if (Event.type == SDL_QUIT)
            {
                //quit the program
                Quit == true;
            }
        }
    }

    //free the surface and quit the program
    Cleanup();

    return 0;
}
 

 

 

Any help would be apreciated.  Thank you in advance.

0

Share this post


Link to post
Share on other sites

 

 

//quit the program
Quit == true;

 

This part needs some fixing.

oh....  It's amazing that no matter how hard I look I always miss that one little detail.  Thanks!

0

Share this post


Link to post
Share on other sites

 

 

//quit the program
Quit == true;

 

This part needs some fixing.

Well now the program will close, but the picture still isn't showing up.

0

Share this post


Link to post
Share on other sites

Whack the warning level up to the max. You should get warnings about statements having no effect (or is that gcc only?)

0

Share this post


Link to post
Share on other sites

Just curious. Did you try stepping through the program with the debugger?

 

I guess I'm assuming windows and Visual Studio..

Edited by Megahertz
0

Share this post


Link to post
Share on other sites

Since you are in the Type - Test - Figure it out phase,  Try Hardwiring the variables you are attempting to pass.  Until you are totally comfortable with writing, and I know all to well, the authors of books make typo errors.  Also, to start with I think you are trying to do much error trapping.  This in itself could also become a big trap until you become totally comfortable with it.

 

CONFESSION : I myself do not know all the ins and outs of the C++ and it's many libraries but try simplifying it.

 

Instead of all of the sub-routines, write everything in MAIN in linear format, Keep it simple. Load your image into a variable called MYTREE. , then apply it to your screen.  Do not worry about the error trapping ,Focus on loading the image.  also make sure that your code and image are set to the same Directory.

 

If they are in different directories, you could very well not be loading nothing at all and that is what you are seeing. 

 

You may want to write a small snippet, with an error message box to test if the "Tree.PNG" file exist where you are telling the program to look for it.  In Fact I think that is the first thing you should check,  Make sure your image is in your active directory.

 

Let me know if that was the problem!

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0