Now drawing on windows again

This commit is contained in:
Henrique 2013-02-26 05:57:11 -03:00 committed by Eduardo Bart
parent c3c951ebbb
commit 45eda6c573
7 changed files with 36 additions and 38 deletions

View File

@ -238,7 +238,7 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine)
if(g_painter)
g_painter->unbind();
painter->bind();
g_window.setGraphicsContext(painter->getGraphicsContext());
//g_window.setGraphicsContext(painter->getGraphicsContext());
g_painter = painter;
}
@ -254,6 +254,11 @@ bool Graphics::selectPainterEngine(PainterEngine painterEngine)
void Graphics::resize(const Size& size)
{
m_viewportSize = size;
#ifdef PAINTER_DX9
if(g_painterDX9)
g_painterDX9->setResolution(size);
#endif
#ifdef PAINTER_OGL1
if(g_painterOGL1)
g_painterOGL1->setResolution(size);

View File

@ -24,5 +24,7 @@
GraphicsContext::GraphicsContext(const std::string& name)
{
std::cout << "lal1: \"" << name.c_str() << "\" aa" << std::endl;
m_name = name;
std::cout << "lal2: \"" << getName().c_str() << "\" aa" << std::endl;
}

View File

@ -25,15 +25,13 @@
GraphicsContextWGL::GraphicsContextWGL() :
GraphicsContext("WGL")
{
m_deviceContext = 0;
m_wglContext = 0;
}
void GraphicsContextWGL::create(WindowType window)
void GraphicsContextWGL::create(WindowType window, DisplayType display)
{
m_deviceContext = GetDC(window);
if(!m_deviceContext)
g_logger.fatal("GetDC failed");
m_window = window;
m_display = display;
uint pixelFormat;
static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),
@ -53,18 +51,18 @@ void GraphicsContextWGL::create(WindowType window)
0, // Reserved
0, 0, 0 }; // Layer Masks Ignored
pixelFormat = ChoosePixelFormat(m_deviceContext, &pfd);
pixelFormat = ChoosePixelFormat(display, &pfd);
if(!pixelFormat)
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");
if(!(m_wglContext = wglCreateContext(m_deviceContext)))
if(!(m_wglContext = wglCreateContext(display)))
g_logger.fatal("Unable to create GL context");
}
void GraphicsContextWGL::destroy(WindowType window)
void GraphicsContextWGL::destroy()
{
if(m_wglContext) {
if(!wglMakeCurrent(NULL, NULL))
@ -73,17 +71,11 @@ void GraphicsContextWGL::destroy(WindowType window)
g_logger.error("Release rendering context failed.");
m_wglContext = NULL;
}
if(m_deviceContext) {
if(!ReleaseDC(window, m_deviceContext))
g_logger.error("Release device context failed.");
m_deviceContext = NULL;
}
}
void GraphicsContextWGL::restore()
{
if(!wglMakeCurrent(m_deviceContext, m_wglContext))
if(!wglMakeCurrent(m_display, m_wglContext))
g_logger.fatal("Unable to make current WGL context");
}
@ -108,7 +100,7 @@ void *GraphicsContextWGL::getExtensionProcAddress(const char *ext)
void GraphicsContextWGL::swapBuffers()
{
SwapBuffers(m_deviceContext);
SwapBuffers(m_display);
}
void GraphicsContextWGL::setVerticalSync(bool enable)

View File

@ -31,8 +31,8 @@ class GraphicsContextWGL : public GraphicsContext
public:
GraphicsContextWGL();
void create(WindowType window);
void destroy(WindowType window);
void create(WindowType window, DisplayType display);
void destroy();
void restore();
bool isExtensionSupported(const char *ext);
@ -43,7 +43,6 @@ public:
void setVerticalSync(bool enable);
private:
HDC m_deviceContext;
HGLRC m_wglContext;
};

View File

@ -66,8 +66,8 @@ int PlatformWindow::loadMouseCursor(const std::string& file, const Point& hotSpo
void PlatformWindow::setGraphicsContext(const GraphicsContextPtr& graphicsContext)
{
// TODO
//if(m_graphicsContext && m_graphicsContext->getName() == graphicsContext->getName())
//return;
if(m_graphicsContext && m_graphicsContext->getName() == graphicsContext->getName())
return;
if(m_graphicsContext)
internalDestroyContext();

View File

@ -36,7 +36,9 @@ WIN32Window::WIN32Window()
m_minimumSize = Size(600,480);
m_size = Size(600,480);
m_hidden = true;
m_deviceContext = 0;
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_TAB] = Fw::KeyTab;
@ -212,6 +214,12 @@ void WIN32Window::terminate()
internalDestroyContext();
if(m_deviceContext) {
if(!ReleaseDC(m_window, m_deviceContext))
g_logger.error("Release device context failed.");
m_deviceContext = NULL;
}
if(m_window) {
if(!DestroyWindow(m_window))
g_logger.error("ERROR: Destroy window failed.");
@ -275,17 +283,21 @@ void WIN32Window::internalCreateWindow()
g_logger.fatal("Unable to create window");
ShowWindow(m_window, SW_HIDE);
m_deviceContext = GetDC(m_window);
if(!m_deviceContext)
g_logger.fatal("GetDC failed");
}
void WIN32Window::internalCreateContext()
{
dump << m_graphicsContext->getName().c_str();
m_graphicsContext->create(m_window);
m_graphicsContext->create(m_window, m_deviceContext);
}
void WIN32Window::internalDestroyContext()
{
m_graphicsContext->destroy(m_window);
m_graphicsContext->destroy();
}
void WIN32Window::internalRestoreContext()
@ -293,16 +305,6 @@ void WIN32Window::internalRestoreContext()
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)
{
Rect clientRect(pos, getClientRect().size());

View File

@ -35,9 +35,6 @@ class WIN32Window : public PlatformWindow
void internalDestroyContext();
void internalRestoreContext();
void *getExtensionProcAddress(const char *ext);
bool isExtensionSupported(const char *ext);
LRESULT windowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
friend class WindowProcProxy;
@ -83,6 +80,7 @@ private:
Rect adjustWindowRect(const Rect& rect);
std::vector<HCURSOR> m_cursors;
HDC m_deviceContext;
HWND m_window;
HINSTANCE m_instance;
HCURSOR m_cursor;