what C++ tutorials would you recommend for beginner ?

Discussion in '3DS - Homebrew Development and Emulators' started by Pikachuk, Jul 24, 2017.

  1. Pikachuk
    OP

    Pikachuk GBAtemp Advanced Fan

    Member
    642
    146
    Mar 19, 2016
    France
    Bordeaux
    I've recently started learning C++, i learned all the parts about objects, parents,friends,pointers and things like this but when i saw how the template projects of 3ds look like, i see that i still miss a lot of informations because i don't understand anything
    would you have some infos about what should i learn exactly to start to develop some games touhou like for 3ds ?
     
  2. jockep

    jockep GBAtemp Regular

    Member
    141
    51
    Apr 12, 2017
    What is it you don't understand which example?
     
  3. Pikachuk
    OP

    Pikachuk GBAtemp Advanced Fan

    Member
    642
    146
    Mar 19, 2016
    France
    Bordeaux
    how the rendering works things like this

    i only know the basics of C++, so the console part so i'd like to learn more about how to make the interfaces of the homebrews
     
  4. Kubas_inko

    Kubas_inko 3DS Hardmoder

    Member
    428
    45
    Feb 3, 2017
    Czech Republic
    btw the C++ should be in title
     
  5. Cyan

    Cyan GBATemp's lurking knight

    Global Moderator
    17,618
    8,197
    Oct 27, 2002
    France
    Engine room, learning
    as I don't know your level, or what you are really looking for, I will speak "generally", not for the 3DS nor give specific 3DS SDK functions.

    Every consoles or graphical devices have GPU (Graphic Processor Unit), which are responsible for displaying 2D pixels/pictures, 3D objects in a 3D world space, or calculating textures in real time, etc.
    Each device has its own specification, and can do different things.

    What you want is first to initialize that GPU, to tell the console that your code require graphical interface. (no, it's not always required nor obvious, it could be an app to record sound, etc.)
    When you initialize the GPU, you reserve a memory space where you will place all your pixel's color information that the GPU has to display on screen. This is called the "Frame buffer".
    Usually, we create two frame buffers to get proper video output without lag.
    to keep rendering at a proper frame rate without glitches, or "drawing effect" or flickering effect, you need two frame buffer addresses, that you swap once filled completely.
    so you need to reserve twice the amount in the RAM.



    So, based on the device and its own "color depth" (graphic 8 bit, 32 bit, with or without Alpha channel, etc.) you need to know how many memory in RAM you need to reserve for the GPU.
    Screen_pixel_width X screen_pixel_height X color_depth X 2 (2 frame buffer), and you need to do this "per screen". (3DS has two screens to init, don't forget you need to reserve 4 frame buffers)

    The color depth is based on how many bit you need to code one pixel : RGB can be coded on 8bit, or 24 bit or RGBA on 32bit, etc., there are different ways to code the color for one pixel, you need to read your device sepcification for the "current graphic mode" you choose to use. You could need only 8 bit RGB, and don't need alpha channel or the full 32bit possible colors, it's generally up to you to pick the 2D graphic mode you want to use. sometime it can even require 3D display, which is another init method.

    Once you have your reserved Frame buffer you send that RAM address to the GPU on every cycle to be displayed its content.


    Now you need a function which will write each pixel's color inside that RAM address to display what you want on screen.
    To display a picture, you'll need :
    a function to mount/list the devices (SD, USB, network, etc.)
    a function to parse a file's data and decode a picture (library for jpeg, png, bitmap, etc.) to Array values used by your current graphic mode that you write on your frame buffer, pixel by pixel.
    a function which will alternate the frame buffer address in the GPU to render the fully completely generated frame, instead of overwriting the frame in real time, which could cause visual artifact and bad effect.

    While your program is running, it's doing a loop until the program is closed by the user.
    In that loop, you have all your code to detect user's input, generate a display (fill all pixel's color) to the frame buffer based on the user's input (move a cursor, etc.), tell the GPU to render the content of the buffer, repeat

    This is the basic to render a picture on screen or a graphical interface, or in fact any game.


    Now what you need to know is that what I explained is the basic of the frame buffer.
    if you use a library (LibNDS, PALib, sf2d, citro3d, etc.) all this "frame buffer size calculation" is done by the library, you have access to existing methods (functions) to make your life easier.
    for example, you init the GPU with "Buffer_UP1_address = GPU(init, upper, 4);" and it will initialize the upper screen with graphic mode 4 (which could be a 32bit RGBA for example), reserve enough memory in RAM and return that address. you don't have to bother with screen size or color depth yourself.
    I only explained how it works on a "low level" so you understand how screens are working.


    That's a very basic schematic of what's happening and what you need to do.
    Maybe it will help you understand the examples you are looking to learn how it works. (maybe not, and my explanation was bad or not useful, sorry :P)
     
    Last edited by Cyan, Jul 25, 2017
    xJoelituh, jockep and Kyouken like this.
  6. jockep

    jockep GBAtemp Regular

    Member
    141
    51
    Apr 12, 2017
    To be honest i've used sf2d library for gui but it's not maintained anymore and i havent looked at citro3d att all.
     
  7. Pikachuk
    OP

    Pikachuk GBAtemp Advanced Fan

    Member
    642
    146
    Mar 19, 2016
    France
    Bordeaux
    thanks for the tips
    i've started using SDL to make a cross platform between windows and 3ds game engine that will allow me to make 3ds games

    but there is something weird, the same code of setcolorkey works when i compile on windows but doesn't work when compiled on 3ds
    (on 3ds it doesn't set transparency of the key color)
    it's the exact same code, only the headers are changed by preprocessor macros to change the platform

    and my second problem is that i want to play multiple sounds at the same time for the game but the sdl only allow one at once
    i can't build sdl_mixer because of the missing libmikmod