• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0

SDL help with my program

1 post in this topic

Hi, if anyone can find a solution to my problem will be great.
i am using codeblocks 10.05 SDL_image-1.2.12 SDL_ttf-2.0.11 SDL-1.2.14-win32
i am writing a program from scratch and i am a beginner if you want. two main problem affictl my program no compiling error or so ever but perhaphs limitation of code language probably?

1-my program as a login screen that i manage to make it work fantastic for me, but once i arrive the login succesfull i want to have the rid of everything except the screen in order to proceed with the loading of the real game, but this is no possible if i insert a sdl_freesurface or a clean up function the program seem to crash. (segmentation relative to the flipping of the screen for the real game i use different images so it is not a problem of sharing the same image...)

2-i started my game creating a map yes this will be a 2d tile game based, now what i would like to do it is grabbing the map with mouseevent button down and realise it when i relise the left button; and using mousemovement to calculate the offset while the left button it is pressed. probably sdl do not let you to use the two event togheter?

2b if i use only mouse move the map actualy moves but still the screen doesn't update and you can see the drag.

thanks if somebody reply

Share this post

Link to post
Share on other sites
Hi everyone i got this program from one of my friend on internet and it is working for moving as bitmap around (still to adapth to my program) but still seems i can't have the rid of the screen of login if anyone can help please i have the following message

#0 0040350E wrconw::wrconv(this=0x28fe03, screen=0x5f3768, backgroundtwo=0x0, event={type = 5 '\005', active = {type = 5 '\005', gain = 0 '\0', state = 1 '\001'}, key = {type = 5 '\005', which = 0 '\0', state = 1 '\001', keysym = {scancode = 5 '\005', sym = SDLK_UNKNOWN, mod = KMOD_NONE, unicode = 0}}, motion = {type = 5 '\005', which = 0 '\0', state = 1 '\001', x = 261, y = 387, xrel = 0, yrel = 0}, button = {type = 5 '\005', which = 0 '\0', button = 1 '\001', state = 1 '\001', x = 261, y = 387}, jaxis = {type = 5 '\ (C:\wrconv 0.01\wrconv0.01.cpp:88)
#1 00404968 SDL_main(argc=1, args=0x5f2b30) (C:\wrconv 0.01\login.cpp:399)
#2 0040565B console_main(argc=1, argv=0x5f2b30) (./src/main/win32/SDL_win32_main.c:315)
#3 00405718 WinMain(hInst=0x400000, hPrev=0x0, szCmdLine=0x813668 "", sw=10) (./src/main/win32/SDL_win32_main.c:398)
#4 00000000 0x00404fe6 in main() (??:??)

now i post you the code working for moving a bitmmap around with the mouse

#include <SDL.h>
const int SCREEN_WIDTH = 320; /* Set the screen width variable */
const int SCREEN_HEIGHT = 240; /* Set the screen height variable */
const int SCREEN_DEPTH = 32; /* Set the screen depth variable */

int main(int argc, char *argv[])


SDL_Surface *screen;
SDL_Surface *bitmap;

SDL_Rect offset;
/* Part of bitmap to view */
SDL_Rect bitmap_offset;
SDL_Event event;

bool running = true;
bool mousedown = false;
/* Initialize SDL */

/* Initialise the screen, by passing the screen width, height, depth, and surface type */

/* set up the screen offset variables, where we will draw the bitmap to */
offset.x = 0;
offset.y = 0;
offset.h = SCREEN_HEIGHT;
offset.w = SCREEN_WIDTH;
/* Part of bitmap to view */
bitmap_offset = offset; /* C++ code */
bitmap = SDL_LoadBMP ("C:/wrconv 0.01/bin/Debug/images/backgroundtwo.bmp");

/* calculate the maximum x and y origin of bitmap to show on screen */
int max_x_origin = bitmap->w - SCREEN_WIDTH;
int max_y_origin = bitmap->h - SCREEN_HEIGHT;
/* Check if bitmap is smaller than window */
if(max_x_origin < 0)
max_x_origin = 0;
if(max_y_origin < 0)
max_y_origin = 0;

/* apply the bitmap to the screen */
SDL_BlitSurface (bitmap, NULL, screen, &offset);

/* update the screen */
while( SDL_PollEvent( &event ) )
if(event.type = SDL_MOUSEBUTTONDOWN)
if (event.button.button == SDL_BUTTON_LEFT)
mousedown = true;
if(event.type = SDL_MOUSEBUTTONUP)
if (event.button.button == SDL_BUTTON_LEFT)
mousedown = false;
if(event.type = SDL_MOUSEMOTION)
if (mousedown) {
/* Change which part of bitmap to show */
bitmap_offset.x -= event.motion.xrel;
bitmap_offset.y -= event.motion.yrel;

/* Check rectangle values are valid */
if(bitmap_offset.x < 0)
bitmap_offset.x = 0;

if(bitmap_offset.y < 0)
bitmap_offset.y = 0;
if(bitmap_offset.x > max_x_origin)

bitmap_offset.x = max_x_origin;

if(bitmap_offset.y > max_y_origin)
bitmap_offset.y = max_y_origin;

/* update surface and show */

SDL_BlitSurface (bitmap, &bitmap_offset, screen, &offset);


if( event.type == SDL_QUIT )
//Quit the program
running = false;
/* Don't hog the computer */
SDL_FreeSurface( bitmap );

return 0;

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
Followers 0