Sign in to follow this  

SDL on a windows form application

This topic is 3485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 3485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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