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
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();
I try and try but I have no more ideas what I do wrong. Maybe one of the
professionals here has a good idea
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)