SDL on a windows form application

Started by
4 comments, last by Arbel 15 years, 11 months ago
This is probably an easy question for some people, but I'm not exactly sure how I would go about doing this. I'm making an editor for our game in C++ using DevExpress tools, and other windows built-in tools. I want to dedicate part of the form to the display, which will of course be displayed using SDL. How do I set it up so that it only displays on part of the form. Would I need to create a viewport?
Advertisement
SDL isn't designed to be used as part of another application in that way - it expects to own its own windows. There is the 'SDL_WINDOWID hack' if you search on here and on Google for it, but apparently it's non-trivial to get right.
In that case, do you think OpenGL would be my best route?
Depends what sort of thing precisely you want to show, and what you will be using in your game.
It's possible and i've done it before but i can only get drawing to work, no sound.
To do it you create a surface like this:

SDL_Surface* backBuffer = SDL_CreateRGBSurface(SDL_SWSURFACE, 640, 480, 24, 0x00FF0000, 0x0000FF00, 0x000000FF, 0);


Now to draw it, i call this function in WM_PAINT message:

void flipSurface(HWND hWnd, HDC pDc, SDL_Surface* pSource, int pX, int pY, int w, int h)    {        BITMAPINFO bitInfo;        RECT size;        int width, height;        memset(&bitInfo, 0, sizeof(bitInfo));        bitInfo.bmiHeader.biSize = sizeof(bitInfo.bmiHeader);        bitInfo.bmiHeader.biWidth = pSource->w;        bitInfo.bmiHeader.biHeight = -pSource->h;        bitInfo.bmiHeader.biPlanes = 1;        bitInfo.bmiHeader.biBitCount = pSource->format->BitsPerPixel;        bitInfo.bmiHeader.biCompression = BI_RGB;        GetClientRect(hWnd, &size);        width = (size.right < w ? size.right : w) - pX;        height = (size.bottom < h ? size.bottom : h) - pY;        StretchDIBits(pDc, pX, pY, width, height, 0, 0, width,            height, pSource->pixels, &bitInfo, DIB_RGB_COLORS, SRCCOPY);    }case WM_PAINT:    PAINTSTRUCT ps;    HDC dc = BeginPaint(hWnd, &ps);    flipSurface(hWnd, dc, backBuffer, 0, 0, 640, 480);    EndPaint(hWnd, &ps);break;
Thanks for the code, I'll be sure to give it a try. Basically what we are going to be doing is have the display screen be identical to the actual game screen. You can drag in images from the tree structure on the left and drag them "into" the screen to place them. You can also, using the buttons at top, switch between layers and place object on other layers etc. You can also right click an object and set its animation, so we would want the editor to display what objects look like while animating as well.

I've written Animation/Sprite stuff in SDL, so I'd like to re-use it if possible.

This topic is closed to new replies.

Advertisement