Newbie wants to create windows on a surface

Hi all!

Well, I am new to SDL and currently I am just hacking around a bit in C++ to get
a feeling for SDL.

My current problem ist that I want to create a kind of window on a main
screen and want to draw or write in that window area.

To realize this I created a window class:
#include “window.h”

Window::Window(SDL_Surface *parent, int x, int y, int _width, int _height) {

parent_surface = parent;
pos_x = x;
pos_y = y;
width = _width;
height = _height;
rect.x = pos_x;
rect.y = pos_y;
rect.w = width;
rect.h = height;

rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;

window_surface = SDL_CreateRGBSurface(SDL_HWSURFACE, _width, _height, 32,
rmask, gmask, bmask, amask);
if (window_surface == NULL) {
fprintf(stderr, “window_surface == NULL!!\n”);

Window::~Window(void) {


void Window::Show(void) {

SDL_BlitSurface(window_surface, &rect, parent_surface, &rect);
SDL_UpdateRect(parent_surface, pos_x, pos_y, width, height);

void Window::Hide(void) {

SDL_FillRect(parent_surface, &rect, 0);
SDL_UpdateRect(parent_surface, rect.x, rect.y, rect.w, rect.h);

SDL_Surface *Window::Surface(void) {

return window_surface;

void Window::setBackgroundColor(Color *color) {

SDL_FillRect(window_surface, &rect, color->getInt32Color());
SDL_UpdateRect(window_surface, rect.x, rect.y, rect.w, rect.h);

bgColor = color;

void Window::Update(void) {

SDL_UpdateRect(window_surface, rect.x, rect.y, rect.w, rect.h);

(Note: The Color class encapsulates SDL_Color and Uint32 colors. That
works fine).

Then I tried this in my main program:
screen = SDL_SetVideoMode(1024, 768, 24, SDL_HWSURFACE);
window = new Window(screen, 100, 100, 250, 250);
window->setBackgroundColor(new Color(255,255,255));

(All variables and objects are declared).

So the main code should create an area of width and height 250 at the
position 100x100 on the main surface.
Then the new window should be filled with white color. Finally
window->Show() should show the window and the screen and this does not

Final goal is to show and hide one or more windows via pressed keys.

I tried different ways with SDL_BlitSurface and / or SDL_UpdateRect but
that does not work either (even working thru the articles of this group) :frowning:

So I hope someone has a good hint what I do wrong.

Thanks and regards,
“Die grosse Mehrzahl unserer Importe kommt von ausserhalb des Landes”
(George W. Bush)

Hauke Joachim Zuehl wrote:

SDL_BlitSurface(window_surface, &rect, parent_surface, &rect);
should be NULL instead!> SDL_UpdateRect(parent_surface, pos_x, pos_y, width, height);