[Mesa-dev] [PATCH 2/2] demos/pixeltest: Adapt the example for points too.

2014-01-08 Thread jfonseca
From: José Fonseca jfons...@vmware.com

This example is very useful to understand the rasterization of lines.
And with this change, points too.

Adding a key / command-line option to switch modes is left for a future
opportunity though.
---
 src/demos/pixeltest.c | 109 --
 1 file changed, 69 insertions(+), 40 deletions(-)

diff --git a/src/demos/pixeltest.c b/src/demos/pixeltest.c
index 0898290..0b6a580 100644
--- a/src/demos/pixeltest.c
+++ b/src/demos/pixeltest.c
@@ -31,6 +31,10 @@ float width = 1.0f;
 #define SIZE 128/* of non-zoomed drawing region */
 #define ZOOM 32 /* scale factor for zooming */
 
+// TODO: Allow to switch mode via key and/or command-line option.
+//GLenum mode = GL_POINT;
+GLenum mode = GL_LINE;
+
 static GLboolean DrawFront = GL_FALSE;
 GLushort TempImage[SIZE][SIZE]; /* original 128 by 128 pixel image */
 GLushort myImage[SIZE*ZOOM][SIZE*ZOOM]; /* zoom by a factor of 32 */
@@ -168,33 +172,48 @@ drawMagnifiedView(void)
   }
}
   
-   /* Draws the actual line on zoomed version */
-   drawline(X0+APosX-MouseX, Y0+APosY-MouseY, 
-X1+APosX-MouseX, Y1+APosY-MouseY, 0);
-  
-   /* Draws bounding line area */ 
-   if (fabsf(X0 - X1) = 
-   fabsf(Y0 - Y1)) {
-  /* X-MAJOR line */
-  drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
-   X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 0x);
-  drawline(X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 
-   X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
-  drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
-   X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 0x);
-  drawline(X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 
-   X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
-   }
-   else {
-  /* Y-MAJOR line */
-  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
-   X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 0x);
-  drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 
-   X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
-  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
-   X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 0x);
-  drawline(X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 
-   X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
+   switch (mode) {
+   case GL_POINT:
+  /* Draws bounding point area */ 
+  drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY-halfwidth, 
+  X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY-halfwidth, 0x);
+  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY-halfwidth, 
+  X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY+halfwidth, 0x);
+  drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY+halfwidth, 
+  X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY+halfwidth, 0x);
+  drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY+halfwidth, 
+  X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY-halfwidth, 0x);
+  break;
+   case GL_LINE:
+  /* Draws the actual line on zoomed version */
+  drawline(X0+APosX-MouseX, Y0+APosY-MouseY, 
+  X1+APosX-MouseX, Y1+APosY-MouseY, 0);
+
+  /* Draws bounding line area */ 
+  if (fabsf(X0 - X1) = 
+ fabsf(Y0 - Y1)) {
+/* X-MAJOR line */
+drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
+ X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 0x);
+drawline(X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 
+ X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
+drawline(X0+APosX-MouseX, Y0+APosY-MouseY+halfwidth, 
+ X0+APosX-MouseX, Y0+APosY-MouseY-halfwidth, 0x);
+drawline(X1+APosX-MouseX, Y1+APosY-MouseY+halfwidth, 
+ X1+APosX-MouseX, Y1+APosY-MouseY-halfwidth, 0x);
+  }
+  else {
+/* Y-MAJOR line */
+drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
+ X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 0x);
+drawline(X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 
+ X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
+drawline(X0+APosX-MouseX+halfwidth, Y0+APosY-MouseY, 
+ X0+APosX-MouseX-halfwidth, Y0+APosY-MouseY, 0x);
+drawline(X1+APosX-MouseX+halfwidth, Y1+APosY-MouseY, 
+ X1+APosX-MouseX-halfwidth, Y1+APosY-MouseY, 0x);
+  }
+  break;
}
 }
 
