C++ starter

Started by
36 comments, last by Thiatsii 9 years, 7 months ago


in other words i guess i should just learn pure c++ before trying to use sfml?

Not necessarily. It depends on what you mean by getting a headache from not knowing what they are doing in their code.

Are you referring to parts of code like pointers, references, functions:


int *ptrNum = nullptr; // a null pointer
double someNumber = 24.3;
double numberChanger(double &num)
{
    ++num;
    return num;
}
// or the more complex things like 
template <typename Type>
Type max(Type tX, Type tY)
{
    return (tX > tY) ? tX : tY;
}

double testNumber = max(24.2, 45.6);

Or do you mean the logic of what they are trying to do in the code (pulled from Allegro Wiki):


// collision detection code
int bounding_box_collision(int b1_x, int b1_y, int b1_w, int b1_h, int b2_x, int b2_y, int b2_w, int b2_h)
{
    if ((b1_x > b2_x + b2_w - 1) || // is b1 on the right side of b2?
        (b1_y > b2_y + b2_h - 1) || // is b1 under b2?
        (b2_x > b1_x + b1_w - 1) || // is b2 on the right side of b1?
        (b2_y > b1_y + b1_h - 1))   // is b2 under b1?
    {
        // no collision
        return 0;
    }
 
    // collision
    return 1;
}

Or the calls for using a library (pulled from SFML sprite tutorial):


// position
sprite.setPosition(sf::Vector2f(10, 50)); // absolute position
sprite.move(sf::Vector2f(5, 10)); // offset relative to the current position

// rotation
sprite.setRotation(90); // absolute angle
sprite.rotate(15); // offset relative to the current angle

// scale
sprite.setScale(sf::Vector2f(0.5f, 2.f)); // absolute scale factor
sprite.scale(sf::Vector2f(1.5f, 3.f)); // factor relative to the current scale
Advertisement

in other words i guess i should just learn pure c++ before trying to use sfml?

Not necessarily. It depends on what you mean by getting a headache from not knowing what they are doing in their code.
Are you referring to parts of code like pointers, references, functions:
int *ptrNum = nullptr; // a null pointer
double someNumber = 24.3;
double numberChanger(double &num)
{
    ++num;
    return num;
}
// or the more complex things like 
template <typename Type>
Type max(Type tX, Type tY)
{
    return (tX > tY) ? tX : tY;
}

double testNumber = max(24.2, 45.6);
Or the calls for using a library (pulled from SFML sprite tutorial):
// position
sprite.setPosition(sf::Vector2f(10, 50)); // absolute position
sprite.move(sf::Vector2f(5, 10)); // offset relative to the current position

// rotation
sprite.setRotation(90); // absolute angle
sprite.rotate(15); // offset relative to the current angle

// scale
sprite.setScale(sf::Vector2f(0.5f, 2.f)); // absolute scale factor
sprite.scale(sf::Vector2f(1.5f, 3.f)); // factor relative to the current scale

i think its mainly when i read syntax and functions that i dont know.


i think its mainly when i read syntax and functions that i dont know.

That is the best time to google and find what it means. C++ is complex and adding libraries to it doesn't help, but sticking purely to C++ means you aren't really growing your knowledgebase. Just go slow and take it easy. You will learn it with plenty of practice and a lot of patience.


i think its mainly when i read syntax and functions that i dont know.

That is the best time to google and find what it means. C++ is complex and adding libraries to it doesn't help, but sticking purely to C++ means you aren't really growing your knowledgebase. Just go slow and take it easy. You will learn it with plenty of practice and a lot of patience.

thanks :D im reading tutorial books now and feeling good that i am not the only one who feels like this and every one has problems with new syntax and stuff.

hey i want to start reading more books for C++ i have read 2 beginner books and i want to get a C++ Standard Library book any recommendation's i would be buying a paperback or hard cover version of the book. i hate reading on phone or pc. on second thought i don't really want the standard Library i want to learn the actual language! so if any one knows a book to teach the actual language that would be great.

For learning the language I always recommend the same books in the same order:

1) Programming: Principles and Practice Using C++ 2nd Edition by Bjarne Stroustrup
Is a book designed to help you learn to program (if you have never programmed before) using C++ as a tool. It is also the intro course book for several degrees at Texas A&M University. Not to mention it is written by Bjarne Stroustrup himself.
2) C++ Primer 5th Edition by Stanley B. Lippman, Josee Lajoie, Barbara E. Moo
The usual recommendation for Beginner C++, but that phrase is a little misleading. It isn't a book for someone who as never programmed, but rather a book for a programmer who is experienced in another language and looking to learn C++ now. It covers C++ more in-depth.
3) The C++ Standard Library: A Tutorial and Reference by Nicolai M. Josuttis
Covers the standard library in-depth.
4) The C++ Programming Language (as a reference) by Bjarne Stroustrup
I recommend this purely as a reference book. It too is written by Bjarne Stroustrup. You can certainly read it cover to cover if you like, but it makes a better reference than a book about learning due to its technical nature.

Can't hurt to also invest in SFML Game Development by Artur Moreira, Jan Haller, and Henrik Vogelius Hansson while you are at it.

Sorry I'm getting back to this so late. I noticed a few things missed.

You can use SFML and OpenGL together, with using both the SFML Graphics library and OpenGL. It was designed to handle that. Or you can use the individual modules without the Graphics library: http://sfml-dev.org/tutorials/2.1/window-opengl.php

As for all the sf:: functions, classes, and keywords, I tend to use the reference to look and see what everything does: http://sfml-dev.org/documentation/2.1/annotated.php

For instance, finding out what keys you can detect (and conviently, how to detect them): http://sfml-dev.org/documentation/2.1/classsf_1_1Keyboard.php

If you have any specific questions while learning and using SFML, feel free to start a thread and ask. Several of us use it.


I always like to start small and get something visible on the screen before adding complexity to it.
This has kept my sanity intact as well.

I too came from console code to the windows side and was damn near overwhelmed at how to make the transition. About 3.5 months ago I decided to take the hard route by not going with SFML or such. I went with DirectX alone. What I learned was that everything done in windows is through the Message Procedure. I think it took me two weeks to correctly separate the DirectX calls into their own class with a pointer to the MsgProc using a callback. This, so that I can pump key or mouse events directly back to my graphics code. My difficulty lay in that many tutorials had everything on a single page, or they separated the directX but, kept handling key and time events by passing them to functions to call other functions: not because it was performing input handling, but simply because of the way the classes were related. Frustrating at the time. Yet, this to me signaled that I needed to understand what was going on.

Start with 2D and learn it fully. I say this for two reason: first, most everything will carry over into 3D and the 2D is what you'll use for a GUI or HUD; and second, it really helps you play around with concepts as you learn. I started with just getting a sprite to move and rotate from a top down perspective. Now, add linear interpolation to your movement and SLERP for your rotations so that they have smooth acceleration/ deceleration. Build on it by setting a point to move to when you click the mouse. Also have the object start to move with a keyboard press, and on the next press have it decelerate to 0. By breaking these concepts into simple chunks, it kept my sanity intact because I could directly see the results of my learning progress. Also, it helps me to work on two or three separate problems and switch between them when I start getting frustrated with the current one.

Keep a separate journal and write about your problems. For me, it was amusing to look back and see what I was having such difficulty over then. It was also a great boost to my spirit as I saw how I kept tackling, what at the time, seemed insurmountable.

This topic is closed to new replies.

Advertisement