allow feedback on window size; ask glfw how big a window we *actually* got.

This commit is contained in:
Chris Forbes
2010-02-18 08:18:46 +13:00
parent ecb92c45b6
commit a6d36fcb9a
4 changed files with 14 additions and 2 deletions

View File

@@ -28,6 +28,8 @@ namespace OpenRa.FileFormats.Graphics
IShader CreateShader( Stream stream );
Size WindowSize { get; }
void Begin();
void End();
void Clear( Color color );

View File

@@ -370,6 +370,7 @@ namespace OpenRa
bool windowed = !Game.Settings.Fullscreen;
var resolution = GetResolution(settings);
renderer = new Renderer(resolution, windowed);
resolution = renderer.Resolution;
var controller = new Controller(() => (Modifiers)(int)0/*ModifierKeys*/); /* a bit of insane input routing */

View File

@@ -49,6 +49,8 @@ namespace OpenRa.Graphics
SpriteRenderer rgbaRenderer;
Sprite textSprite;
public Size Resolution { get { return device.WindowSize; } }
public Renderer(Size resolution, bool windowed)
{
device = CreateDevice( Assembly.LoadFile( Path.GetFullPath( "OpenRa.Gl.dll" ) ), resolution.Width, resolution.Height, windowed, false );

View File

@@ -45,6 +45,8 @@ namespace OpenRa.GlRenderer
readonly Glfw.GLFWwindowclosefun windowCloseCallback;
int mouseX, mouseY;
public Size WindowSize { get { return windowSize; } }
internal static void CheckGlError()
{
var n = Gl.glGetError();
@@ -55,7 +57,7 @@ namespace OpenRa.GlRenderer
public GraphicsDevice( int width, int height, bool fullscreen, bool vsync )
{
Glfw.glfwInit();
Glfw.glfwOpenWindow(width, height, 0, 0, 0, 0, 0, 0, fullscreen ? Glfw.GLFW_FULLSCREEN : Glfw.GLFW_WINDOW);
Glfw.glfwOpenWindow(width, height, 0, 0, 0, 0, 0, 0, /*fullscreen ? Glfw.GLFW_FULLSCREEN : */Glfw.GLFW_WINDOW);
bool initDone = false;
var lastButtonBits = (MouseButtons)0;
@@ -69,7 +71,11 @@ namespace OpenRa.GlRenderer
Game.DispatchMouseInput( action == Glfw.GLFW_PRESS ? MouseInputEvent.Down : MouseInputEvent.Up,
new MouseEventArgs( b, action == Glfw.GLFW_PRESS ? 1 : 0, mouseX, mouseY, 0 ), 0 );
lastButtonBits = action == Glfw.GLFW_PRESS ? b : 0;
if (action == Glfw.GLFW_PRESS) lastButtonBits |= b;
else lastButtonBits &= ~b;
if (action != Glfw.GLFW_PRESS && action != Glfw.GLFW_RELEASE)
throw new InvalidOperationException();
} );
Glfw.glfwSetMousePosCallback(mousePositionCallback = (x, y) =>
{
@@ -86,6 +92,7 @@ namespace OpenRa.GlRenderer
} );
CheckGlError();
Glfw.glfwGetWindowSize(out width, out height);
windowSize = new Size( width, height );
cgContext = Cg.cgCreateContext();