-
Create a window
-
Draw a Sprite in the window
-
Control where and what size in the window it appears
-
Make the sprite position and size independent of window resolution
-
Have a working build system, that uses SDL
-
setup on your present machine using your automation script
-
from Workshop 1
-
you shouldn’t need to change the
conanfile.txtorCMakeLists.txtfiles
-
-
We’ll be adding stuff to
main.cppto do more interesting things -
You could continue with your existing code (take a snapshot/commit)
-
or start a fresh project
-
-
SDL2 can already load some images, which we can then use as Sprites
-
only very limited forms of
.bmpfiles -
24bpp
`.bmpfiles
-
-
add code using
SDL_CreateWindowto create a window-
be careful where/when in your program you put this
-
it would be good to have it in a function
-
-
you should check for errors and do something appropriate
-
bad return values
-
-
SDL has some assert functions that you could use
-
look them up, which would make sense for your program
-
or handle errors differently
-
-
Our present program doesn’t have a Game Loop
-
it just runs and then exits
-
-
Add a Game Loop
-
keep it simple initially
-
it should call (at least) 3 functions
-
process_input -
update -
render
-
-
-
Add a log for each time this loop goes around
-
what "priority" should this log be?
-
-
Store the colour in a variable
-
what "scope" should this variable be in?
-
or - how do our functions access its data
-
-
Change the variable over time
-
where should this happen?
-
-
Use the variable when drawing
-
wher should this happen?
-
-
So far we have no classes
-
Quite likely you will use Global variables for your program at this point
-
WARNING: Global variables are, in general, BAD practice
-
We should try to move away from this in future
-
Our Game loop doesn’t exit well at the present
-
SDL can give us input from the user
-
Look up
SDL_PollEventin the documentation -
Use it in your code (in
process_input) to stop your program running when:-
the user closes the window
-
the user presses escape down
-
-
Log appropriately
-
SDL can load some bitmap files with the
SDL_LoadBMPfunction-
we’ll move to a better image loader later
-
-
Look up the documentation for
SDL_LoadBMP -
Make your program load an image
-
make sure you have one in the appropriate format
-
where will your program look
-
-
What "type" does
SDL_LoadBMPgive you -
Log and handles errors appropriately
-
this WILL help you now and in future
-
-
"Textures" exist in GPU memory
-
"Surfaces" exist in CPU memory
-
SDL_LoadBMPdoesn’t give you a texture -
SDL_CreateTextureFromSurfacewill help you create a "texture"-
what should you do with the surface after you’ve finished with it
-
check the documentation
-
-
Log and handles errors appropriately
-
this WILL help you now and in future
-
-
SDL_RenderCopycan control the size and position of the sprite -
Read the documentation
-
Change the size and position
-
What units are these in?