@@ -203,11 +222,6 @@ Display( void )
 {
float z = 0;
 
-   printf((%f, %f) - (%f, %f), width = %f\n,
-X0, Y0,
-X1, Y1,
-width);
-
glClearColor(.3, .3, .3, 1);
glClear( GL_COLOR_BUFFER_BIT );

@@ -230,16 +244,31 @@ Display( void )
glVertex3f(150, 0, z);
glEnd();
 
-   /* Original line
+   /* Original geometry
 */
-   glLineWidth(width);
-   glBegin(GL_LINES);
-   

Re: [Mesa-dev] [PATCH 2/2] demos/pixeltest: Adapt the example for points too.

2014-01-08 Thread Erik Faye-Lund
On Wed, Jan 8, 2014 at 6:30 PM,  jfons...@vmware.com wrote:
 From: José Fonseca jfons...@vmware.com

 This example is very useful to understand the rasterization of lines.
 And with this change, points too.

 Adding a key / command-line option to switch modes is left for a future
 opportunity though.
 ---
  src/demos/pixeltest.c | 109 
 --
  1 file changed, 69 insertions(+), 40 deletions(-)

 diff --git a/src/demos/pixeltest.c b/src/demos/pixeltest.c
 index 0898290..0b6a580 100644
 --- a/src/demos/pixeltest.c
 +++ b/src/demos/pixeltest.c
 @@ -31,6 +31,10 @@ float width = 1.0f;
  #define SIZE 128/* of non-zoomed drawing region */
  #define ZOOM 32 /* scale factor for zooming */

 +// TODO: Allow to switch mode via key and/or command-line option.
 +//GLenum mode = GL_POINT;
 +GLenum mode = GL_LINE;
 +

C++/C99 comments in source-file normally using traditional C comments.
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/2] demos/pixeltest: Adapt the example for points too.

2014-01-08 Thread Jose Fonseca


- Original Message -
 On Wed, Jan 8, 2014 at 6:30 PM,  jfons...@vmware.com wrote:
  From: José Fonseca jfons...@vmware.com
 
  This example is very useful to understand the rasterization of lines.
  And with this change, points too.
 
  Adding a key / command-line option to switch modes is left for a future
  opportunity though.
  ---
   src/demos/pixeltest.c | 109
   --
   1 file changed, 69 insertions(+), 40 deletions(-)
 
  diff --git a/src/demos/pixeltest.c b/src/demos/pixeltest.c
  index 0898290..0b6a580 100644
  --- a/src/demos/pixeltest.c
  +++ b/src/demos/pixeltest.c
  @@ -31,6 +31,10 @@ float width = 1.0f;
   #define SIZE 128/* of non-zoomed drawing region */
   #define ZOOM 32 /* scale factor for zooming */
 
  +// TODO: Allow to switch mode via key and/or command-line option.
  +//GLenum mode = GL_POINT;
  +GLenum mode = GL_LINE;
  +
 
 C++/C99 comments in source-file normally using traditional C comments
 

I don't think we are following that rule:

  $ cd mesa/demos
  $ grep -R '^\s\+\/\/' --include '*.c' src/ | wc -l
  91

Anyway I'll fix before commit, as below.

Jose


diff --git a/src/demos/pixeltest.c b/src/demos/pixeltest.c
index 0b6a580..0348daa 100644
--- a/src/demos/pixeltest.c
+++ b/src/demos/pixeltest.c
@@ -31,9 +31,12 @@ float width = 1.0f;
 #define SIZE 128/* of non-zoomed drawing region */
 #define ZOOM 32 /* scale factor for zooming */
 
-// TODO: Allow to switch mode via key and/or command-line option.
-//GLenum mode = GL_POINT;
+/* TODO: Allow to switch mode via key and/or command-line option. */
+#if 0
+GLenum mode = GL_POINT;
+#else
 GLenum mode = GL_LINE;
+#endif
 
 static GLboolean DrawFront = GL_FALSE;
 GLushort TempImage[SIZE][SIZE]; /* original 128 by 128 pixel image */
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 2/2] demos/pixeltest: Adapt the example for points too.

2014-01-08 Thread Brian Paul

On 01/08/2014 10:30 AM, jfons...@vmware.com wrote:

From: José Fonseca jfons...@vmware.com

This example is very useful to understand the rasterization of lines.
And with this change, points too.

Adding a key / command-line option to switch modes is left for a future
opportunity though.


For both:
Reviewed-by: Brian Paul bri...@vmware.com

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev