mirror of
https://github.com/edubart/otclient.git
synced 2025-06-07 19:34:29 +02:00
Now drawing on windows again
This commit is contained in:
parent
c3c951ebbb
commit
45eda6c573
@ -238,7 +238,7 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine)
|
|||||||
if(g_painter)
|
if(g_painter)
|
||||||
g_painter->unbind();
|
g_painter->unbind();
|
||||||
painter->bind();
|
painter->bind();
|
||||||
g_window.setGraphicsContext(painter->getGraphicsContext());
|
//g_window.setGraphicsContext(painter->getGraphicsContext());
|
||||||
g_painter = painter;
|
g_painter = painter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -254,6 +254,11 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine)
|
|||||||
void Graphics::resize(const Size& size)
|
void Graphics::resize(const Size& size)
|
||||||
{
|
{
|
||||||
m_viewportSize = size;
|
m_viewportSize = size;
|
||||||
|
#ifdef PAINTER_DX9
|
||||||
|
if(g_painterDX9)
|
||||||
|
g_painterDX9->setResolution(size);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef PAINTER_OGL1
|
#ifdef PAINTER_OGL1
|
||||||
if(g_painterOGL1)
|
if(g_painterOGL1)
|
||||||
g_painterOGL1->setResolution(size);
|
g_painterOGL1->setResolution(size);
|
||||||
|
@ -24,5 +24,7 @@
|
|||||||
|
|
||||||
GraphicsContext::GraphicsContext(const std::string& name)
|
GraphicsContext::GraphicsContext(const std::string& name)
|
||||||
{
|
{
|
||||||
|
std::cout << "lal1: \"" << name.c_str() << "\" aa" << std::endl;
|
||||||
m_name = name;
|
m_name = name;
|
||||||
|
std::cout << "lal2: \"" << getName().c_str() << "\" aa" << std::endl;
|
||||||
}
|
}
|
||||||
|
@ -25,15 +25,13 @@
|
|||||||
GraphicsContextWGL::GraphicsContextWGL() :
|
GraphicsContextWGL::GraphicsContextWGL() :
|
||||||
GraphicsContext("WGL")
|
GraphicsContext("WGL")
|
||||||
{
|
{
|
||||||
m_deviceContext = 0;
|
|
||||||
m_wglContext = 0;
|
m_wglContext = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsContextWGL::create(WindowType window)
|
void GraphicsContextWGL::create(WindowType window, DisplayType display)
|
||||||
{
|
{
|
||||||
m_deviceContext = GetDC(window);
|
m_window = window;
|
||||||
if(!m_deviceContext)
|
m_display = display;
|
||||||
g_logger.fatal("GetDC failed");
|
|
||||||
|
|
||||||
uint pixelFormat;
|
uint pixelFormat;
|
||||||
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
|
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
|
||||||
@ -53,18 +51,18 @@ void GraphicsContextWGL::create(WindowType window)
|
|||||||
0, // Reserved
|
0, // Reserved
|
||||||
0, 0, 0 }; // Layer Masks Ignored
|
0, 0, 0 }; // Layer Masks Ignored
|
||||||
|
|
||||||
pixelFormat = ChoosePixelFormat(m_deviceContext, &pfd);
|
pixelFormat = ChoosePixelFormat(display, &pfd);
|
||||||
if(!pixelFormat)
|
if(!pixelFormat)
|
||||||
g_logger.fatal("Could not find a suitable pixel format");
|
g_logger.fatal("Could not find a suitable pixel format");
|
||||||
|
|
||||||
if(!SetPixelFormat(m_deviceContext, pixelFormat, &pfd))
|
if(!SetPixelFormat(display, pixelFormat, &pfd))
|
||||||
g_logger.fatal("Could not set the pixel format");
|
g_logger.fatal("Could not set the pixel format");
|
||||||
|
|
||||||
if(!(m_wglContext = wglCreateContext(m_deviceContext)))
|
if(!(m_wglContext = wglCreateContext(display)))
|
||||||
g_logger.fatal("Unable to create GL context");
|
g_logger.fatal("Unable to create GL context");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsContextWGL::destroy(WindowType window)
|
void GraphicsContextWGL::destroy()
|
||||||
{
|
{
|
||||||
if(m_wglContext) {
|
if(m_wglContext) {
|
||||||
if(!wglMakeCurrent(NULL, NULL))
|
if(!wglMakeCurrent(NULL, NULL))
|
||||||
@ -73,17 +71,11 @@ void GraphicsContextWGL::destroy(WindowType window)
|
|||||||
g_logger.error("Release rendering context failed.");
|
g_logger.error("Release rendering context failed.");
|
||||||
m_wglContext = NULL;
|
m_wglContext = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_deviceContext) {
|
|
||||||
if(!ReleaseDC(window, m_deviceContext))
|
|
||||||
g_logger.error("Release device context failed.");
|
|
||||||
m_deviceContext = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsContextWGL::restore()
|
void GraphicsContextWGL::restore()
|
||||||
{
|
{
|
||||||
if(!wglMakeCurrent(m_deviceContext, m_wglContext))
|
if(!wglMakeCurrent(m_display, m_wglContext))
|
||||||
g_logger.fatal("Unable to make current WGL context");
|
g_logger.fatal("Unable to make current WGL context");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +100,7 @@ void *GraphicsContextWGL::getExtensionProcAddress(const char *ext)
|
|||||||
|
|
||||||
void GraphicsContextWGL::swapBuffers()
|
void GraphicsContextWGL::swapBuffers()
|
||||||
{
|
{
|
||||||
SwapBuffers(m_deviceContext);
|
SwapBuffers(m_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GraphicsContextWGL::setVerticalSync(bool enable)
|
void GraphicsContextWGL::setVerticalSync(bool enable)
|
||||||
|
@ -31,8 +31,8 @@ class GraphicsContextWGL : public GraphicsContext
|
|||||||
public:
|
public:
|
||||||
GraphicsContextWGL();
|
GraphicsContextWGL();
|
||||||
|
|
||||||
void create(WindowType window);
|
void create(WindowType window, DisplayType display);
|
||||||
void destroy(WindowType window);
|
void destroy();
|
||||||
void restore();
|
void restore();
|
||||||
|
|
||||||
bool isExtensionSupported(const char *ext);
|
bool isExtensionSupported(const char *ext);
|
||||||
@ -43,7 +43,6 @@ public:
|
|||||||
void setVerticalSync(bool enable);
|
void setVerticalSync(bool enable);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HDC m_deviceContext;
|
|
||||||
HGLRC m_wglContext;
|
HGLRC m_wglContext;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ int PlatformWindow::loadMouseCursor(const std::string& file, const Point& hotSpo
|
|||||||
void PlatformWindow::setGraphicsContext(const GraphicsContextPtr& graphicsContext)
|
void PlatformWindow::setGraphicsContext(const GraphicsContextPtr& graphicsContext)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
//if(m_graphicsContext && m_graphicsContext->getName() == graphicsContext->getName())
|
if(m_graphicsContext && m_graphicsContext->getName() == graphicsContext->getName())
|
||||||
//return;
|
return;
|
||||||
|
|
||||||
if(m_graphicsContext)
|
if(m_graphicsContext)
|
||||||
internalDestroyContext();
|
internalDestroyContext();
|
||||||
|
@ -36,7 +36,9 @@ WIN32Window::WIN32Window()
|
|||||||
m_minimumSize = Size(600,480);
|
m_minimumSize = Size(600,480);
|
||||||
m_size = Size(600,480);
|
m_size = Size(600,480);
|
||||||
m_hidden = true;
|
m_hidden = true;
|
||||||
|
m_deviceContext = 0;
|
||||||
m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL);
|
m_graphicsContext = GraphicsContextPtr(new GraphicsContextWGL);
|
||||||
|
std::cout << "lal3: \"" << m_graphicsContext->getName().c_str() << "\" aa" << std::endl;
|
||||||
|
|
||||||
m_keyMap[VK_ESCAPE] = Fw::KeyEscape;
|
m_keyMap[VK_ESCAPE] = Fw::KeyEscape;
|
||||||
m_keyMap[VK_TAB] = Fw::KeyTab;
|
m_keyMap[VK_TAB] = Fw::KeyTab;
|
||||||
@ -212,6 +214,12 @@ void WIN32Window::terminate()
|
|||||||
|
|
||||||
internalDestroyContext();
|
internalDestroyContext();
|
||||||
|
|
||||||
|
if(m_deviceContext) {
|
||||||
|
if(!ReleaseDC(m_window, m_deviceContext))
|
||||||
|
g_logger.error("Release device context failed.");
|
||||||
|
m_deviceContext = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if(m_window) {
|
if(m_window) {
|
||||||
if(!DestroyWindow(m_window))
|
if(!DestroyWindow(m_window))
|
||||||
g_logger.error("ERROR: Destroy window failed.");
|
g_logger.error("ERROR: Destroy window failed.");
|
||||||
@ -275,17 +283,21 @@ void WIN32Window::internalCreateWindow()
|
|||||||
g_logger.fatal("Unable to create window");
|
g_logger.fatal("Unable to create window");
|
||||||
|
|
||||||
ShowWindow(m_window, SW_HIDE);
|
ShowWindow(m_window, SW_HIDE);
|
||||||
|
|
||||||
|
m_deviceContext = GetDC(m_window);
|
||||||
|
if(!m_deviceContext)
|
||||||
|
g_logger.fatal("GetDC failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::internalCreateContext()
|
void WIN32Window::internalCreateContext()
|
||||||
{
|
{
|
||||||
dump << m_graphicsContext->getName().c_str();
|
dump << m_graphicsContext->getName().c_str();
|
||||||
m_graphicsContext->create(m_window);
|
m_graphicsContext->create(m_window, m_deviceContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::internalDestroyContext()
|
void WIN32Window::internalDestroyContext()
|
||||||
{
|
{
|
||||||
m_graphicsContext->destroy(m_window);
|
m_graphicsContext->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WIN32Window::internalRestoreContext()
|
void WIN32Window::internalRestoreContext()
|
||||||
@ -293,16 +305,6 @@ void WIN32Window::internalRestoreContext()
|
|||||||
m_graphicsContext->restore();
|
m_graphicsContext->restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WIN32Window::isExtensionSupported(const char *ext)
|
|
||||||
{
|
|
||||||
return m_graphicsContext->isExtensionSupported(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
void *WIN32Window::getExtensionProcAddress(const char *ext)
|
|
||||||
{
|
|
||||||
return m_graphicsContext->getExtensionProcAddress(ext);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WIN32Window::move(const Point& pos)
|
void WIN32Window::move(const Point& pos)
|
||||||
{
|
{
|
||||||
Rect clientRect(pos, getClientRect().size());
|
Rect clientRect(pos, getClientRect().size());
|
||||||
|
@ -35,9 +35,6 @@ class WIN32Window : public PlatformWindow
|
|||||||
void internalDestroyContext();
|
void internalDestroyContext();
|
||||||
void internalRestoreContext();
|
void internalRestoreContext();
|
||||||
|
|
||||||
void *getExtensionProcAddress(const char *ext);
|
|
||||||
bool isExtensionSupported(const char *ext);
|
|
||||||
|
|
||||||
LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||||
friend class WindowProcProxy;
|
friend class WindowProcProxy;
|
||||||
|
|
||||||
@ -83,6 +80,7 @@ private:
|
|||||||
Rect adjustWindowRect(const Rect& rect);
|
Rect adjustWindowRect(const Rect& rect);
|
||||||
|
|
||||||
std::vector<HCURSOR> m_cursors;
|
std::vector<HCURSOR> m_cursors;
|
||||||
|
HDC m_deviceContext;
|
||||||
HWND m_window;
|
HWND m_window;
|
||||||
HINSTANCE m_instance;
|
HINSTANCE m_instance;
|
||||||
HCURSOR m_cursor;
|
HCURSOR m_cursor;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user