X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=progs%2Fdemos%2Ffslight.c;h=f0d76a4a06fb50de4ec40ba530cf4c3bf179b229;hb=7e7f0f61bf41bccfdd0f68afc03ccc6b1d3c0c91;hp=2fa25a0adf46a8ae38c8725342e79f16565a06d5;hpb=2cf5fd48d1586f961910a14324a457854cb66221;p=mesa.git diff --git a/progs/demos/fslight.c b/progs/demos/fslight.c index 2fa25a0adf4..f0d76a4a06f 100644 --- a/progs/demos/fslight.c +++ b/progs/demos/fslight.c @@ -23,6 +23,8 @@ #include "extfuncs.h" +#define TEXTURE 0 + static GLint CoordAttrib = 0; static char *FragProgFile = NULL; @@ -43,7 +45,7 @@ static GLint uTexture; static GLuint SphereList, RectList, CurList; static GLint win = 0; -static GLboolean anim = GL_FALSE; +static GLboolean anim = GL_TRUE; static GLboolean wire = GL_FALSE; static GLboolean pixelLight = GL_TRUE; @@ -56,7 +58,7 @@ static GLfloat xRot = 90.0f, yRot = 0.0f; static void normalize(GLfloat *dst, const GLfloat *src) { - GLfloat len = sqrtf(src[0] * src[0] + src[1] * src[1] + src[2] * src[2]); + GLfloat len = sqrt(src[0] * src[0] + src[1] * src[1] + src[2] * src[2]); dst[0] = src[0] / len; dst[1] = src[1] / len; dst[2] = src[2] / len; @@ -103,6 +105,7 @@ Redisplay(void) GLfloat fps = frames / seconds; printf("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + fflush(stdout); t0 = t; frames = 0; } @@ -223,33 +226,6 @@ static void TestFunctions(void) { printf("Error 0x%x at line %d\n", glGetError(), __LINE__); - { - GLfloat pos[3]; - printf("Error 0x%x at line %d\n", glGetError(), __LINE__); - printf("Light pos %g %g %g\n", pos[0], pos[1], pos[2]); - } - - - { - GLfloat m[16], result[16]; - GLint mPos; - int i; - - for (i = 0; i < 16; i++) - m[i] = (float) i; - - mPos = glGetUniformLocation_func(program, "m"); - printf("Error 0x%x at line %d\n", glGetError(), __LINE__); - glUniformMatrix4fv_func(mPos, 1, GL_FALSE, m); - printf("Error 0x%x at line %d\n", glGetError(), __LINE__); - - glGetUniformfv_func(program, mPos, result); - printf("Error 0x%x at line %d\n", glGetError(), __LINE__); - - for (i = 0; i < 16; i++) { - printf("%8g %8g\n", m[i], result[i]); - } - } assert(glIsProgram_func(program)); assert(glIsShader_func(fragShader)); @@ -278,14 +254,31 @@ TestFunctions(void) glGetProgramInfoLog_func(program, 1000, &len, log); printf("Program Info Log: %s\n", log); } + + /* active uniforms */ + { + GLint n, max, i; + glGetProgramiv_func(program, GL_ACTIVE_UNIFORMS, &n); + glGetProgramiv_func(program, GL_ACTIVE_UNIFORM_MAX_LENGTH, &max); + printf("Num uniforms: %d Max name length: %d\n", n, max); + for (i = 0; i < n; i++) { + GLint size, len; + GLenum type; + char name[100]; + glGetActiveUniform_func(program, i, 100, &len, &size, &type, name); + printf(" %d: %s nameLen=%d size=%d type=0x%x\n", + i, name, len, size, type); + } + } } +#if TEXTURE static void MakeTexture(void) { -#define SZ0 128 -#define SZ1 64 +#define SZ0 64 +#define SZ1 32 GLubyte image0[SZ0][SZ0][SZ0][4]; GLubyte image1[SZ1][SZ1][SZ1][4]; GLuint i, j, k; @@ -348,6 +341,7 @@ MakeTexture(void) glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); } +#endif static void @@ -473,8 +467,8 @@ Init(void) version = (const char *) glGetString(GL_VERSION); if (version[0] != '2' || version[1] != '.') { - printf("Warning: this program expects OpenGL 2.0\n"); - /*exit(1);*/ + printf("This program requires OpenGL 2.x, found %s\n", version); + exit(1); } GetExtensionFuncs(); @@ -507,8 +501,10 @@ Init(void) glUniform4fv_func(uDiffuse, 1, diffuse); glUniform4fv_func(uSpecular, 1, specular); - assert(glGetError() == 0); + /* assert(glGetError() == 0);*/ +#if TEXTURE glUniform1i_func(uTexture, 2); /* use texture unit 2 */ +#endif /*assert(glGetError() == 0);*/ if (CoordAttrib) { @@ -540,7 +536,9 @@ Init(void) CurList = SphereList; +#if TEXTURE MakeTexture(); +#endif printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); printf("Press p to toggle between per-pixel and per-vertex lighting\n"); @@ -573,6 +571,8 @@ Init(void) #if 0 TestFunctions(); +#else + (void) TestFunctions; #endif } @@ -583,10 +583,14 @@ ParseOptions(int argc, char *argv[]) int i; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-fs") == 0) { - FragProgFile = argv[i+1]; + FragProgFile = argv[++i]; } else if (strcmp(argv[i], "-vs") == 0) { - VertProgFile = argv[i+1]; + VertProgFile = argv[++i]; + } + else { + fprintf(stderr, "unknown option %s\n", argv[i]); + break; } } } @@ -597,7 +601,7 @@ main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitWindowPosition( 0, 0); - glutInitWindowSize(100, 100); + glutInitWindowSize(200, 200); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); win = glutCreateWindow(argv[0]); glutReshapeFunc(Reshape);