Jump to content

  • Log In with Google      Sign In   
  • Create Account


Zanman777

Member Since 17 Apr 2012
Offline Last Active Jun 26 2014 08:34 AM
-----

Posts I've Made

In Topic: Re-learning C++ and some help with learning it.

16 June 2014 - 06:07 PM

Hi, Zero_Breaker. I feel exactly like you. And I understand why you feel so demotivated. The thing is, you're probably (subconsciously, anyway) thinking you'll be learning all this C++ again and forget it again soon. Other reason for your low morale is you don't get to see results of what you've learned. Finally, the third factor is probably you don't feel trully commited to the whole process of digging in, learning and doing.

 

Programming is a very, very demanding task. You have to learn C++ (considering your approach now). Then, you need to learn 2D/3D math. Then you need to learn how to use a graphics library (OpenGL, or SDL, or a 3D engine...). In the meantime you need to learn how a game is actually coded - the logic of the game loop, how to integrate several source and header files, how to organize the whole code... The list goes on and on.

 

Don't feel guilty because you're not getting to the finish line. It does take a long, long time. The important thing here is you like the journey, not just the final destination. I'm saying this but I'm on the same boat... I also keep getting lost on what to do next, what to learn next. Maybe we could learn together? I'm sure it would boost the heck of our morales, to share thoughts, maybe even programming stuff together?

 

If anyone else reading this is on the same boat, drop me a msg or reply to this topic, maybe we could gather a "beginners" group to keep everyone motivated and to help each other learning stuff.

 

That being said, and replying to your post, I'd say the book you chose (C++ Primer 5th Edition) is a very, very good choice. It's the book I chose too. It gets very deep into C++, and it may be tiring to finish it, but believe me, it will be worth it. It helps to really understand how C++ works. It will help you to avoid magical bugs and compiler warnings/errors popping out of nowhere because you will trully master the dirty details of it all. So be easy on yourself. You're going the right path, but it's also the hardest one. My approach to your problem (feeling demotivated, bored...) was this: taking notes on the details that will most probably be forgotten in a couple of days (because they're not used enough) but represent potential pitfalls when it comes to code. I made a kind of personal "cheat sheet" with some 15 pages of notes about everything I'll need to remind myself of when I want to code. The book itself has over 1000 pages iirc, so bringing it down to 15 pages is a major sense of accomplishment by itself. Heck, I'll share my cheat sheet with you if it helps you, no problem :)

 

Concerning the bookstore stuff, I can help you with that if you want. Send me PM if you're interested

 

Cheers ;) 


In Topic: Please tell me there's a way to set line width in SDL

18 December 2013 - 08:36 AM

My purpose was to draw buttons' borders. There is no way to specify the SDL_Rect border width, so I was trying the line approach. How can I draw a customisable button border, then?


In Topic: Quick question - problems declaring an SDL_Texture container

16 December 2013 - 03:33 PM

The textureToLoad smile.png


In Topic: Quick question - problems declaring an SDL_Texture container

16 December 2013 - 03:13 PM

Oh, so with your code suggestion the SDL_Texture won't go out of scope? If so, it's piece of cake.

 

Yeah, it's working now, but getting rid of a member that only gets used on one member function would be a plus smile.png


In Topic: Quick question - problems declaring an SDL_Texture container

16 December 2013 - 02:42 PM

graphics.h

class Graphics
{
public:
     void renderBMP(std::string path, int posX, int posY);

private:
    // the textures container. The strings will be the file paths
    map<string, SDL_Texture*> textures;
    SDL_Texture *textureToLoad; // temporary texture holder for the loading function. The workaround.
};

graphics.cpp

/*  Search for this BMP's path on the textures container.
*   If it doesn't exist, load it to the container.
*   If it already exists, retrieve the texture from the container. */

void Graphics::renderBMP(std::string path, int posX, int posY)
{
    if (textures.find(path) == textures.end()) // If this texture isn't loaded yet
    {
        SDL_Surface *tempSurface = SDL_LoadBMP(path.c_str());
        textureToLoad = SDL_CreateTextureFromSurface(renderer, tempSurface);
        SDL_FreeSurface(tempSurface);
        textures[path] = textureToLoad;
    }
    else
    {
        textureToLoad = textures[path];
    }

    // the rest doesn't matter
}

This is how I have it, after a little workaround.

 

I was trying to avoid the need of a class member (in this case, textureToLoad) to hold the new SDL_Texture after the renderBMP() function has gone out of scope.

 

What I was trying was this:

void Graphics::renderBMP(std::string path, int posX, int posY)
{
    if (textures.find(path) == textures.end()) // If this texture isn't loaded yet
    {
        SDL_Surface *tempSurface = SDL_LoadBMP(path.c_str());
        textures[path] = new SDL_Texture(SDL_CreateTextureFromSurface(renderer, tempSurface));
        SDL_FreeSurface(tempSurface);
    }
// blablabla

I was getting the error again this way.

 

In the meantime I found out that SDL isn't prepared to be used in such a way that means creating SDL_Textures directly (without the pointer interface). Quoting a site I found http://stackoverflow.com/questions/18897076/sdl-texture-incomplete-type):

 

 

SDL_Texture is an opaque type by design (that is, designed to only be operated on by SDL2 internally), you can "pass it around" as a pointer, but you can't access the internals (or create a SDL_Texture yourself, for example by doing a malloc, because you don't know the size of the structure). If you stick to SDL_Texture *blah;

pointers and pass them around to the SDL2 functions you should be fine.

This I why I decided to use the workaround.


PARTNERS