Subject: [Nel] GNU/Linux viewport fix

From: Loic Dachary <[email-masked]>
Date: Mon, 18 Feb 2002 22:55:54 +0100

Hi,

	Here is a patch that fixes the viewport lossage on GNU/Linux.
The patch is minimal and while working on it I realized that X11
support probably need some serious work. Am I right or somehow
mistaken ?

	Cheers,

P.S. Note that the patch adds less than 15 lines ;-)

Index: nel/src/3d/driver/opengl/driver_opengl.cpp
===================================================================
RCS file: /home/cvsroot/code/nel/src/3d/driver/opengl/driver_opengl.cpp,v
retrieving revision 1.136
diff -u -r1.136 driver_opengl.cpp
--- nel/src/3d/driver/opengl/driver_opengl.cpp	15 Feb 2002 17:43:03 -0000	1.136
+++ nel/src/3d/driver/opengl/driver_opengl.cpp	18 Feb 2002 21:48:32 -0000
@@ -1213,13 +1213,23 @@
 
 void CDriverGL::setupViewport (const class CViewport& viewport)
 {
-#ifdef NL_OS_WINDOWS
+#if NL_OS_WINDOWS
 	if (_hWnd)
 	{
 		// Get window rect
 		RECT rect;
 		GetClientRect (_hWnd, &rect);
-
+		// Setup gl viewport
+		int clientWidth=rect.right-rect.left;
+		int clientHeight=rect.bottom-rect.top;
+#else // NL_OS_WINDOWS
+		XWindowAttributes win_attributes;
+		if (!XGetWindowAttributes(dpy, win, &win_attributes))
+		  throw EBadDisplay("Can't get window attributes.");
+		// Setup gl viewport
+		int clientWidth=win_attributes.width;
+		int clientHeight=win_attributes.height;
+#endif // NL_OS_WINDOWS
 		// Get viewport
 		float x;
 		float y;
@@ -1227,9 +1237,6 @@
 		float height;
 		viewport.getValues (x, y, width, height);
 
-		// Setup gl viewport
-		int clientWidth=rect.right-rect.left;
-		int clientHeight=rect.bottom-rect.top;
 		int ix=(int)((float)clientWidth*x);
 		clamp (ix, 0, clientWidth);
 		int iy=(int)((float)clientHeight*y);
@@ -1239,6 +1246,7 @@
 		int iheight=(int)((float)clientHeight*height);
 		clamp (iheight, 0, clientHeight-iy);
 		glViewport (ix, iy, iwidth, iheight);
+#if NL_OS_WINDOWS
 	}
 #endif // NL_OS_WINDOWS
 }

-- 
Loic   Dachary         http://www.dachary.org/  [email-masked]
12 bd  Magenta         http://www.senga.org/      [email-masked]
75010    Paris         T: 33 1 42 45 07 97          [email-masked]
        GPG Public Key: http://www.dachary.org/loic/gpg.txt

---

From: Vincent Caron <[email-masked]>
Date: 18 Feb 2002 23:32:25 +0100

> support probably need some serious work. Am I right or somehow

I would say 'you are right' :)

There are some things that could be cleaner of more efficient, like the
(not so working) keyboard mapping, a function to fetch the window size
(the 'XGetWindowAttribute' snippet is pasted everywhere), DGA mouse
handling, and other tidbits ...

---

From: Loic Dachary <[email-masked]>
Date: Tue, 19 Feb 2002 11:26:31 +0100

> handling, and other tidbits ...

	Wouldn't SDL help a lot here ? 

	Cheers,

---

From: Vincent Caron <[email-masked]>
Date: 19 Feb 2002 16:08:34 +0100

> 	Wouldn't SDL help a lot here ? 

It could. However NeL needs very few glue code with the OS, SDL has a
minimal OpenGL support (was added late, SDL primary purpose is direct
frame buffer access, doesn't deal with extensions for instance), and
comes with its own event and setup mechanism. I guess taking
'inspiration' from such a lib would be a good idea ... However SDL was
used by Loki for most ports, so it has a good track record.

I'm maintaining a list of GL toolkits here :
  http://ngl.sourceforge.net/links.php

(Yes, I also have such a lib - NGL - which is bound to be released, but
is a much broader framework, shouldn't fit NeL)