Newbie cannot create windows

Hi all,

I am new to SDL and want to create surfaces like windows to turn them on
and off via keypresses.
Working through the archives and demos showed me to use SDL_BlitSurface.
Well, so I created a C++ class “Window” which is the following:
#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;

#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x000000ff;
gmask = 0x0000ff00;
bmask = 0x00ff0000;
amask = 0xff000000;
#endif

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) {

SDL_FreeSurface(window_surface);
}

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);
Show();
}

(Note: Class Color handles SDL_Color and Uint32 colors. That works
fine).

Now I implemented in my main program the following code (all variables
are declared):
screen = SDL_SetVideoMode(1024, 768, 24, SDL_HWSURFACE);
window = new Window(screen, 100, 100, 250, 250);
window->setBackgroundColor(new Color(255,255,255));
window->Show();

You can see that the new window should have white background color (the
main screen is black) but unfortunately I cannot see the new surface :frowning:

Btw: After the last line above the input handler is called and one of
the (less) options is finishing the program, so there is not much code
after window->Show(); :slight_smile:

I try and try but I have no more ideas what I do wrong. Maybe one of the
professionals here has a good idea :slight_smile:

Thanks and regards,
Hauke–
“Wir sind der Nato fest verpflichtet. Wir sind ein Teil der Nato.
Wir sind Europa fest verpflichtet. Wir sind ein Teil Europas”
(George W. Bush)

Quoth Hauke Joachim Zuehl , on Fri 28 Mar 2003:

Now I implemented in my main program the following code (all variables
are declared):
screen = SDL_SetVideoMode(1024, 768, 24, SDL_HWSURFACE);
window = new Window(screen, 100, 100, 250, 250);
window->setBackgroundColor(new Color(255,255,255));
window->Show();

You can see that the new window should have white background color (the
main screen is black) but unfortunately I cannot see the new surface :frowning:
(snip)

Your blits are using the same rectangle for the source and
destination. This is not, AFAICT, correct in this case; I presume you
want to blit the whole of the Window:: surface, in which case you
would blit from (0, 0)+(width, height) of the source to (x, y)+(width,
height) of the destination.

---> Drake Wilson

-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 232 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20030328/cc3067b3/attachment-0007.pgp

Hauke Joachim Zuehl wrote:

SDL_BlitSurface(window_surface, &rect, parent_surface, &rect);
SDL_FillRect(window_surface, &rect, color->getInt32Color());

These calls are wrong, you should use NULL instead of rect, since rect
is referred to the position and size of the window_surface on the screen.

Beside this you should also take care to the use of HWSURFACE. Usually
there is no point in using it without double buffering and fullscreen.

Bye,
Gabry