summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian <brian.paul@tungstengraphics.com>2007-11-23 16:19:25 -0700
committerBrian <brian.paul@tungstengraphics.com>2007-11-23 16:19:25 -0700
commitbe1fa5b3d706a336e6719248e51d98f4bf21644d (patch)
tree6c76abd5314f3e8d3aed3f7338410ff258e291b1
parent88b067cb040b42e774733959545f19ad780c873b (diff)
better test of point attenuation
-rw-r--r--progs/trivial/point-param.c56
1 files changed, 33 insertions, 23 deletions
diff --git a/progs/trivial/point-param.c b/progs/trivial/point-param.c
index 520bca9ea2..02500cd34e 100644
--- a/progs/trivial/point-param.c
+++ b/progs/trivial/point-param.c
@@ -23,15 +23,13 @@
*/
#define GL_GLEXT_PROTOTYPES
+#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <GL/glut.h>
-#define CI_OFFSET_1 16
-#define CI_OFFSET_2 32
-
GLenum doubleBuffer;
@@ -41,53 +39,63 @@ static void Init(void)
fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
- glClearColor(0.0, 0.0, 1.0, 0.0);
+ glClearColor(0.0, 0.0, 1.0, 0.0);
}
static void Reshape(int width, int height)
{
-
glViewport(0, 0, (GLint)width, (GLint)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
+ glOrtho(-1.0, 1.0, -1.0, 1.0, 0, 100.0);
glMatrixMode(GL_MODELVIEW);
}
static void Key(unsigned char key, int x, int y)
{
-
switch (key) {
- case 27:
+ case 27:
exit(1);
- default:
+ default:
return;
}
-
glutPostRedisplay();
}
+
+static float
+expected(float z, float size, const float atten[3])
+{
+ float dist = fabs(z);
+ const GLfloat q = atten[0] + dist * (atten[1] + dist * atten[2]);
+ const GLfloat a = sqrt(1.0 / q);
+ return size * a;
+}
+
+
static void Draw(void)
{
- static GLfloat theQuad[3] = { 0.25, 0.0, 1/60.0 };
+ static GLfloat atten[3] = { 0.0, 0.1, .01 };
+ float size = 40.0;
+ int i;
glClear(GL_COLOR_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glPointSize(8.0);
- glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad);
+ glPointSize(size);
+ glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, atten);
+ glColor3f(1,0,0);
+ printf("Expected point sizes:\n");
glBegin(GL_POINTS);
- glColor3f(1,0,0);
- glVertex3f( 0.9, -0.9, -30.0);
- glColor3f(1,1,0);
- glVertex3f( 0.9, 0.9, -30.0);
- glColor3f(1,0,1);
- glVertex3f(-0.9, 0.9, -30.0);
- glColor3f(0,1,1);
- glVertex3f(-0.9, -0.9, -30.0);
+ for (i = 0; i < 5; i++) {
+ float x = -0.8 + i * 0.4;
+ float z = -i * 20 - 10;
+ glVertex3f( x, 0.0, z);
+ printf(" %f\n", expected(z, size, atten));
+ }
glEnd();
glFlush();
@@ -97,6 +105,7 @@ static void Draw(void)
}
}
+
static GLenum Args(int argc, char **argv)
{
GLint i;
@@ -116,6 +125,7 @@ static GLenum Args(int argc, char **argv)
return GL_TRUE;
}
+
int main(int argc, char **argv)
{
GLenum type;
@@ -132,7 +142,7 @@ int main(int argc, char **argv)
type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
glutInitDisplayMode(type);
- if (glutCreateWindow("First Tri") == GL_FALSE) {
+ if (glutCreateWindow(argv[0]) == GL_FALSE) {
exit(1);
}
@@ -142,5 +152,5 @@ int main(int argc, char **argv)
glutKeyboardFunc(Key);
glutDisplayFunc(Draw);
glutMainLoop();
- return 0;
+ return 0;
}