Jump to content
  • Advertisement
Sign in to follow this  
Arbel

SDL on a windows form application

This topic is 3819 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
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.

Share this post


Link to post
Share on other sites
Depends what sort of thing precisely you want to show, and what you will be using in your game.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!