Coders Packet

Creating A Window using SDL library in C++.

By Garvit Jethwani

In this Packet, We are using the basics of the SDL library to create a window and also insert a bmp image in that window.

We are using Visual Studio 2019 for this project. SDL is designed to provide low-level access to keyboard, mouse, audio via OpenGL. It is very popular and useful in creating games in C++.

But before we can access the SDL library we have to download the SDL2 package and then we have to make few changes to Visual Studio. After creating the project we have to include some paths in additional libraries by going in project properties. I have included a txt file mentioning all the changes we have to make before we can use SDL library.  

We have to first include SDL.h. Now we can mention the width and height of the window at the starting as constant. We are creating the SDL_Window object and giving the parameters of height and width and flag as we wanted. We are keeping others undefined. After that window is created and for checking if the event happens is a quit_event after that we break from the loop. After the end of event, we are destroying the window we created.

For Inserting a bmp image we are creating two SDL_Surface objects- image_Surface and window_Surface and initializing with NULL. We are extracting window_Surface from the window object. And for Image Surface are loading the .bmp  file present in the same directory. And the image is loaded in the window.



Note: The Instructions to make appropriate changes in Visual Studio are given In the Instructions.txt file of the packet. Which is necessary for including and Using SDL library.

Download project

Reviews Report

Submitted by Garvit Jethwani (Gjgarvit)

Download packets of source code on Coders Packet