Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trouble getting SFML working with my Win32 window.  (Read 5593 times)

0 Members and 1 Guest are viewing this topic.

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Trouble getting SFML working with my Win32 window.
« on: February 05, 2010, 05:23:34 pm »
Ok, I am making an editor for my game using SFML to display the GUI and Irrlicht to display the viewport. My problem is that the SFML part isn't working at all, it should be in that little light patch on the right (it's light because thats the window colour, sfml is literally not displaying at all, not even a blank colour)


This is my WinMain
Code: [Select]
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hWnd = InitialiseWin32Window(hInstance);
Viewport* viewport = new Viewport(hWnd, hInstance);
ControlPanel* controlpanel = new ControlPanel(hWnd, hInstance);

MSG msg;
while(true)
{
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
if(msg.message == WM_QUIT)
break;
}
viewport->Run();
controlpanel->Run();
Sleep(0);
}
delete controlpanel;
delete viewport;
return 0;
}


Control Panel header
Code: [Select]
#ifndef ControlPanel_h
#define ControlPanel_h

#include <windows.h>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>

class ControlPanel
{
public:
ControlPanel(HWND hWnd, HINSTANCE hInstance);
~ControlPanel();

void Run();

protected:
HWND SfmlControlPanel;
sf::RenderWindow* renderpanel;
};

#endif


And Control Panel source file
Code: [Select]
#include "ControlPanel.h"

ControlPanel::ControlPanel(HWND hWnd, HINSTANCE hInstance)
{
SfmlControlPanel = CreateWindowW(L"STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
864, 0, 160, 600, hWnd, NULL, hInstance, NULL);
renderpanel = new sf::RenderWindow(hWnd);
}

ControlPanel::~ControlPanel()
{
delete renderpanel;
}

void ControlPanel::Run()
{
renderpanel->Clear(sf::Color(255,0,0));
renderpanel->Display();
}


I really have no idea why it's not working, as you can see I am trying to display that entire rectangle as red and nothing is displaying at all.
As you can see irrlicht is working correctly, so it shouldn't be a problem with my main window.

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Trouble getting SFML working with my Win32 window.
« Reply #1 on: February 05, 2010, 05:29:14 pm »
Do you use the OpenGL backend of Irrlicht? Can you show your Viewport class?
Laurent Gomila - SFML developer

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Trouble getting SFML working with my Win32 window.
« Reply #2 on: February 05, 2010, 05:37:47 pm »
I used the DX9 renderer in Irrlicht, it works very similar to SFML with win32 integration.

Here are my viewport files.

Header
Code: [Select]
#ifndef Viewport_h
#define Viewport_h

#include <windows.h>
#include <irrlicht.h>

class Viewport
{
public:
Viewport(HWND hWnd, HINSTANCE hInstance);
~Viewport();

void Run();

protected:
HWND irrlichtViewport;
irr::IrrlichtDevice* device;
irr::video::IVideoDriver* driver;
irr::scene::ISceneManager* smgr;
};

#endif


Source File
Code: [Select]
#include "Viewport.h"

Viewport::Viewport(HWND hWnd, HINSTANCE hInstance)
{
irrlichtViewport = CreateWindowW(L"STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
0, 0, 864, 600, hWnd, NULL, hInstance, NULL);

irr::SIrrlichtCreationParameters params;
params.DriverType = irr::video::EDT_DIRECT3D9;
params.WindowId = reinterpret_cast<void*>(irrlichtViewport);

device = irr::createDeviceEx(params);

driver = device->getVideoDriver();
smgr = device->getSceneManager();

smgr->addCameraSceneNode(0, irr::core::vector3df(5,5,5),irr::core::vector3df(0,0,0));
irr::scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(smgr->getMesh("../Media/floortile.obj"));
node->setMaterialFlag(irr::video::EMF_LIGHTING, false);

}

Viewport::~Viewport()
{
device->closeDevice();
device->drop();
}

void Viewport::Run()
{
device->getTimer()->tick();
driver->beginScene(true, true, irr::video::SColor(255, 50, 50, 50));
smgr->drawAll();
driver->endScene();
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Trouble getting SFML working with my Win32 window.
« Reply #3 on: February 05, 2010, 06:14:45 pm »
Does the SFML view work if you remove your Irrlicht viewport?
Laurent Gomila - SFML developer

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Trouble getting SFML working with my Win32 window.
« Reply #4 on: February 05, 2010, 06:35:36 pm »
Strangely it draws from 0, 0 to 864, 600...

That is most confusing considering the definition of CreateWindowW is as so...
Code: [Select]
CreateWindowW(lpClassName, lpWindowName, dwStyle, x, y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam)
Which should mean that based on this...
Code: [Select]
SfmlControlPanel = CreateWindowW(L"STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
864, 0, 160, 600, hWnd, NULL, hInstance, NULL);

that the following should be true in my function call:
Code: [Select]
lpClassName = "STATIC"
lpWindowName = NULL
dwStyle = WS_CHILD | WS_VISIBLE | QS_CLIPSIBLINGS
x = 864
y = 0
nWidth = 160
nHeight = 600
hWndParent = hWnd
hMenu = NULL
hInstance = hInstance
lpParam = NULL

Surely then the sfml render panel should range from 864, 0 to 864+160, 0+600 in my window?...


Ok this is getting REALLY wierd.
Code: [Select]
SfmlControlPanel = CreateWindowW(L"STATIC", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
100, 0, 160, 600, hWnd, NULL, hInstance, NULL);

That does this:

It's like it's occupying the inverse of the areas specified, VERY peculiar.
Possible sfml bug bug?

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Trouble getting SFML working with my Win32 window.
« Reply #5 on: February 05, 2010, 06:44:21 pm »
OK, SFML BUG IDENTIFIED
You appear to be using the width and height where you should be using x and y and using x and y where you should be using width and height.

Ok no bug afterall

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Trouble getting SFML working with my Win32 window.
« Reply #6 on: February 05, 2010, 07:26:05 pm »
Hum... I have a simpler conclusion: you use the wrong HWND
Code: [Select]
renderpanel = new sf::RenderWindow(SfmlControlPanel); // <--- you initially used hWnd
Laurent Gomila - SFML developer

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Trouble getting SFML working with my Win32 window.
« Reply #7 on: February 05, 2010, 08:16:16 pm »
Oh man I feel so stupid, how could I have missed that D:

Thanks so much, and sorry about labelling it a bug based on my sillyness :P

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Trouble getting SFML working with my Win32 window.
« Reply #8 on: February 05, 2010, 08:35:40 pm »
Oh, suddenly the font size of "SFML BUG IDENTIFIED" shrunk drastically. :P

(Sorry for OT)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Jallen

  • Newbie
  • *
  • Posts: 39
    • View Profile
Trouble getting SFML working with my Win32 window.
« Reply #9 on: February 05, 2010, 08:43:03 pm »
Hmm, is it possible for my SFML view on my win32 window to get events via this interface?
Code: [Select]
const sf::Input& input = renderpanel->GetInput();

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Trouble getting SFML working with my Win32 window.
« Reply #10 on: February 05, 2010, 10:55:24 pm »
Quote from: "Jallen"
Hmm, is it possible for my SFML view on my win32 window to get events via this interface?
Code: [Select]
const sf::Input& input = renderpanel->GetInput();

Absolutely, it should work fine. SFML subclasses the window in order to catch all its events, so that it behaves like SFML-made windows.
Laurent Gomila - SFML developer

 

anything