From 08a1e1ebcb612dfa9172f04e4644b34d95ec7dac Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 9 Apr 2009 17:04:58 -0600 Subject: demos: fix aspect ratio in Reshape() --- progs/glsl/bump.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/glsl/bump.c b/progs/glsl/bump.c index b93ab44b5b..0ea1f8331f 100644 --- a/progs/glsl/bump.c +++ b/progs/glsl/bump.c @@ -150,10 +150,11 @@ Redisplay(void) static void Reshape(int width, int height) { + float ar = (float) width / (float) height; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -15.0f); -- cgit v1.2.3 From f8f4b03442fea4f159d2a536bf2311ecb305cd51 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 10 Apr 2009 13:08:57 +0100 Subject: progs: Port glxinfo to wgl. --- progs/wgl/SConscript | 2 + progs/wgl/wglinfo.c | 737 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 739 insertions(+) create mode 100644 progs/wgl/wglinfo.c (limited to 'progs') diff --git a/progs/wgl/SConscript b/progs/wgl/SConscript index b7cf35b7fc..31f61676de 100644 --- a/progs/wgl/SConscript +++ b/progs/wgl/SConscript @@ -21,3 +21,5 @@ for prog in progs: target = prog, source = prog + '/' + prog + '.c', ) + +env.Program('wglinfo', ['wglinfo.c']) diff --git a/progs/wgl/wglinfo.c b/progs/wgl/wglinfo.c new file mode 100644 index 0000000000..5cf0e8bb25 --- /dev/null +++ b/progs/wgl/wglinfo.c @@ -0,0 +1,737 @@ +/* + * Copyright (C) 2009 VMware, Inc. + * Copyright (C) 1999-2006 Brian Paul + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * This program is a work-alike of the GLX glxinfo program. + * Command line options: + * -t print wide table + * -v print verbose information + * -b only print ID of "best" visual on screen 0 + * -l print interesting OpenGL limits (added 5 Sep 2002) + */ + +#include + +#include +#include +#include +#include +#include +#include + + +typedef enum +{ + Normal, + Wide, + Verbose +} InfoMode; + + +/* + * Print a list of extensions, with word-wrapping. + */ +static void +print_extension_list(const char *ext) +{ + const char *indentString = " "; + const int indent = 4; + const int max = 79; + int width, i, j; + + if (!ext || !ext[0]) + return; + + width = indent; + printf(indentString); + i = j = 0; + while (1) { + if (ext[j] == ' ' || ext[j] == 0) { + /* found end of an extension name */ + const int len = j - i; + if (width + len > max) { + /* start a new line */ + printf("\n"); + width = indent; + printf(indentString); + } + /* print the extension name between ext[i] and ext[j] */ + while (i < j) { + printf("%c", ext[i]); + i++; + } + /* either we're all done, or we'll continue with next extension */ + width += len + 1; + if (ext[j] == 0) { + break; + } + else { + i++; + j++; + if (ext[j] == 0) + break; + printf(", "); + width += 2; + } + } + j++; + } + printf("\n"); +} + + +/** + * Print interesting limits for vertex/fragment programs. + */ +static void +print_program_limits(GLenum target) +{ +#if defined(GL_ARB_vertex_program) || defined(GL_ARB_fragment_program) + struct token_name { + GLenum token; + const char *name; + }; + static const struct token_name limits[] = { + { GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEMPORARIES_ARB, "GL_MAX_PROGRAM_TEMPORARIES_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB" }, + { GL_MAX_PROGRAM_PARAMETERS_ARB, "GL_MAX_PROGRAM_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ATTRIBS_ARB, "GL_MAX_PROGRAM_ATTRIBS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB" }, + { GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB, "GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB" }, + { GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "GL_MAX_PROGRAM_ENV_PARAMETERS_ARB" }, + { GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB" }, + { GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB" }, + { (GLenum) 0, NULL } + }; + PFNGLGETPROGRAMIVARBPROC GetProgramivARB_func = (PFNGLGETPROGRAMIVARBPROC) + wglGetProcAddress("glGetProgramivARB"); + GLint max[1]; + int i; + + if (target == GL_VERTEX_PROGRAM_ARB) { + printf(" GL_VERTEX_PROGRAM_ARB:\n"); + } + else if (target == GL_FRAGMENT_PROGRAM_ARB) { + printf(" GL_FRAGMENT_PROGRAM_ARB:\n"); + } + else { + return; /* something's wrong */ + } + + for (i = 0; limits[i].token; i++) { + GetProgramivARB_func(target, limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", limits[i].name, max[0]); + } + } +#endif /* GL_ARB_vertex_program / GL_ARB_fragment_program */ +} + + +/** + * Print interesting limits for vertex/fragment shaders. + */ +static void +print_shader_limits(GLenum target) +{ + struct token_name { + GLenum token; + const char *name; + }; +#if defined(GL_ARB_vertex_shader) + static const struct token_name vertex_limits[] = { + { GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, "GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB" }, + { GL_MAX_VARYING_FLOATS_ARB, "GL_MAX_VARYING_FLOATS_ARB" }, + { GL_MAX_VERTEX_ATTRIBS_ARB, "GL_MAX_VERTEX_ATTRIBS_ARB" }, + { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB" }, + { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" }, + { (GLenum) 0, NULL } + }; +#endif +#if defined(GL_ARB_fragment_shader) + static const struct token_name fragment_limits[] = { + { GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, "GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB" }, + { GL_MAX_TEXTURE_COORDS_ARB, "GL_MAX_TEXTURE_COORDS_ARB" }, + { GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "GL_MAX_TEXTURE_IMAGE_UNITS_ARB" }, + { (GLenum) 0, NULL } + }; +#endif + GLint max[1]; + int i; + +#if defined(GL_ARB_vertex_shader) + if (target == GL_VERTEX_SHADER_ARB) { + printf(" GL_VERTEX_SHADER_ARB:\n"); + for (i = 0; vertex_limits[i].token; i++) { + glGetIntegerv(vertex_limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", vertex_limits[i].name, max[0]); + } + } + } +#endif +#if defined(GL_ARB_fragment_shader) + if (target == GL_FRAGMENT_SHADER_ARB) { + printf(" GL_FRAGMENT_SHADER_ARB:\n"); + for (i = 0; fragment_limits[i].token; i++) { + glGetIntegerv(fragment_limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + printf(" %s = %d\n", fragment_limits[i].name, max[0]); + } + } + } +#endif +} + + +/** + * Print interesting OpenGL implementation limits. + */ +static void +print_limits(const char *extensions) +{ + struct token_name { + GLuint count; + GLenum token; + const char *name; + }; + static const struct token_name limits[] = { + { 1, GL_MAX_ATTRIB_STACK_DEPTH, "GL_MAX_ATTRIB_STACK_DEPTH" }, + { 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "GL_MAX_CLIENT_ATTRIB_STACK_DEPTH" }, + { 1, GL_MAX_CLIP_PLANES, "GL_MAX_CLIP_PLANES" }, + { 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "GL_MAX_COLOR_MATRIX_STACK_DEPTH" }, + { 1, GL_MAX_ELEMENTS_VERTICES, "GL_MAX_ELEMENTS_VERTICES" }, + { 1, GL_MAX_ELEMENTS_INDICES, "GL_MAX_ELEMENTS_INDICES" }, + { 1, GL_MAX_EVAL_ORDER, "GL_MAX_EVAL_ORDER" }, + { 1, GL_MAX_LIGHTS, "GL_MAX_LIGHTS" }, + { 1, GL_MAX_LIST_NESTING, "GL_MAX_LIST_NESTING" }, + { 1, GL_MAX_MODELVIEW_STACK_DEPTH, "GL_MAX_MODELVIEW_STACK_DEPTH" }, + { 1, GL_MAX_NAME_STACK_DEPTH, "GL_MAX_NAME_STACK_DEPTH" }, + { 1, GL_MAX_PIXEL_MAP_TABLE, "GL_MAX_PIXEL_MAP_TABLE" }, + { 1, GL_MAX_PROJECTION_STACK_DEPTH, "GL_MAX_PROJECTION_STACK_DEPTH" }, + { 1, GL_MAX_TEXTURE_STACK_DEPTH, "GL_MAX_TEXTURE_STACK_DEPTH" }, + { 1, GL_MAX_TEXTURE_SIZE, "GL_MAX_TEXTURE_SIZE" }, + { 1, GL_MAX_3D_TEXTURE_SIZE, "GL_MAX_3D_TEXTURE_SIZE" }, + { 2, GL_MAX_VIEWPORT_DIMS, "GL_MAX_VIEWPORT_DIMS" }, + { 2, GL_ALIASED_LINE_WIDTH_RANGE, "GL_ALIASED_LINE_WIDTH_RANGE" }, + { 2, GL_SMOOTH_LINE_WIDTH_RANGE, "GL_SMOOTH_LINE_WIDTH_RANGE" }, + { 2, GL_ALIASED_POINT_SIZE_RANGE, "GL_ALIASED_POINT_SIZE_RANGE" }, + { 2, GL_SMOOTH_POINT_SIZE_RANGE, "GL_SMOOTH_POINT_SIZE_RANGE" }, +#if defined(GL_ARB_texture_cube_map) + { 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, "GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB" }, +#endif +#if defined(GLX_NV_texture_rectangle) + { 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, "GL_MAX_RECTANGLE_TEXTURE_SIZE_NV" }, +#endif +#if defined(GL_ARB_texture_compression) + { 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, "GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB" }, +#endif +#if defined(GL_ARB_multitexture) + { 1, GL_MAX_TEXTURE_UNITS_ARB, "GL_MAX_TEXTURE_UNITS_ARB" }, +#endif +#if defined(GL_EXT_texture_lod_bias) + { 1, GL_MAX_TEXTURE_LOD_BIAS_EXT, "GL_MAX_TEXTURE_LOD_BIAS_EXT" }, +#endif +#if defined(GL_EXT_texture_filter_anisotropic) + { 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, "GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT" }, +#endif +#if defined(GL_ARB_draw_buffers) + { 1, GL_MAX_DRAW_BUFFERS_ARB, "GL_MAX_DRAW_BUFFERS_ARB" }, +#endif + { 0, (GLenum) 0, NULL } + }; + GLint i, max[2]; + + printf("OpenGL limits:\n"); + for (i = 0; limits[i].count; i++) { + glGetIntegerv(limits[i].token, max); + if (glGetError() == GL_NO_ERROR) { + if (limits[i].count == 1) + printf(" %s = %d\n", limits[i].name, max[0]); + else /* XXX fix if we ever query something with more than 2 values */ + printf(" %s = %d, %d\n", limits[i].name, max[0], max[1]); + } + } + +#if defined(GL_EXT_convolution) + { + PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC glGetConvolutionParameterivEXT_func = + (PFNGLGETCONVOLUTIONPARAMETERIVEXTPROC)wglGetProcAddress("glGetConvolutionParameterivEXT"); + if(glGetConvolutionParameterivEXT_func) { + /* these don't fit into the above mechanism, unfortunately */ + glGetConvolutionParameterivEXT_func(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_WIDTH, max); + glGetConvolutionParameterivEXT_func(GL_CONVOLUTION_2D, GL_MAX_CONVOLUTION_HEIGHT, max+1); + if (glGetError() == GL_NONE) { + printf(" GL_MAX_CONVOLUTION_WIDTH/HEIGHT = %d, %d\n", max[0], max[1]); + } + } + } +#endif + +#if defined(GL_ARB_vertex_program) + if (strstr(extensions, "GL_ARB_vertex_program")) { + print_program_limits(GL_VERTEX_PROGRAM_ARB); + } +#endif +#if defined(GL_ARB_fragment_program) + if (strstr(extensions, "GL_ARB_fragment_program")) { + print_program_limits(GL_FRAGMENT_PROGRAM_ARB); + } +#endif +#if defined(GL_ARB_vertex_shader) + if (strstr(extensions, "GL_ARB_vertex_shader")) { + print_shader_limits(GL_VERTEX_SHADER_ARB); + } +#endif +#if defined(GL_ARB_fragment_shader) + if (strstr(extensions, "GL_ARB_fragment_shader")) { + print_shader_limits(GL_FRAGMENT_SHADER_ARB); + } +#endif +} + + +static LRESULT CALLBACK +WndProc(HWND hWnd, + UINT uMsg, + WPARAM wParam, + LPARAM lParam ) +{ + switch (uMsg) { + case WM_DESTROY: + PostQuitMessage(0); + break; + default: + return DefWindowProc(hWnd, uMsg, wParam, lParam); + } + + return 0; +} + + +static void +print_screen_info(HDC _hdc, GLboolean limits) +{ + WNDCLASS wc; + HWND win; + HGLRC ctx; + int visinfo; + int width = 100, height = 100; + HDC hdc; + PIXELFORMATDESCRIPTOR pfd; + + memset(&wc, 0, sizeof wc); + wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); + wc.hCursor = LoadCursor(NULL, IDC_ARROW); + wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); + wc.lpfnWndProc = WndProc; + wc.lpszClassName = "wglinfo"; + wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; + RegisterClass(&wc); + + win = CreateWindowEx(0, + wc.lpszClassName, + "wglinfo", + WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + CW_USEDEFAULT, + CW_USEDEFAULT, + width, + height, + NULL, + NULL, + wc.hInstance, + NULL); + if (!win) { + fprintf(stderr, "Couldn't create window"); + exit(1); + } + + hdc = GetDC(win); + if (!hdc) { + fprintf(stderr, "Couldn't obtain HDC"); + return; + } + + pfd.cColorBits = 3; + pfd.cRedBits = 1; + pfd.cGreenBits = 1; + pfd.cBlueBits = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; + pfd.iLayerType = PFD_MAIN_PLANE; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.nSize = sizeof(pfd); + pfd.nVersion = 1; + + visinfo = ChoosePixelFormat(hdc, &pfd); + if (!visinfo) { + pfd.dwFlags |= PFD_DOUBLEBUFFER; + visinfo = ChoosePixelFormat(hdc, &pfd); + } + + if (!visinfo) { + fprintf(stderr, "Error: couldn't find RGB WGL visual\n"); + return; + } + + SetPixelFormat(hdc, visinfo, &pfd); + ctx = wglCreateContext(hdc); + if (!ctx) { + fprintf(stderr, "Error: wglCreateContext failed\n"); + return; + } + + if (wglMakeCurrent(hdc, ctx)) { +#if defined(WGL_ARB_extensions_string) + PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB_func = + (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB"); +#endif + const char *glVendor = (const char *) glGetString(GL_VENDOR); + const char *glRenderer = (const char *) glGetString(GL_RENDERER); + const char *glVersion = (const char *) glGetString(GL_VERSION); + const char *glExtensions = (const char *) glGetString(GL_EXTENSIONS); + +#if defined(WGL_ARB_extensions_string) + if(wglGetExtensionsStringARB_func) { + const char *wglExtensions = wglGetExtensionsStringARB_func(hdc); + if(wglExtensions) { + printf("WGL extensions:\n"); + print_extension_list(wglExtensions); + } + } +#endif + printf("OpenGL vendor string: %s\n", glVendor); + printf("OpenGL renderer string: %s\n", glRenderer); + printf("OpenGL version string: %s\n", glVersion); +#ifdef GL_VERSION_2_0 + if (glVersion[0] >= '2' && glVersion[1] == '.') { + char *v = (char *) glGetString(GL_SHADING_LANGUAGE_VERSION); + printf("OpenGL shading language version string: %s\n", v); + } +#endif + + printf("OpenGL extensions:\n"); + print_extension_list(glExtensions); + if (limits) + print_limits(glExtensions); + } + else { + fprintf(stderr, "Error: wglMakeCurrent failed\n"); + } + + DestroyWindow(win); +} + + +static const char * +visual_render_type_name(BYTE iPixelType) +{ + switch (iPixelType) { + case PFD_TYPE_RGBA: + return "rgba"; + case PFD_TYPE_COLORINDEX: + return "ci"; + default: + return ""; + } +} + +static void +print_visual_attribs_verbose(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd) +{ + printf("Visual ID: %x generic=%d native=%d\n", + iPixelFormat, + ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0, + ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0); + printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", + 0 /* ppfd->bufferSize */, 0 /* ppfd->level */, + visual_render_type_name(ppfd->dwFlags), + ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0, + ppfd->dwFlags & PFD_STEREO ? 1 : 0); + printf(" rgba: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n", + ppfd->cRedBits, ppfd->cGreenBits, + ppfd->cBlueBits, ppfd->cAlphaBits); + printf(" cAuxBuffers=%d cDepthBits=%d cStencilBits=%d\n", + ppfd->cAuxBuffers, ppfd->cDepthBits, ppfd->cStencilBits); + printf(" accum: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n", + ppfd->cAccumRedBits, ppfd->cAccumGreenBits, + ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits); + printf(" multiSample=%d multiSampleBuffers=%d\n", + 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */); +} + + +static void +print_visual_attribs_short_header(void) +{ + printf(" visual x bf lv rg d st colorbuffer ax dp st accumbuffer ms cav\n"); + printf(" id gen nat sp sz l ci b ro r g b a bf th cl r g b a ns b eat\n"); + printf("-----------------------------------------------------------------------\n"); +} + + +static void +print_visual_attribs_short(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd) +{ + char *caveat = "None"; + + printf("0x%02x %2d %2d %2d %2d %2d %c%c %c %c %2d %2d %2d %2d %2d %2d %2d", + iPixelFormat, + ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0, + ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0, + 0, + 0 /* ppfd->bufferSize */, + 0 /* ppfd->level */, + ppfd->iPixelType == PFD_TYPE_RGBA ? 'r' : ' ', + ppfd->iPixelType == PFD_TYPE_COLORINDEX ? 'c' : ' ', + ppfd->dwFlags & PFD_DOUBLEBUFFER ? 'y' : '.', + ppfd->dwFlags & PFD_STEREO ? 'y' : '.', + ppfd->cRedBits, ppfd->cGreenBits, + ppfd->cBlueBits, ppfd->cAlphaBits, + ppfd->cAuxBuffers, + ppfd->cDepthBits, + ppfd->cStencilBits + ); + + printf(" %2d %2d %2d %2d %2d %1d %s\n", + ppfd->cAccumRedBits, ppfd->cAccumGreenBits, + ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits, + 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */, + caveat + ); +} + + +static void +print_visual_attribs_long_header(void) +{ + printf("Vis Vis Visual Trans buff lev render DB ste r g b a aux dep ste accum buffers MS MS\n"); + printf(" ID Depth Type parent size el type reo sz sz sz sz buf th ncl r g b a num bufs\n"); + printf("----------------------------------------------------------------------------------------------------\n"); +} + + +static void +print_visual_attribs_long(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd) +{ + printf("0x%2x %2d %11d %2d %2d %2d %4s %3d %3d %3d %3d %3d %3d", + iPixelFormat, + ppfd->dwFlags & PFD_GENERIC_FORMAT ? 1 : 0, + ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0, + 0, + 0 /* ppfd->bufferSize */, + 0 /* ppfd->level */, + visual_render_type_name(ppfd->iPixelType), + ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0, + ppfd->dwFlags & PFD_STEREO ? 1 : 0, + ppfd->cRedBits, ppfd->cGreenBits, + ppfd->cBlueBits, ppfd->cAlphaBits + ); + + printf(" %3d %4d %2d %3d %3d %3d %3d %2d %2d\n", + ppfd->cAuxBuffers, + ppfd->cDepthBits, + ppfd->cStencilBits, + ppfd->cAccumRedBits, ppfd->cAccumGreenBits, + ppfd->cAccumBlueBits, ppfd->cAccumAlphaBits, + 0 /* ppfd->numSamples */, 0 /* ppfd->numMultisample */ + ); +} + + +static void +print_visual_info(HDC hdc, InfoMode mode) +{ + PIXELFORMATDESCRIPTOR pfd; + int numVisuals, numWglVisuals; + int i; + + numVisuals = DescribePixelFormat(hdc, 1, sizeof(PIXELFORMATDESCRIPTOR), NULL); + if (numVisuals == 0) + return; + + numWglVisuals = 0; + for (i = 0; i < numVisuals; i++) { + if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) + continue; + + if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) + continue; + + ++numWglVisuals; + } + + printf("%d WGL Visuals\n", numWglVisuals); + + if (mode == Normal) + print_visual_attribs_short_header(); + else if (mode == Wide) + print_visual_attribs_long_header(); + + for (i = 0; i < numVisuals; i++) { + if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) + continue; + + if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) + continue; + + if (mode == Verbose) + print_visual_attribs_verbose(i, &pfd); + else if (mode == Normal) + print_visual_attribs_short(i, &pfd); + else if (mode == Wide) + print_visual_attribs_long(i, &pfd); + } + printf("\n"); +} + + +/* + * Examine all visuals to find the so-called best one. + * We prefer deepest RGBA buffer with depth, stencil and accum + * that has no caveats. + */ +static int +find_best_visual(HDC hdc) +{ +#if 0 + XVisualInfo theTemplate; + XVisualInfo *visuals; + int numVisuals; + long mask; + int i; + struct visual_attribs bestVis; + + /* get list of all visuals on this screen */ + theTemplate.screen = scrnum; + mask = VisualScreenMask; + visuals = XGetVisualInfo(hdc, mask, &theTemplate, &numVisuals); + + /* init bestVis with first visual info */ + get_visual_attribs(hdc, &visuals[0], &bestVis); + + /* try to find a "better" visual */ + for (i = 1; i < numVisuals; i++) { + struct visual_attribs vis; + + get_visual_attribs(hdc, &visuals[i], &vis); + + /* always skip visuals with caveats */ + if (vis.visualCaveat != GLX_NONE_EXT) + continue; + + /* see if this vis is better than bestVis */ + if ((!bestVis.supportsGL && vis.supportsGL) || + (bestVis.visualCaveat != GLX_NONE_EXT) || + (bestVis.iPixelType != vis.iPixelType) || + (!bestVis.doubleBuffer && vis.doubleBuffer) || + (bestVis.cRedBits < vis.cRedBits) || + (bestVis.cGreenBits < vis.cGreenBits) || + (bestVis.cBlueBits < vis.cBlueBits) || + (bestVis.cAlphaBits < vis.cAlphaBits) || + (bestVis.cDepthBits < vis.cDepthBits) || + (bestVis.cStencilBits < vis.cStencilBits) || + (bestVis.cAccumRedBits < vis.cAccumRedBits)) { + /* found a better visual */ + bestVis = vis; + } + } + + return bestVis.id; +#else + return 0; +#endif +} + + +static void +usage(void) +{ + printf("Usage: glxinfo [-v] [-t] [-h] [-i] [-b] [-display ]\n"); + printf("\t-v: Print visuals info in verbose form.\n"); + printf("\t-t: Print verbose table.\n"); + printf("\t-h: This information.\n"); + printf("\t-b: Find the 'best' visual and print it's number.\n"); + printf("\t-l: Print interesting OpenGL limits.\n"); +} + + +int +main(int argc, char *argv[]) +{ + HDC hdc; + InfoMode mode = Normal; + GLboolean findBest = GL_FALSE; + GLboolean limits = GL_FALSE; + int i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-t") == 0) { + mode = Wide; + } + else if (strcmp(argv[i], "-v") == 0) { + mode = Verbose; + } + else if (strcmp(argv[i], "-b") == 0) { + findBest = GL_TRUE; + } + else if (strcmp(argv[i], "-l") == 0) { + limits = GL_TRUE; + } + else if (strcmp(argv[i], "-h") == 0) { + usage(); + return 0; + } + else { + printf("Unknown option `%s'\n", argv[i]); + usage(); + return 0; + } + } + + hdc = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL); + + if (findBest) { + int b; + b = find_best_visual(hdc); + printf("%d\n", b); + } + else { + print_screen_info(hdc, limits); + printf("\n"); + print_visual_info(hdc, mode); + } + + return 0; +} -- cgit v1.2.3 From d60b4f7885d88fc868c3af2ba661cd79c907af7f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 10 Apr 2009 08:56:03 -0600 Subject: mesa: asst. progs/test/Makefile files --- progs/tests/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'progs') diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 58ea5690df..90c41a327e 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -201,10 +201,10 @@ fillrate.o: fillrate.c readtex.h floattex: floattex.o readtex.o shaderutil.o - $(CC) $(CFLAGS) $(LDFLAGS) floattex.o readtex.o shaderutil.o $(LIBS) -o $@ + $(APP_CC) $(CFLAGS) $(LDFLAGS) floattex.o readtex.o shaderutil.o $(LIBS) -o $@ floattex.o: floattex.c readtex.h shaderutil.h - $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) floattex.c -o $@ + $(APP_CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) floattex.c -o $@ readtex.o: readtex.c @@ -230,7 +230,7 @@ shaderutil.h: $(TOP)/progs/util/shaderutil.h cp $< . shaderutil.o: shaderutil.c shaderutil.h - $(CC) -c -I$(INCDIR) $(CFLAGS) shaderutil.c + $(APP_CC) -c -I$(INCDIR) $(INCLUDES) $(CFLAGS) shaderutil.c -- cgit v1.2.3 From 6fc244c68d3b3a9f89b6f752725e6c768cb08a84 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Fri, 10 Apr 2009 18:43:51 +0100 Subject: wgl: Note down the gallium pixel formats, instead of re-guessing them. --- progs/wgl/wglinfo.c | 8 +- .../state_trackers/wgl/shared/stw_context.c | 3 +- .../state_trackers/wgl/shared/stw_context.h | 2 + .../state_trackers/wgl/shared/stw_framebuffer.c | 94 +++------------------- .../state_trackers/wgl/shared/stw_framebuffer.h | 3 + .../state_trackers/wgl/shared/stw_pixelformat.c | 12 +++ .../state_trackers/wgl/shared/stw_pixelformat.h | 4 + 7 files changed, 38 insertions(+), 88 deletions(-) (limited to 'progs') diff --git a/progs/wgl/wglinfo.c b/progs/wgl/wglinfo.c index 5cf0e8bb25..881d35b297 100644 --- a/progs/wgl/wglinfo.c +++ b/progs/wgl/wglinfo.c @@ -586,8 +586,8 @@ print_visual_info(HDC hdc, InfoMode mode) if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) continue; - if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) - continue; + //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) + // continue; ++numWglVisuals; } @@ -603,8 +603,8 @@ print_visual_info(HDC hdc, InfoMode mode) if(!DescribePixelFormat(hdc, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd)) continue; - if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) - continue; + //if(!(pfd.dwFlags & PFD_SUPPORT_OPENGL)) + // continue; if (mode == Verbose) print_visual_attribs_verbose(i, &pfd); diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.c b/src/gallium/state_trackers/wgl/shared/stw_context.c index e6bb8e1847..1e3bf10317 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.c +++ b/src/gallium/state_trackers/wgl/shared/stw_context.c @@ -153,6 +153,7 @@ stw_create_layer_context( goto fail; ctx->st->ctx->DriverCtx = ctx; + ctx->pfi = pf; pipe_mutex_lock( stw_dev->mutex ); hglrc = handle_table_add(stw_dev->ctx_table, ctx); @@ -330,7 +331,7 @@ stw_make_current( if (fb == NULL && ctx != NULL && hdc != NULL) { GLvisual *visual = &ctx->st->ctx->Visual; - fb = stw_framebuffer_create( hdc, visual, width, height ); + fb = stw_framebuffer_create( hdc, visual, ctx->pfi, width, height ); if (fb == NULL) return FALSE; } diff --git a/src/gallium/state_trackers/wgl/shared/stw_context.h b/src/gallium/state_trackers/wgl/shared/stw_context.h index b289615272..bc3b1dc880 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_context.h +++ b/src/gallium/state_trackers/wgl/shared/stw_context.h @@ -31,12 +31,14 @@ #include struct st_context; +struct stw_pixelformat_info; struct stw_context { struct st_context *st; HDC hdc; DWORD color_bits; + const struct stw_pixelformat_info *pfi; }; #endif /* STW_CONTEXT_H */ diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c index 55dc9d678c..e70e20390e 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.c @@ -93,21 +93,6 @@ stw_call_window_proc( return CallNextHookEx(tls_data->hCallWndProcHook, nCode, wParam, lParam); } -static INLINE boolean -stw_is_supported_color(enum pipe_format format) -{ - struct pipe_screen *screen = stw_dev->screen; - return screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_RENDER_TARGET, 0); -} - -static INLINE boolean -stw_is_supported_depth_stencil(enum pipe_format format) -{ - struct pipe_screen *screen = stw_dev->screen; - return screen->is_format_supported(screen, format, PIPE_TEXTURE_2D, - PIPE_TEXTURE_USAGE_DEPTH_STENCIL, 0); -} /* Create a new framebuffer object which will correspond to the given HDC. */ @@ -115,83 +100,26 @@ struct stw_framebuffer * stw_framebuffer_create( HDC hdc, GLvisual *visual, + const struct stw_pixelformat_info *pfi, GLuint width, GLuint height ) { - struct stw_framebuffer *fb; enum pipe_format colorFormat, depthFormat, stencilFormat; + struct stw_framebuffer *fb; - /* Determine PIPE_FORMATs for buffers. - */ - - if(visual->alphaBits <= 0 && visual->redBits <= 5 && visual->blueBits <= 6 && visual->greenBits <= 5 && - stw_is_supported_color(PIPE_FORMAT_R5G6B5_UNORM)) { - colorFormat = PIPE_FORMAT_R5G6B5_UNORM; - } - else if(visual->alphaBits <= 0 && visual->redBits <= 8 && visual->blueBits <= 8 && visual->greenBits <= 8 && - stw_is_supported_color(PIPE_FORMAT_X8R8G8B8_UNORM)) { - colorFormat = PIPE_FORMAT_X8R8G8B8_UNORM; - } - else if(visual->alphaBits <= 1 && visual->redBits <= 5 && visual->blueBits <= 5 && visual->greenBits <= 5 && - stw_is_supported_color(PIPE_FORMAT_A1R5G5B5_UNORM)) { - colorFormat = PIPE_FORMAT_A1R5G5B5_UNORM; - } - else if(visual->alphaBits <= 4 && visual->redBits <= 4 && visual->blueBits <= 4 && visual->greenBits <= 4 && - stw_is_supported_color(PIPE_FORMAT_A4R4G4B4_UNORM)) { - colorFormat = PIPE_FORMAT_A4R4G4B4_UNORM; - } - else if(visual->alphaBits <= 8 && visual->redBits <= 8 && visual->blueBits <= 8 && visual->greenBits <= 8 && - stw_is_supported_color(PIPE_FORMAT_A8R8G8B8_UNORM)) { - colorFormat = PIPE_FORMAT_A8R8G8B8_UNORM; - } - else { - assert(0); - return NULL; - } + colorFormat = pfi->color_format; + + assert(pf_layout( pfi->depth_stencil_format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); - if (visual->depthBits == 0) - depthFormat = PIPE_FORMAT_NONE; - else if (visual->depthBits <= 16 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z16_UNORM)) - depthFormat = PIPE_FORMAT_Z16_UNORM; - else if (visual->depthBits <= 24 && visual->stencilBits != 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_X8Z24_UNORM)) { - depthFormat = PIPE_FORMAT_X8Z24_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits != 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z24X8_UNORM)) { - depthFormat = PIPE_FORMAT_Z24X8_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_S8Z24_UNORM)) { - depthFormat = PIPE_FORMAT_S8Z24_UNORM; - } - else if (visual->depthBits <= 24 && visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_Z24S8_UNORM)) { - depthFormat = PIPE_FORMAT_Z24S8_UNORM; - } - else if(stw_is_supported_depth_stencil(PIPE_FORMAT_Z32_UNORM)) { - depthFormat = PIPE_FORMAT_Z32_UNORM; - } - else if(stw_is_supported_depth_stencil(PIPE_FORMAT_Z32_FLOAT)) { - depthFormat = PIPE_FORMAT_Z32_FLOAT; - } - else { - assert(0); + if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_Z )) + depthFormat = pfi->depth_stencil_format; + else depthFormat = PIPE_FORMAT_NONE; - } - if (depthFormat == PIPE_FORMAT_S8Z24_UNORM || - depthFormat == PIPE_FORMAT_Z24S8_UNORM) { - stencilFormat = depthFormat; - } - else if (visual->stencilBits == 8 && - stw_is_supported_depth_stencil(PIPE_FORMAT_S8_UNORM)) { - stencilFormat = PIPE_FORMAT_S8_UNORM; - } - else { + if(pf_get_component_bits( pfi->depth_stencil_format, PIPE_FORMAT_COMP_S )) + stencilFormat = pfi->depth_stencil_format; + else stencilFormat = PIPE_FORMAT_NONE; - } fb = CALLOC_STRUCT( stw_framebuffer ); if (fb == NULL) diff --git a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h index ea3bf6f8fc..607b7f0ef2 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h +++ b/src/gallium/state_trackers/wgl/shared/stw_framebuffer.h @@ -30,6 +30,8 @@ #include "main/mtypes.h" +struct stw_pixelformat_info; + /** * Windows framebuffer, derived from gl_framebuffer. */ @@ -45,6 +47,7 @@ struct stw_framebuffer * stw_framebuffer_create( HDC hdc, GLvisual *visual, + const struct stw_pixelformat_info *pfi, GLuint width, GLuint height ); diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c index 897478e0f5..67a92d3d8e 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c +++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.c @@ -128,11 +128,23 @@ stw_pixelformat_add( assert(stw_dev->pixelformat_extended_count < STW_MAX_PIXELFORMATS); if(stw_dev->pixelformat_extended_count >= STW_MAX_PIXELFORMATS) return; + + assert(pf_layout( color->format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_R ) == color->bits.red ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_G ) == color->bits.green ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_B ) == color->bits.blue ); + assert(pf_get_component_bits( color->format, PIPE_FORMAT_COMP_A ) == color->bits.alpha ); + assert(pf_layout( depth->format ) == PIPE_FORMAT_LAYOUT_RGBAZS ); + assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_Z ) == depth->bits.depth ); + assert(pf_get_component_bits( depth->format, PIPE_FORMAT_COMP_S ) == depth->bits.stencil ); pfi = &stw_dev->pixelformats[stw_dev->pixelformat_extended_count]; memset(pfi, 0, sizeof *pfi); + pfi->color_format = color->format; + pfi->depth_stencil_format = depth->format; + pfi->pfd.nSize = sizeof pfi->pfd; pfi->pfd.nVersion = 1; diff --git a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h index acfb230d9d..34522ebef3 100644 --- a/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h +++ b/src/gallium/state_trackers/wgl/shared/stw_pixelformat.h @@ -31,9 +31,13 @@ #include #include "pipe/p_compiler.h" +#include "pipe/p_format.h" struct stw_pixelformat_info { + enum pipe_format color_format; + enum pipe_format depth_stencil_format; + PIXELFORMATDESCRIPTOR pfd; unsigned numSampleBuffers; -- cgit v1.2.3 From f94053eb7d3f129e5086f6dc431a13f83c93a189 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 15 Apr 2009 19:55:00 -0600 Subject: tests: another extended swizzle test --- progs/fp/swz3.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 progs/fp/swz3.txt (limited to 'progs') diff --git a/progs/fp/swz3.txt b/progs/fp/swz3.txt new file mode 100644 index 0000000000..382f5880d3 --- /dev/null +++ b/progs/fp/swz3.txt @@ -0,0 +1,5 @@ +!!ARBfp1.0 +TEMP R0, R1; +MOV R0, -fragment.color; +SWZ result.color, R0, -y, -x, z, 1; +END -- cgit v1.2.3 From 82e92eeab0c831683961175d155865786149a354 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 15 Apr 2009 23:36:22 +0200 Subject: progs/tests: Make texcompress2 get texture --- progs/tests/texcompress2.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'progs') diff --git a/progs/tests/texcompress2.c b/progs/tests/texcompress2.c index cbb8f1d3a2..b95aca9fb9 100644 --- a/progs/tests/texcompress2.c +++ b/progs/tests/texcompress2.c @@ -51,7 +51,6 @@ TestSubTex(void) GLboolean all = 0*GL_TRUE; GLubyte *buffer; GLint size, fmt; - int i; glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB, &size); @@ -82,6 +81,23 @@ TestSubTex(void) } +static void +TestGetTex(void) +{ + GLubyte *buffer; + + buffer = (GLubyte *) malloc(3 * ImgWidth * ImgHeight); + + glGetTexImage(GL_TEXTURE_2D, + 0, + GL_RGB, + GL_UNSIGNED_BYTE, + buffer); + + free(buffer); +} + + static void LoadCompressedImage(const char *file) { @@ -146,7 +162,10 @@ LoadCompressedImage(const char *file) glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, filter); - TestSubTex(); + if (0) + TestSubTex(); + else + TestGetTex(); } -- cgit v1.2.3 From 0d0028e6df3542272ce833fec2e7af99d762fe8f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 16 Apr 2009 09:25:52 -0600 Subject: demos: use larger buffer for snprintf() call, see bug 21220 --- progs/samples/blendeq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/samples/blendeq.c b/progs/samples/blendeq.c index cd0474c5ce..037d06fa52 100644 --- a/progs/samples/blendeq.c +++ b/progs/samples/blendeq.c @@ -100,7 +100,7 @@ static void PrintColorStrings( void ) { GLubyte ubbuf[3]; int i, xleft, xright; - char colorString[18]; + char colorString[100]; xleft = 5 + windW/4; xright = 5 + windW/2; -- cgit v1.2.3 From 189db329caba805f4ae9ab28c675f37565fd4c9c Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 16 Apr 2009 10:28:27 -0600 Subject: demos: set init window size, not pos --- progs/glsl/linktest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/glsl/linktest.c b/progs/glsl/linktest.c index 601b24e893..988d082341 100644 --- a/progs/glsl/linktest.c +++ b/progs/glsl/linktest.c @@ -242,7 +242,7 @@ int main(int argc, char *argv[]) { glutInit(&argc, argv); - glutInitWindowPosition( 0, 0); + glutInitWindowSize(300, 300); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); Win = glutCreateWindow(argv[0]); glutReshapeFunc(Reshape); -- cgit v1.2.3 From 047efcd050a92687403952910de4fded3df46964 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 17 Apr 2009 08:09:17 -0600 Subject: demos: move glewInit() after glutCreateWindow() Fixes segfault. See bug 21239. However, the demo doesn't render properly. Probably a bug in the GL_ATI_fragment_shader code. --- progs/tests/afsmultiarb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/tests/afsmultiarb.c b/progs/tests/afsmultiarb.c index 162ab19493..ca25a4d75b 100644 --- a/progs/tests/afsmultiarb.c +++ b/progs/tests/afsmultiarb.c @@ -442,8 +442,8 @@ int main( int argc, char *argv[] ) glutInitWindowSize( 300, 300 ); glutInitWindowPosition( 0, 0 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); - glewInit(); glutCreateWindow(argv[0] ); + glewInit(); Init( argc, argv ); -- cgit v1.2.3 From 90c880f08996cce57273544d8ba11b56ce2a06f3 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 17 Apr 2009 09:15:58 -0600 Subject: demos: move glewInit() call, fixes crash/bug 21247 --- progs/tests/vparray.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/tests/vparray.c b/progs/tests/vparray.c index 9c2fad97d9..af9b62d33e 100644 --- a/progs/tests/vparray.c +++ b/progs/tests/vparray.c @@ -280,9 +280,9 @@ int main(int argc, char **argv) glutInitWindowPosition(0, 0); glutInitWindowSize(400, 400); if (glutCreateWindow("Isosurface") <= 0) { - glewInit(); exit(0); } + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutSpecialFunc(SpecialKey); -- cgit v1.2.3 From 538a82388293ca1b14e6eb8b26179d1f42627210 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 17 Apr 2009 16:23:33 -0600 Subject: demos: new glsl/array.c demo Test variable indexing into a uniform array in a vertex shader. --- progs/glsl/Makefile | 8 ++ progs/glsl/array.c | 261 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 269 insertions(+) create mode 100644 progs/glsl/array.c (limited to 'progs') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 0f1a299570..5fb95c4b3b 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -10,6 +10,7 @@ LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(T LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) PROGS = \ + array \ bitmap \ brick \ bump \ @@ -80,6 +81,13 @@ shaderutil.o: shaderutil.c shaderutil.h +array.o: array.c extfuncs.h shaderutil.h + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) array.c + +array: array.o shaderutil.o + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) array.o shaderutil.o $(LIBS) -o $@ + + bitmap.o: bitmap.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bitmap.c diff --git a/progs/glsl/array.c b/progs/glsl/array.c new file mode 100644 index 0000000000..46ef8043bc --- /dev/null +++ b/progs/glsl/array.c @@ -0,0 +1,261 @@ +/** + * Test variable array indexing in a vertex shader. + * Brian Paul + * 17 April 2009 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "extfuncs.h" +#include "shaderutil.h" + + +/** + * The vertex position.z is used as a (variable) index into an + * array which returns a new Z value. + */ +static const char *VertShaderText = + "uniform sampler2D tex1; \n" + "uniform float HeightArray[20]; \n" + "void main() \n" + "{ \n" + " vec4 pos = gl_Vertex; \n" + " int i = int(pos.z * 9.5); \n" + " pos.z = HeightArray[i]; \n" + " gl_Position = gl_ModelViewProjectionMatrix * pos; \n" + " gl_FrontColor = pos; \n" + "} \n"; + +static const char *FragShaderText = + "void main() \n" + "{ \n" + " gl_FragColor = gl_Color; \n" + "} \n"; + + +static GLuint fragShader; +static GLuint vertShader; +static GLuint program; + +static GLint win = 0; +static GLboolean Anim = GL_TRUE; +static GLboolean WireFrame = GL_TRUE; +static GLfloat xRot = -70.0f, yRot = 0.0f, zRot = 0.0f; + + +static void +Idle(void) +{ + zRot = 90 + glutGet(GLUT_ELAPSED_TIME) * 0.05; + glutPostRedisplay(); +} + + +/** z=f(x,y) */ +static float +fz(float x, float y) +{ + return fabs(cos(1.5*x) + cos(1.5*y)); +} + + +static void +DrawMesh(void) +{ + GLfloat xmin = -2.0, xmax = 2.0; + GLfloat ymin = -2.0, ymax = 2.0; + GLuint xdivs = 20, ydivs = 20; + GLfloat dx = (xmax - xmin) / xdivs; + GLfloat dy = (ymax - ymin) / ydivs; + GLfloat ds = 1.0 / xdivs, dt = 1.0 / ydivs; + GLfloat x, y, s, t; + GLuint i, j; + + y = ymin; + t = 0.0; + for (i = 0; i < ydivs; i++) { + x = xmin; + s = 0.0; + glBegin(GL_QUAD_STRIP); + for (j = 0; j < xdivs; j++) { + float z0 = fz(x, y), z1 = fz(x, y + dy); + + glTexCoord2f(s, t); + glVertex3f(x, y, z0); + + glTexCoord2f(s, t + dt); + glVertex3f(x, y + dy, z1); + x += dx; + s += ds; + } + glEnd(); + y += dy; + t += dt; + } +} + + +static void +Redisplay(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (WireFrame) + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + else + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glPushMatrix(); + glRotatef(xRot, 1.0f, 0.0f, 0.0f); + glRotatef(yRot, 0.0f, 1.0f, 0.0f); + glRotatef(zRot, 0.0f, 0.0f, 1.0f); + + glPushMatrix(); + DrawMesh(); + glPopMatrix(); + + glPopMatrix(); + + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -15.0f); +} + + +static void +CleanUp(void) +{ + glDeleteShader_func(fragShader); + glDeleteShader_func(vertShader); + glDeleteProgram_func(program); + glutDestroyWindow(win); +} + + +static void +Key(unsigned char key, int x, int y) +{ + const GLfloat step = 2.0; + (void) x; + (void) y; + + switch(key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'w': + WireFrame = !WireFrame; + break; + case 'z': + zRot += step; + break; + case 'Z': + zRot -= step; + break; + case 27: + CleanUp(); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +SpecialKey(int key, int x, int y) +{ + const GLfloat step = 2.0; + + (void) x; + (void) y; + + switch(key) { + case GLUT_KEY_UP: + xRot += step; + break; + case GLUT_KEY_DOWN: + xRot -= step; + break; + case GLUT_KEY_LEFT: + yRot -= step; + break; + case GLUT_KEY_RIGHT: + yRot += step; + break; + } + glutPostRedisplay(); +} + + +static void +Init(void) +{ + GLfloat HeightArray[20]; + GLint u, i; + + if (!ShadersSupported()) + exit(1); + + GetExtensionFuncs(); + + vertShader = CompileShaderText(GL_VERTEX_SHADER, VertShaderText); + fragShader = CompileShaderText(GL_FRAGMENT_SHADER, FragShaderText); + program = LinkShaders(vertShader, fragShader); + + glUseProgram_func(program); + + /* Setup the HeightArray[] uniform */ + for (i = 0; i < 20; i++) + HeightArray[i] = i / 20.0; + u = glGetUniformLocation_func(program, "HeightArray"); + glUniform1fv_func(u, 20, HeightArray); + + assert(glGetError() == 0); + + glClearColor(0.4f, 0.4f, 0.8f, 0.0f); + glEnable(GL_DEPTH_TEST); + glColor3f(1, 1, 1); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowSize(500, 500); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutSpecialFunc(SpecialKey); + glutDisplayFunc(Redisplay); + Init(); + if (Anim) + glutIdleFunc(Idle); + glutMainLoop(); + return 0; +} + -- cgit v1.2.3 From 2bf326af10d02b2d5a44cee98fa62c8a8940dd11 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 10:08:15 -0600 Subject: demos: fix usage text --- progs/tests/jkrahntest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/tests/jkrahntest.c b/progs/tests/jkrahntest.c index 08660b8932..3fef105fc2 100644 --- a/progs/tests/jkrahntest.c +++ b/progs/tests/jkrahntest.c @@ -45,7 +45,7 @@ int main(int argc, char **argv) if (argc < 2) { fprintf(stderr, "This program tests GLX context switching.\n"); - fprintf(stderr, "Usage: cxbug \n"); + fprintf(stderr, "Usage: jkrahntest \n"); fprintf(stderr, "Where n is:\n"); fprintf(stderr, "\t1) Use two contexts and swap only when the context is current (typical case).\n"); fprintf(stderr, "\t2) Use two contexts and swap at the same time.\n"); -- cgit v1.2.3 From 3e750ce5c4576883f5b567eaf3336fea3df3a997 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 10:20:26 -0600 Subject: demos: fix incorrect assertion --- progs/tests/vptest1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/tests/vptest1.c b/progs/tests/vptest1.c index 5162919292..6e32b03346 100644 --- a/progs/tests/vptest1.c +++ b/progs/tests/vptest1.c @@ -128,7 +128,7 @@ static void Init( void ) glLoadProgramNV(GL_VERTEX_PROGRAM_NV, 1, strlen(prog1), (const GLubyte *) prog1); - assert(!glIsProgramNV(1)); + assert(glIsProgramNV(1)); glLoadProgramNV(GL_VERTEX_PROGRAM_NV, 2, strlen(prog2), -- cgit v1.2.3 From 118856641f4871d6f6afd1abb67ad7fe56a6814b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 12:54:27 -0600 Subject: demos: move glslnoise.c demo to glsl/noise2.c --- progs/demos/Makefile | 1 - progs/demos/glslnoise.c | 201 ------------------------------------------------ progs/glsl/Makefile | 8 ++ progs/glsl/noise2.c | 201 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 209 insertions(+), 202 deletions(-) delete mode 100644 progs/demos/glslnoise.c create mode 100644 progs/glsl/noise2.c (limited to 'progs') diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 32c6072123..43bf09c0af 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -32,7 +32,6 @@ PROGS = \ geartrain \ glinfo \ gloss \ - glslnoise \ gltestperf \ glutfx \ isosurf \ diff --git a/progs/demos/glslnoise.c b/progs/demos/glslnoise.c deleted file mode 100644 index e972b62673..0000000000 --- a/progs/demos/glslnoise.c +++ /dev/null @@ -1,201 +0,0 @@ -/* - * GLSL noise demo. - * - * Michal Krol - * 20 February 2006 - * - * Based on the original demo by: - * Stefan Gustavson (stegu@itn.liu.se) 2004, 2005 - */ - -#ifdef WIN32 -#include -#endif - -#include -#include -#include -#include -#include - -#ifdef WIN32 -#define GETPROCADDRESS(F) wglGetProcAddress(F) -#else -#define GETPROCADDRESS(F) glutGetProcAddress(F) -#endif - -static GLhandleARB fragShader; -static GLhandleARB vertShader; -static GLhandleARB program; - -static GLint uTime; - -static GLint t0 = 0; -static GLint frames = 0; - -static GLfloat u_time = 0.0f; - -static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; -static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; -static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; -static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL; -static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL; -static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL; -static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL; -static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; -static PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL; - -static void Redisplay (void) -{ - GLint t; - - glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glUniform1fARB (uTime, 0.5f * u_time); - - glPushMatrix (); - glutSolidSphere (2.0, 20, 10); - glPopMatrix (); - - glutSwapBuffers(); - frames++; - - t = glutGet (GLUT_ELAPSED_TIME); - if (t - t0 >= 5000) { - GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; - GLfloat fps = frames / seconds; - printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); - fflush(stdout); - t0 = t; - frames = 0; - } -} - -static void Idle (void) -{ - u_time += 0.1f; - glutPostRedisplay (); -} - -static void Reshape (int width, int height) -{ - glViewport (0, 0, width, height); - glMatrixMode (GL_PROJECTION); - glLoadIdentity (); - glFrustum (-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); - glMatrixMode (GL_MODELVIEW); - glLoadIdentity (); - glTranslatef (0.0f, 0.0f, -15.0f); -} - -static void Key (unsigned char key, int x, int y) -{ - (void) x; - (void) y; - - switch (key) - { - case 27: - exit(0); - break; - } - glutPostRedisplay (); -} - -static void Init (void) -{ - static const char *fragShaderText = - "uniform float time;\n" - "varying vec3 position;\n" - "void main () {\n" - " gl_FragColor = vec4 (vec3 (0.5 + 0.5 * noise1 (vec4 (position, time))), 1.0);\n" - "}\n" - ; - static const char *vertShaderText = - "varying vec3 position;\n" - "void main () {\n" - " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" - " position = 4.0 * gl_Vertex.xyz;\n" - "}\n" - ; - - if (!glutExtensionSupported ("GL_ARB_fragment_shader")) - { - printf ("Sorry, this demo requires GL_ARB_fragment_shader\n"); - exit(1); - } - if (!glutExtensionSupported ("GL_ARB_shader_objects")) - { - printf ("Sorry, this demo requires GL_ARB_shader_objects\n"); - exit(1); - } - if (!glutExtensionSupported ("GL_ARB_shading_language_100")) - { - printf ("Sorry, this demo requires GL_ARB_shading_language_100\n"); - exit(1); - } - if (!glutExtensionSupported ("GL_ARB_vertex_shader")) - { - printf ("Sorry, this demo requires GL_ARB_vertex_shader\n"); - exit(1); - } - - glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) - GETPROCADDRESS("glCreateShaderObjectARB"); - glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) - GETPROCADDRESS("glShaderSourceARB"); - glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) - GETPROCADDRESS("glCompileShaderARB"); - glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) - GETPROCADDRESS("glCreateProgramObjectARB"); - glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) - GETPROCADDRESS("glAttachObjectARB"); - glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) - GETPROCADDRESS ("glLinkProgramARB"); - glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) - GETPROCADDRESS("glUseProgramObjectARB"); - - glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) - GETPROCADDRESS("glGetUniformLocationARB"); - glUniform1fARB = (PFNGLUNIFORM1FARBPROC) - GETPROCADDRESS("glUniform1fARB"); - - fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB); - glShaderSourceARB (fragShader, 1, &fragShaderText, NULL); - glCompileShaderARB (fragShader); - - vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB); - glShaderSourceARB (vertShader, 1, &vertShaderText, NULL); - glCompileShaderARB (vertShader); - - program = glCreateProgramObjectARB (); - glAttachObjectARB (program, fragShader); - glAttachObjectARB (program, vertShader); - glLinkProgramARB (program); - glUseProgramObjectARB (program); - - uTime = glGetUniformLocationARB (program, "time"); - - glClearColor (0.0f, 0.1f, 0.3f, 1.0f); - glEnable (GL_CULL_FACE); - glEnable (GL_DEPTH_TEST); - - printf ("GL_RENDERER = %s\n", (const char *) glGetString (GL_RENDERER)); -} - -int main (int argc, char *argv[]) -{ - glutInit (&argc, argv); - glutInitWindowPosition ( 0, 0); - glutInitWindowSize (200, 200); - glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); - glutCreateWindow (argv[0]); - glutReshapeFunc (Reshape); - glutKeyboardFunc (Key); - glutDisplayFunc (Redisplay); - glutIdleFunc (Idle); - Init (); - glutMainLoop (); - return 0; -} - diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 5fb95c4b3b..8e61ab690b 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -23,6 +23,7 @@ PROGS = \ multinoise \ multitex \ noise \ + noise2 \ points \ pointcoord \ samplers \ @@ -163,6 +164,13 @@ noise: noise.o shaderutil.o $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise.o shaderutil.o $(LIBS) -o $@ +noise2.o: noise2.c extfuncs.h shaderutil.h + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) noise2.c + +noise2: noise2.o shaderutil.o + $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise2.o shaderutil.o $(LIBS) -o $@ + + points.o: points.c extfuncs.h shaderutil.h $(APP_CC) -c -I$(INCDIR) $(CFLAGS) points.c diff --git a/progs/glsl/noise2.c b/progs/glsl/noise2.c new file mode 100644 index 0000000000..e972b62673 --- /dev/null +++ b/progs/glsl/noise2.c @@ -0,0 +1,201 @@ +/* + * GLSL noise demo. + * + * Michal Krol + * 20 February 2006 + * + * Based on the original demo by: + * Stefan Gustavson (stegu@itn.liu.se) 2004, 2005 + */ + +#ifdef WIN32 +#include +#endif + +#include +#include +#include +#include +#include + +#ifdef WIN32 +#define GETPROCADDRESS(F) wglGetProcAddress(F) +#else +#define GETPROCADDRESS(F) glutGetProcAddress(F) +#endif + +static GLhandleARB fragShader; +static GLhandleARB vertShader; +static GLhandleARB program; + +static GLint uTime; + +static GLint t0 = 0; +static GLint frames = 0; + +static GLfloat u_time = 0.0f; + +static PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB = NULL; +static PFNGLSHADERSOURCEARBPROC glShaderSourceARB = NULL; +static PFNGLCOMPILESHADERARBPROC glCompileShaderARB = NULL; +static PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB = NULL; +static PFNGLATTACHOBJECTARBPROC glAttachObjectARB = NULL; +static PFNGLLINKPROGRAMARBPROC glLinkProgramARB = NULL; +static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB = NULL; +static PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB = NULL; +static PFNGLUNIFORM1FARBPROC glUniform1fARB = NULL; + +static void Redisplay (void) +{ + GLint t; + + glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glUniform1fARB (uTime, 0.5f * u_time); + + glPushMatrix (); + glutSolidSphere (2.0, 20, 10); + glPopMatrix (); + + glutSwapBuffers(); + frames++; + + t = glutGet (GLUT_ELAPSED_TIME); + if (t - t0 >= 5000) { + GLfloat seconds = (GLfloat) (t - t0) / 1000.0f; + GLfloat fps = frames / seconds; + printf ("%d frames in %6.3f seconds = %6.3f FPS\n", frames, seconds, fps); + fflush(stdout); + t0 = t; + frames = 0; + } +} + +static void Idle (void) +{ + u_time += 0.1f; + glutPostRedisplay (); +} + +static void Reshape (int width, int height) +{ + glViewport (0, 0, width, height); + glMatrixMode (GL_PROJECTION); + glLoadIdentity (); + glFrustum (-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode (GL_MODELVIEW); + glLoadIdentity (); + glTranslatef (0.0f, 0.0f, -15.0f); +} + +static void Key (unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch (key) + { + case 27: + exit(0); + break; + } + glutPostRedisplay (); +} + +static void Init (void) +{ + static const char *fragShaderText = + "uniform float time;\n" + "varying vec3 position;\n" + "void main () {\n" + " gl_FragColor = vec4 (vec3 (0.5 + 0.5 * noise1 (vec4 (position, time))), 1.0);\n" + "}\n" + ; + static const char *vertShaderText = + "varying vec3 position;\n" + "void main () {\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + " position = 4.0 * gl_Vertex.xyz;\n" + "}\n" + ; + + if (!glutExtensionSupported ("GL_ARB_fragment_shader")) + { + printf ("Sorry, this demo requires GL_ARB_fragment_shader\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_shader_objects")) + { + printf ("Sorry, this demo requires GL_ARB_shader_objects\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_shading_language_100")) + { + printf ("Sorry, this demo requires GL_ARB_shading_language_100\n"); + exit(1); + } + if (!glutExtensionSupported ("GL_ARB_vertex_shader")) + { + printf ("Sorry, this demo requires GL_ARB_vertex_shader\n"); + exit(1); + } + + glCreateShaderObjectARB = (PFNGLCREATESHADEROBJECTARBPROC) + GETPROCADDRESS("glCreateShaderObjectARB"); + glShaderSourceARB = (PFNGLSHADERSOURCEARBPROC) + GETPROCADDRESS("glShaderSourceARB"); + glCompileShaderARB = (PFNGLCOMPILESHADERARBPROC) + GETPROCADDRESS("glCompileShaderARB"); + glCreateProgramObjectARB = (PFNGLCREATEPROGRAMOBJECTARBPROC) + GETPROCADDRESS("glCreateProgramObjectARB"); + glAttachObjectARB = (PFNGLATTACHOBJECTARBPROC) + GETPROCADDRESS("glAttachObjectARB"); + glLinkProgramARB = (PFNGLLINKPROGRAMARBPROC) + GETPROCADDRESS ("glLinkProgramARB"); + glUseProgramObjectARB = (PFNGLUSEPROGRAMOBJECTARBPROC) + GETPROCADDRESS("glUseProgramObjectARB"); + + glGetUniformLocationARB = (PFNGLGETUNIFORMLOCATIONARBPROC) + GETPROCADDRESS("glGetUniformLocationARB"); + glUniform1fARB = (PFNGLUNIFORM1FARBPROC) + GETPROCADDRESS("glUniform1fARB"); + + fragShader = glCreateShaderObjectARB (GL_FRAGMENT_SHADER_ARB); + glShaderSourceARB (fragShader, 1, &fragShaderText, NULL); + glCompileShaderARB (fragShader); + + vertShader = glCreateShaderObjectARB (GL_VERTEX_SHADER_ARB); + glShaderSourceARB (vertShader, 1, &vertShaderText, NULL); + glCompileShaderARB (vertShader); + + program = glCreateProgramObjectARB (); + glAttachObjectARB (program, fragShader); + glAttachObjectARB (program, vertShader); + glLinkProgramARB (program); + glUseProgramObjectARB (program); + + uTime = glGetUniformLocationARB (program, "time"); + + glClearColor (0.0f, 0.1f, 0.3f, 1.0f); + glEnable (GL_CULL_FACE); + glEnable (GL_DEPTH_TEST); + + printf ("GL_RENDERER = %s\n", (const char *) glGetString (GL_RENDERER)); +} + +int main (int argc, char *argv[]) +{ + glutInit (&argc, argv); + glutInitWindowPosition ( 0, 0); + glutInitWindowSize (200, 200); + glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + glutCreateWindow (argv[0]); + glutReshapeFunc (Reshape); + glutKeyboardFunc (Key); + glutDisplayFunc (Redisplay); + glutIdleFunc (Idle); + Init (); + glutMainLoop (); + return 0; +} + -- cgit v1.2.3 From 6a495d26af54011ff1ec0597b38db2ce162c7d50 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 12:55:55 -0600 Subject: demos: move streaming_rect.c demo to tests/ --- progs/demos/Makefile | 1 - progs/demos/streaming_rect.c | 327 ------------------------------------------- progs/tests/Makefile | 1 + progs/tests/streaming_rect.c | 327 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 328 insertions(+), 328 deletions(-) delete mode 100644 progs/demos/streaming_rect.c create mode 100644 progs/tests/streaming_rect.c (limited to 'progs') diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 43bf09c0af..1cdd963417 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -48,7 +48,6 @@ PROGS = \ renormal \ shadowtex \ singlebuffer \ - streaming_rect \ spectex \ spriteblast \ stex3d \ diff --git a/progs/demos/streaming_rect.c b/progs/demos/streaming_rect.c deleted file mode 100644 index f65ac4ce36..0000000000 --- a/progs/demos/streaming_rect.c +++ /dev/null @@ -1,327 +0,0 @@ -/* - * GL_ARB_pixel_buffer_object test - * - * Command line options: - * -w WIDTH -h HEIGHT sets window size - * - */ - -#include -#include -#include -#include -#include -#include - -#include "readtex.h" - - -#define ANIMATE 10 -#define PBO 11 -#define QUIT 100 - -static GLuint DrawPBO; - -static GLboolean Animate = GL_TRUE; -static GLboolean use_pbo = 1; -static GLboolean whole_rect = 1; - -static GLfloat Drift = 0.0; -static GLfloat drift_increment = 1/255.0; -static GLfloat Xrot = 20.0, Yrot = 30.0; - -static GLuint Width = 1024; -static GLuint Height = 512; - - -static void Idle( void ) -{ - if (Animate) { - - Drift += drift_increment; - if (Drift >= 1.0) - Drift = 0.0; - - glutPostRedisplay(); - } -} - -/*static int max( int a, int b ) { return a > b ? a : b; }*/ - -#ifndef min -static int min( int a, int b ) { return a < b ? a : b; } -#endif - -static void DrawObject() -{ - GLint size = Width * Height * 4; - - if (use_pbo) { - /* XXX: This is extremely important - semantically makes the buffer - * contents undefined, but in practice means that the driver can - * release the old copy of the texture and allocate a new one - * without waiting for outstanding rendering to complete. - */ - glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO); - glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, size, NULL, GL_STREAM_DRAW_ARB); - - { - char *image = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY_ARB); - - printf("char %d\n", (unsigned char)(Drift * 255)); - - memset(image, (unsigned char)(Drift * 255), size); - - glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT); - } - - - /* BGRA is required for most hardware paths: - */ - glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, Width, Height, 0, - GL_BGRA, GL_UNSIGNED_BYTE, NULL); - } - else { - static char *image = NULL; - - if (image == NULL) - image = malloc(size); - - glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); - - memset(image, (unsigned char)(Drift * 255), size); - - /* BGRA should be the fast path for regular uploads as well. - */ - glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, Width, Height, 0, - GL_BGRA, GL_UNSIGNED_BYTE, image); - } - - { - int x,y,w,h; - - if (whole_rect) { - x = y = 0; - w = Width; - h = Height; - } - else { - x = y = 0; - w = min(10, Width); - h = min(10, Height); - } - - glBegin(GL_QUADS); - - glTexCoord2f( x, y); - glVertex2f( x, y ); - - glTexCoord2f( x, y + h); - glVertex2f( x, y + h); - - glTexCoord2f( x + w + .5, y + h); - glVertex2f( x + w, y + h ); - - glTexCoord2f( x + w, y + .5); - glVertex2f( x + w, y ); - - glEnd(); - } -} - - - -static void Display( void ) -{ - static GLint T0 = 0; - static GLint Frames = 0; - GLint t; - - glClear( GL_COLOR_BUFFER_BIT ); - - glPushMatrix(); - DrawObject(); - glPopMatrix(); - - glutSwapBuffers(); - - Frames++; - - t = glutGet(GLUT_ELAPSED_TIME); - if (t - T0 >= 1000) { - GLfloat seconds = (t - T0) / 1000.0; - - GLfloat fps = Frames / seconds; - printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); - fflush(stdout); - - drift_increment = 2.2 * seconds / Frames; - T0 = t; - Frames = 0; - } -} - - -static void Reshape( int width, int height ) -{ - glViewport( 0, 0, width, height ); - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); -/* glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 ); */ - gluOrtho2D( 0, width, height, 0 ); - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - glTranslatef(0.375, 0.375, 0); -} - - -static void ModeMenu(int entry) -{ - if (entry==ANIMATE) { - Animate = !Animate; - } - else if (entry==PBO) { - use_pbo = !use_pbo; - } - else if (entry==QUIT) { - exit(0); - } - - glutPostRedisplay(); -} - - -static void Key( unsigned char key, int x, int y ) -{ - (void) x; - (void) y; - switch (key) { - case 27: - exit(0); - break; - } - glutPostRedisplay(); -} - - -static void SpecialKey( int key, int x, int y ) -{ - float step = 3.0; - (void) x; - (void) y; - - switch (key) { - case GLUT_KEY_UP: - Xrot += step; - break; - case GLUT_KEY_DOWN: - Xrot -= step; - break; - case GLUT_KEY_LEFT: - Yrot += step; - break; - case GLUT_KEY_RIGHT: - Yrot -= step; - break; - } - glutPostRedisplay(); -} - - -static void Init( int argc, char *argv[] ) -{ - const char *exten = (const char *) glGetString(GL_EXTENSIONS); - GLuint texObj; - GLint size; - - - if (!strstr(exten, "GL_ARB_pixel_buffer_object")) { - printf("Sorry, GL_ARB_pixel_buffer_object not supported by this renderer.\n"); - exit(1); - } - - glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size); - printf("%d x %d max texture size\n", size, size); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - /* allocate two texture objects */ - glGenTextures(1, &texObj); - - /* setup the texture objects */ - glActiveTextureARB(GL_TEXTURE0_ARB); - glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texObj); - - glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - - glGenBuffersARB(1, &DrawPBO); - - glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO); - glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, - Width * Height * 4, NULL, GL_STREAM_DRAW); - - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); - - glEnable(GL_TEXTURE_RECTANGLE_ARB); - - glShadeModel(GL_SMOOTH); - glClearColor(0.3, 0.3, 0.4, 1.0); - - if (argc > 1 && strcmp(argv[1], "-info")==0) { - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); - printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); - printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); - } -} - - -int main( int argc, char *argv[] ) -{ - GLint i; - - glutInit( &argc, argv ); - - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-w") == 0) { - Width = atoi(argv[i+1]); - if (Width <= 0) { - printf("Error, bad width\n"); - exit(1); - } - i++; - } - else if (strcmp(argv[i], "-h") == 0) { - Height = atoi(argv[i+1]); - if (Height <= 0) { - printf("Error, bad height\n"); - exit(1); - } - i++; - } - } - - glutInitWindowSize( Width, Height ); - glutInitWindowPosition( 0, 0 ); - glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); - glutCreateWindow(argv[0] ); - glewInit(); - - Init( argc, argv ); - - glutReshapeFunc( Reshape ); - glutKeyboardFunc( Key ); - glutSpecialFunc( SpecialKey ); - glutDisplayFunc( Display ); - glutIdleFunc( Idle ); - - glutCreateMenu(ModeMenu); - glutAddMenuEntry("Toggle Animation", ANIMATE); - glutAddMenuEntry("Toggle PBO", PBO); - glutAddMenuEntry("Quit", QUIT); - glutAttachMenu(GLUT_RIGHT_BUTTON); - - glutMainLoop(); - return 0; -} diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 90c41a327e..28b6fb9a5c 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -77,6 +77,7 @@ SOURCES = \ stencil_twoside.c \ stencilwrap.c \ stencil_wrap.c \ + streaming_rect \ subtex \ subtexrate.c \ tex1d.c \ diff --git a/progs/tests/streaming_rect.c b/progs/tests/streaming_rect.c new file mode 100644 index 0000000000..f65ac4ce36 --- /dev/null +++ b/progs/tests/streaming_rect.c @@ -0,0 +1,327 @@ +/* + * GL_ARB_pixel_buffer_object test + * + * Command line options: + * -w WIDTH -h HEIGHT sets window size + * + */ + +#include +#include +#include +#include +#include +#include + +#include "readtex.h" + + +#define ANIMATE 10 +#define PBO 11 +#define QUIT 100 + +static GLuint DrawPBO; + +static GLboolean Animate = GL_TRUE; +static GLboolean use_pbo = 1; +static GLboolean whole_rect = 1; + +static GLfloat Drift = 0.0; +static GLfloat drift_increment = 1/255.0; +static GLfloat Xrot = 20.0, Yrot = 30.0; + +static GLuint Width = 1024; +static GLuint Height = 512; + + +static void Idle( void ) +{ + if (Animate) { + + Drift += drift_increment; + if (Drift >= 1.0) + Drift = 0.0; + + glutPostRedisplay(); + } +} + +/*static int max( int a, int b ) { return a > b ? a : b; }*/ + +#ifndef min +static int min( int a, int b ) { return a < b ? a : b; } +#endif + +static void DrawObject() +{ + GLint size = Width * Height * 4; + + if (use_pbo) { + /* XXX: This is extremely important - semantically makes the buffer + * contents undefined, but in practice means that the driver can + * release the old copy of the texture and allocate a new one + * without waiting for outstanding rendering to complete. + */ + glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO); + glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, size, NULL, GL_STREAM_DRAW_ARB); + + { + char *image = glMapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, GL_WRITE_ONLY_ARB); + + printf("char %d\n", (unsigned char)(Drift * 255)); + + memset(image, (unsigned char)(Drift * 255), size); + + glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT); + } + + + /* BGRA is required for most hardware paths: + */ + glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, Width, Height, 0, + GL_BGRA, GL_UNSIGNED_BYTE, NULL); + } + else { + static char *image = NULL; + + if (image == NULL) + image = malloc(size); + + glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, 0); + + memset(image, (unsigned char)(Drift * 255), size); + + /* BGRA should be the fast path for regular uploads as well. + */ + glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, Width, Height, 0, + GL_BGRA, GL_UNSIGNED_BYTE, image); + } + + { + int x,y,w,h; + + if (whole_rect) { + x = y = 0; + w = Width; + h = Height; + } + else { + x = y = 0; + w = min(10, Width); + h = min(10, Height); + } + + glBegin(GL_QUADS); + + glTexCoord2f( x, y); + glVertex2f( x, y ); + + glTexCoord2f( x, y + h); + glVertex2f( x, y + h); + + glTexCoord2f( x + w + .5, y + h); + glVertex2f( x + w, y + h ); + + glTexCoord2f( x + w, y + .5); + glVertex2f( x + w, y ); + + glEnd(); + } +} + + + +static void Display( void ) +{ + static GLint T0 = 0; + static GLint Frames = 0; + GLint t; + + glClear( GL_COLOR_BUFFER_BIT ); + + glPushMatrix(); + DrawObject(); + glPopMatrix(); + + glutSwapBuffers(); + + Frames++; + + t = glutGet(GLUT_ELAPSED_TIME); + if (t - T0 >= 1000) { + GLfloat seconds = (t - T0) / 1000.0; + + GLfloat fps = Frames / seconds; + printf("%d frames in %6.3f seconds = %6.3f FPS\n", Frames, seconds, fps); + fflush(stdout); + + drift_increment = 2.2 * seconds / Frames; + T0 = t; + Frames = 0; + } +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); +/* glFrustum( -1.0, 1.0, -1.0, 1.0, 10.0, 100.0 ); */ + gluOrtho2D( 0, width, height, 0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef(0.375, 0.375, 0); +} + + +static void ModeMenu(int entry) +{ + if (entry==ANIMATE) { + Animate = !Animate; + } + else if (entry==PBO) { + use_pbo = !use_pbo; + } + else if (entry==QUIT) { + exit(0); + } + + glutPostRedisplay(); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + float step = 3.0; + (void) x; + (void) y; + + switch (key) { + case GLUT_KEY_UP: + Xrot += step; + break; + case GLUT_KEY_DOWN: + Xrot -= step; + break; + case GLUT_KEY_LEFT: + Yrot += step; + break; + case GLUT_KEY_RIGHT: + Yrot -= step; + break; + } + glutPostRedisplay(); +} + + +static void Init( int argc, char *argv[] ) +{ + const char *exten = (const char *) glGetString(GL_EXTENSIONS); + GLuint texObj; + GLint size; + + + if (!strstr(exten, "GL_ARB_pixel_buffer_object")) { + printf("Sorry, GL_ARB_pixel_buffer_object not supported by this renderer.\n"); + exit(1); + } + + glGetIntegerv(GL_MAX_TEXTURE_SIZE, &size); + printf("%d x %d max texture size\n", size, size); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + /* allocate two texture objects */ + glGenTextures(1, &texObj); + + /* setup the texture objects */ + glActiveTextureARB(GL_TEXTURE0_ARB); + glBindTexture(GL_TEXTURE_RECTANGLE_ARB, texObj); + + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + glGenBuffersARB(1, &DrawPBO); + + glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO); + glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, + Width * Height * 4, NULL, GL_STREAM_DRAW); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); + + glEnable(GL_TEXTURE_RECTANGLE_ARB); + + glShadeModel(GL_SMOOTH); + glClearColor(0.3, 0.3, 0.4, 1.0); + + if (argc > 1 && strcmp(argv[1], "-info")==0) { + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); + } +} + + +int main( int argc, char *argv[] ) +{ + GLint i; + + glutInit( &argc, argv ); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-w") == 0) { + Width = atoi(argv[i+1]); + if (Width <= 0) { + printf("Error, bad width\n"); + exit(1); + } + i++; + } + else if (strcmp(argv[i], "-h") == 0) { + Height = atoi(argv[i+1]); + if (Height <= 0) { + printf("Error, bad height\n"); + exit(1); + } + i++; + } + } + + glutInitWindowSize( Width, Height ); + glutInitWindowPosition( 0, 0 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); + glutCreateWindow(argv[0] ); + glewInit(); + + Init( argc, argv ); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + glutIdleFunc( Idle ); + + glutCreateMenu(ModeMenu); + glutAddMenuEntry("Toggle Animation", ANIMATE); + glutAddMenuEntry("Toggle PBO", PBO); + glutAddMenuEntry("Quit", QUIT); + glutAttachMenu(GLUT_RIGHT_BUTTON); + + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From dfd69a27f8c3db3d90e2334237bf4a8eabb17e9e Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 12:57:13 -0600 Subject: demos: move glutfx demo to tests/ --- progs/demos/Makefile | 1 - progs/demos/glutfx.c | 189 --------------------------------------------------- progs/tests/Makefile | 1 + progs/tests/glutfx.c | 189 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 190 insertions(+), 190 deletions(-) delete mode 100644 progs/demos/glutfx.c create mode 100644 progs/tests/glutfx.c (limited to 'progs') diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 1cdd963417..0d4b845137 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -33,7 +33,6 @@ PROGS = \ glinfo \ gloss \ gltestperf \ - glutfx \ isosurf \ ipers \ lodbias \ diff --git a/progs/demos/glutfx.c b/progs/demos/glutfx.c deleted file mode 100644 index 8bf5582389..0000000000 --- a/progs/demos/glutfx.c +++ /dev/null @@ -1,189 +0,0 @@ - -/* - * Example of how one might use GLUT with the 3Dfx driver in full-screen mode. - * Note: this only works with X since we're using Mesa's GLX "hack" for - * using Glide. - * - * Goals: - * easy setup and input event handling with GLUT - * use 3Dfx hardware - * automatically set MESA environment variables - * don't lose mouse input focus - * - * Brian Paul This file is in the public domain. - */ - - -#include -#include -#include -#include - - -#define WIDTH 640 -#define HEIGHT 480 - - -static int Window = 0; -static int ScreenWidth, ScreenHeight; -static GLuint Torus = 0; -static GLfloat Xrot = 0.0, Yrot = 0.0; - - - -static void Display( void ) -{ - static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0}; - static GLfloat red[4] = {1.0, 0.2, 0.2, 1.0}; - static GLfloat green[4] = {0.2, 1.0, 0.2, 1.0}; - - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - glPushMatrix(); - glRotatef(Xrot, 1, 0, 0); - glRotatef(Yrot, 0, 1, 0); - - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue); - glCallList(Torus); - - glRotatef(90.0, 1, 0, 0); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); - glCallList(Torus); - - glRotatef(90.0, 0, 1, 0); - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green); - glCallList(Torus); - - glPopMatrix(); - - glutSwapBuffers(); -} - - -static void Reshape( int width, int height ) -{ - float ratio = (float) width / (float) height; - - ScreenWidth = width; - ScreenHeight = height; - - /* - * The 3Dfx driver is limited to 640 x 480 but the X window may be larger. - * Enforce that here. - */ - if (width > WIDTH) - width = WIDTH; - if (height > HEIGHT) - height = HEIGHT; - - glViewport( 0, 0, width, height ); - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - glFrustum( -ratio, ratio, -1.0, 1.0, 5.0, 30.0 ); - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - glTranslatef( 0.0, 0.0, -20.0 ); -} - - -static void Key( unsigned char key, int x, int y ) -{ - (void) x; - (void) y; - switch (key) { - case 27: - glutDestroyWindow(Window); - exit(0); - break; - } - glutPostRedisplay(); -} - - -static void SpecialKey( int key, int x, int y ) -{ - (void) x; - (void) y; - switch (key) { - case GLUT_KEY_UP: - break; - case GLUT_KEY_DOWN: - break; - case GLUT_KEY_LEFT: - break; - case GLUT_KEY_RIGHT: - break; - } - glutPostRedisplay(); -} - - -static void MouseMove( int x, int y ) -{ - Xrot = y - ScreenWidth / 2; - Yrot = x - ScreenHeight / 2; - glutPostRedisplay(); -} - - -static void Init( void ) -{ - Torus = glGenLists(1); - glNewList(Torus, GL_COMPILE); - glutSolidTorus(0.5, 2.0, 10, 20); - glEndList(); - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); -} - - -int main( int argc, char *argv[] ) -{ -#ifndef _WIN32 - printf("NOTE: if you've got 3Dfx VooDoo hardware you must run this"); - printf(" program as root.\n\n"); - printf("Move the mouse. Press ESC to exit.\n\n"); -#endif - - /* Tell Mesa GLX to use 3Dfx driver in fullscreen mode. */ - putenv("MESA_GLX_FX=fullscreen"); - - /* Disable 3Dfx Glide splash screen */ - putenv("FX_GLIDE_NO_SPLASH="); - - /* Give an initial size and position so user doesn't have to place window */ - glutInitWindowPosition(0, 0); - glutInitWindowSize(WIDTH, HEIGHT); - glutInit( &argc, argv ); - - glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); - - Window = glutCreateWindow(argv[0]); - if (!Window) { - printf("Error, couldn't open window\n"); - exit(1); - } - - /* - * Want the X window to fill the screen so that we don't have to - * worry about losing the mouse input focus. - * Note that we won't actually see the X window since we never draw - * to it, hence, the original X screen's contents aren't disturbed. - */ - glutFullScreen(); - - Init(); - - glutReshapeFunc( Reshape ); - glutKeyboardFunc( Key ); - glutSpecialFunc( SpecialKey ); - glutDisplayFunc( Display ); - glutPassiveMotionFunc( MouseMove ); - - glutMainLoop(); - return 0; -} diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 28b6fb9a5c..18ea559b46 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -50,6 +50,7 @@ SOURCES = \ fptest1.c \ fptexture.c \ getprocaddress.c \ + glutfx \ interleave.c \ invert.c \ jkrahntest.c \ diff --git a/progs/tests/glutfx.c b/progs/tests/glutfx.c new file mode 100644 index 0000000000..8bf5582389 --- /dev/null +++ b/progs/tests/glutfx.c @@ -0,0 +1,189 @@ + +/* + * Example of how one might use GLUT with the 3Dfx driver in full-screen mode. + * Note: this only works with X since we're using Mesa's GLX "hack" for + * using Glide. + * + * Goals: + * easy setup and input event handling with GLUT + * use 3Dfx hardware + * automatically set MESA environment variables + * don't lose mouse input focus + * + * Brian Paul This file is in the public domain. + */ + + +#include +#include +#include +#include + + +#define WIDTH 640 +#define HEIGHT 480 + + +static int Window = 0; +static int ScreenWidth, ScreenHeight; +static GLuint Torus = 0; +static GLfloat Xrot = 0.0, Yrot = 0.0; + + + +static void Display( void ) +{ + static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0}; + static GLfloat red[4] = {1.0, 0.2, 0.2, 1.0}; + static GLfloat green[4] = {0.2, 1.0, 0.2, 1.0}; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glPushMatrix(); + glRotatef(Xrot, 1, 0, 0); + glRotatef(Yrot, 0, 1, 0); + + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue); + glCallList(Torus); + + glRotatef(90.0, 1, 0, 0); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red); + glCallList(Torus); + + glRotatef(90.0, 0, 1, 0); + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green); + glCallList(Torus); + + glPopMatrix(); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + float ratio = (float) width / (float) height; + + ScreenWidth = width; + ScreenHeight = height; + + /* + * The 3Dfx driver is limited to 640 x 480 but the X window may be larger. + * Enforce that here. + */ + if (width > WIDTH) + width = WIDTH; + if (height > HEIGHT) + height = HEIGHT; + + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -ratio, ratio, -1.0, 1.0, 5.0, 30.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -20.0 ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glutDestroyWindow(Window); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + break; + case GLUT_KEY_DOWN: + break; + case GLUT_KEY_LEFT: + break; + case GLUT_KEY_RIGHT: + break; + } + glutPostRedisplay(); +} + + +static void MouseMove( int x, int y ) +{ + Xrot = y - ScreenWidth / 2; + Yrot = x - ScreenHeight / 2; + glutPostRedisplay(); +} + + +static void Init( void ) +{ + Torus = glGenLists(1); + glNewList(Torus, GL_COMPILE); + glutSolidTorus(0.5, 2.0, 10, 20); + glEndList(); + + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); +} + + +int main( int argc, char *argv[] ) +{ +#ifndef _WIN32 + printf("NOTE: if you've got 3Dfx VooDoo hardware you must run this"); + printf(" program as root.\n\n"); + printf("Move the mouse. Press ESC to exit.\n\n"); +#endif + + /* Tell Mesa GLX to use 3Dfx driver in fullscreen mode. */ + putenv("MESA_GLX_FX=fullscreen"); + + /* Disable 3Dfx Glide splash screen */ + putenv("FX_GLIDE_NO_SPLASH="); + + /* Give an initial size and position so user doesn't have to place window */ + glutInitWindowPosition(0, 0); + glutInitWindowSize(WIDTH, HEIGHT); + glutInit( &argc, argv ); + + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + + Window = glutCreateWindow(argv[0]); + if (!Window) { + printf("Error, couldn't open window\n"); + exit(1); + } + + /* + * Want the X window to fill the screen so that we don't have to + * worry about losing the mouse input focus. + * Note that we won't actually see the X window since we never draw + * to it, hence, the original X screen's contents aren't disturbed. + */ + glutFullScreen(); + + Init(); + + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + glutPassiveMotionFunc( MouseMove ); + + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From f47495ec42491f1c32391f29e5ed8819eaef6ee2 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 12:58:00 -0600 Subject: demos: move texdown.c to tests/ --- progs/demos/Makefile | 1 - progs/demos/texdown.c | 477 -------------------------------------------------- progs/tests/Makefile | 1 + progs/tests/texdown.c | 477 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 478 insertions(+), 478 deletions(-) delete mode 100644 progs/demos/texdown.c create mode 100644 progs/tests/texdown.c (limited to 'progs') diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 0d4b845137..0f72595c23 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -54,7 +54,6 @@ PROGS = \ terrain \ tessdemo \ texcyl \ - texdown \ texenv \ texobj \ textures \ diff --git a/progs/demos/texdown.c b/progs/demos/texdown.c deleted file mode 100644 index 7e46045832..0000000000 --- a/progs/demos/texdown.c +++ /dev/null @@ -1,477 +0,0 @@ - -/* - * Copyright (C) 1999 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * texdown - * - * Measure texture download speed. - * Use keyboard to change texture size, format, datatype, scale/bias, - * subimageload, etc. - * - * Brian Paul 28 January 2000 - */ - - -#include -#include -#include -#include - - -static GLsizei MaxSize = 2048; -static GLsizei TexWidth = 1024, TexHeight = 1024, TexBorder = 0; -static GLboolean ScaleAndBias = GL_FALSE; -static GLboolean SubImage = GL_FALSE; -static GLdouble DownloadRate = 0.0; /* texels/sec */ - -static GLuint Mode = 0; - - -/* Try and avoid L2 cache effects by cycling through a small number of - * textures. - * - * At the initial size of 1024x1024x4 == 4mbyte, say 8 textures will - * keep us out of most caches at 32mb total. - * - * This turns into a fairly interesting question of what exactly you - * expect to be in cache in normal usage, and what you think should be - * outside. There's no rules for this, no reason to favour one usage - * over another except what the application you care about happens to - * resemble most closely. - * - * - Should the client texture image be in L2 cache? Has it just been - * generated or read from disk? - * - Does the application really use >1 texture, or is it constantly - * updating one image in-place? - * - * Different answers will favour different texture upload mechanisms. - * To upload an image that is purely outside of cache, a DMA-based - * upload will probably win, whereas for small, in-cache textures, - * copying looks good. - */ -#define NR_TEXOBJ 4 -static GLuint TexObj[NR_TEXOBJ]; - - -struct FormatRec { - GLenum Format; - GLenum Type; - GLenum IntFormat; - GLint TexelSize; -}; - - -static const struct FormatRec FormatTable[] = { - /* Format Type IntFormat TexelSize */ - { GL_BGRA, GL_UNSIGNED_BYTE, GL_RGBA, 4 }, - { GL_RGB, GL_UNSIGNED_BYTE, GL_RGB, 3 }, - { GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA, 4 }, - { GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB, 4 }, - { GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB, 2 }, - { GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE, 1 }, - { GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA, 2 }, - { GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA, 1 }, -}; -static GLint Format; - -#define NUM_FORMATS (sizeof(FormatTable)/sizeof(FormatTable[0])) - -static int -BytesPerTexel(GLint format) -{ - return FormatTable[format].TexelSize; -} - - -static const char * -FormatStr(GLenum format) -{ - switch (format) { - case GL_RGB: - return "GL_RGB"; - case GL_RGBA: - return "GL_RGBA"; - case GL_BGRA: - return "GL_BGRA"; - case GL_LUMINANCE: - return "GL_LUMINANCE"; - case GL_LUMINANCE_ALPHA: - return "GL_LUMINANCE_ALPHA"; - case GL_ALPHA: - return "GL_ALPHA"; - default: - return ""; - } -} - - -static const char * -TypeStr(GLenum type) -{ - switch (type) { - case GL_UNSIGNED_BYTE: - return "GL_UNSIGNED_BYTE"; - case GL_UNSIGNED_SHORT: - return "GL_UNSIGNED_SHORT"; - case GL_UNSIGNED_SHORT_5_6_5: - return "GL_UNSIGNED_SHORT_5_6_5"; - case GL_UNSIGNED_SHORT_5_6_5_REV: - return "GL_UNSIGNED_SHORT_5_6_5_REV"; - default: - return ""; - } -} - -/* On x86, there is a performance cliff for memcpy to texture memory - * for sources below 64 byte alignment. We do our best with this in - * the driver, but it is better if the images are correctly aligned to - * start with: - */ -#define ALIGN (1<<12) - -static unsigned long align(unsigned long value, unsigned long a) -{ - return (value + a - 1) & ~(a-1); -} - -static void -MeasureDownloadRate(void) -{ - const int w = TexWidth + 2 * TexBorder; - const int h = TexHeight + 2 * TexBorder; - const int image_bytes = align(w * h * BytesPerTexel(Format), ALIGN); - const int bytes = image_bytes * NR_TEXOBJ; - GLubyte *orig_texImage, *orig_getImage; - GLubyte *texImage, *getImage; - GLdouble t0, t1, time; - int count; - int i; - int offset = 0; - GLdouble total = 0; /* ints will tend to overflow */ - - printf("allocating %d bytes for %d %dx%d images\n", - bytes, NR_TEXOBJ, w, h); - - orig_texImage = (GLubyte *) malloc(bytes + ALIGN); - orig_getImage = (GLubyte *) malloc(image_bytes + ALIGN); - if (!orig_texImage || !orig_getImage) { - DownloadRate = 0.0; - return; - } - - printf("alloc %p %p\n", orig_texImage, orig_getImage); - - texImage = (GLubyte *)align((unsigned long)orig_texImage, ALIGN); - getImage = (GLubyte *)align((unsigned long)orig_getImage, ALIGN); - - for (i = 1; !(((unsigned long)texImage) & i); i<<=1) - ; - printf("texture image alignment: %d bytes (%p)\n", i, texImage); - - for (i = 0; i < bytes; i++) { - texImage[i] = i & 0xff; - } - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glPixelStorei(GL_PACK_ALIGNMENT, 1); - - if (ScaleAndBias) { - glPixelTransferf(GL_RED_SCALE, 0.5); - glPixelTransferf(GL_GREEN_SCALE, 0.5); - glPixelTransferf(GL_BLUE_SCALE, 0.5); - glPixelTransferf(GL_RED_BIAS, 0.5); - glPixelTransferf(GL_GREEN_BIAS, 0.5); - glPixelTransferf(GL_BLUE_BIAS, 0.5); - } - else { - glPixelTransferf(GL_RED_SCALE, 1.0); - glPixelTransferf(GL_GREEN_SCALE, 1.0); - glPixelTransferf(GL_BLUE_SCALE, 1.0); - glPixelTransferf(GL_RED_BIAS, 0.0); - glPixelTransferf(GL_GREEN_BIAS, 0.0); - glPixelTransferf(GL_BLUE_BIAS, 0.0); - } - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glEnable(GL_TEXTURE_2D); - - count = 0; - t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001; - do { - int img = count%NR_TEXOBJ; - GLubyte *img_ptr = texImage + img * image_bytes; - - glBindTexture(GL_TEXTURE_2D, TexObj[img]); - - if (SubImage && count > 0) { - /* Only update a portion of the image each iteration. This - * is presumably why you'd want to use texsubimage, otherwise - * you may as well just call teximage again. - * - * A bigger question is whether to use a pointer that moves - * with each call, ie does the incoming data come from L2 - * cache under normal circumstances, or is it pulled from - * uncached memory? - * - * There's a good argument to say L2 cache, ie you'd expect - * the data to have been recently generated. It's possible - * that it could have come from a file read, which may or may - * not have gone through the cpu. - */ - glTexSubImage2D(GL_TEXTURE_2D, 0, - -TexBorder, - -TexBorder + offset * h/8, - w, - h/8, - FormatTable[Format].Format, - FormatTable[Format].Type, -#if 1 - texImage /* likely in L2$ */ -#else - img_ptr + offset * bytes/8 /* unlikely in L2$ */ -#endif - ); - offset += 1; - offset %= 8; - total += w * h / 8; - } - else { - glTexImage2D(GL_TEXTURE_2D, 0, - FormatTable[Format].IntFormat, w, h, TexBorder, - FormatTable[Format].Format, - FormatTable[Format].Type, - img_ptr); - total += w*h; - } - - /* draw a tiny polygon to force texture into texram */ - glBegin(GL_TRIANGLES); - glTexCoord2f(0, 0); glVertex2f(1, 1); - glTexCoord2f(1, 0); glVertex2f(3, 1); - glTexCoord2f(0.5, 1); glVertex2f(2, 3); - glEnd(); - - t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001; - time = t1 - t0; - count++; - } while (time < 3.0); - - glDisable(GL_TEXTURE_2D); - - printf("total texels=%f time=%f\n", total, time); - DownloadRate = total / time; - - - free(orig_texImage); - free(orig_getImage); - - { - GLint err = glGetError(); - if (err) - printf("GL error %d\n", err); - } -} - - -static void -PrintString(const char *s) -{ - while (*s) { - glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); - s++; - } -} - - -static void -Display(void) -{ - const int w = TexWidth + 2 * TexBorder; - const int h = TexHeight + 2 * TexBorder; - char s[1000]; - - glClear(GL_COLOR_BUFFER_BIT); - - glRasterPos2i(10, 80); - sprintf(s, "Texture size[cursor]: %d x %d Border[b]: %d", w, h, TexBorder); - PrintString(s); - - glRasterPos2i(10, 65); - sprintf(s, "Format[f]: %s Type: %s IntFormat: %s", - FormatStr(FormatTable[Format].Format), - TypeStr( FormatTable[Format].Type), - FormatStr(FormatTable[Format].IntFormat)); - PrintString(s); - - glRasterPos2i(10, 50); - sprintf(s, "Pixel Scale&Bias[p]: %s TexSubImage[s]: %s", - ScaleAndBias ? "Yes" : "No", - SubImage ? "Yes" : "No"); - PrintString(s); - - if (Mode == 0) { - glRasterPos2i(200, 10); - sprintf(s, "...Measuring..."); - PrintString(s); - glutSwapBuffers(); - glutPostRedisplay(); - Mode++; - } - else if (Mode == 1) { - MeasureDownloadRate(); - glutPostRedisplay(); - Mode++; - } - else { - /* show results */ - glRasterPos2i(10, 10); - sprintf(s, "Download rate: %g Mtexels/second %g MB/second", - DownloadRate / 1000000.0, - DownloadRate * BytesPerTexel(Format) / 1000000.0); - PrintString(s); - { - GLint r, g, b, a, l, i; - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &r); - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &g); - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &b); - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &a); - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_LUMINANCE_SIZE, &l); - glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTENSITY_SIZE, &i); - sprintf(s, "TexelBits: R=%d G=%d B=%d A=%d L=%d I=%d", r, g, b, a, l, i); - glRasterPos2i(10, 25); - PrintString(s); - } - - glutSwapBuffers(); - } -} - - -static void -Reshape(int width, int height) -{ - glViewport( 0, 0, width, height ); - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - glOrtho(0, width, 0, height, -1, 1); - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); -} - - - -static void -Key(unsigned char key, int x, int y) -{ - (void) x; - (void) y; - switch (key) { - case ' ': - Mode = 0; - break; - case 'b': - /* toggle border */ - TexBorder = 1 - TexBorder; - Mode = 0; - break; - case 'f': - /* change format */ - Format = (Format + 1) % NUM_FORMATS; - Mode = 0; - break; - case 'F': - /* change format */ - Format = (Format - 1) % NUM_FORMATS; - Mode = 0; - break; - case 'p': - /* toggle border */ - ScaleAndBias = !ScaleAndBias; - Mode = 0; - break; - case 's': - SubImage = !SubImage; - Mode = 0; - break; - case 27: - exit(0); - break; - } - glutPostRedisplay(); -} - - -static void -SpecialKey(int key, int x, int y) -{ - (void) x; - (void) y; - switch (key) { - case GLUT_KEY_UP: - if (TexHeight < MaxSize) - TexHeight *= 2; - break; - case GLUT_KEY_DOWN: - if (TexHeight > 1) - TexHeight /= 2; - break; - case GLUT_KEY_LEFT: - if (TexWidth > 1) - TexWidth /= 2; - break; - case GLUT_KEY_RIGHT: - if (TexWidth < MaxSize) - TexWidth *= 2; - break; - } - Mode = 0; - glutPostRedisplay(); -} - - -static void -Init(void) -{ - printf("GL_VENDOR = %s\n", (const char *) glGetString(GL_VENDOR)); - printf("GL_VERSION = %s\n", (const char *) glGetString(GL_VERSION)); - printf("GL_RENDERER = %s\n", (const char *) glGetString(GL_RENDERER)); -} - - -int -main(int argc, char *argv[]) -{ - glutInit( &argc, argv ); - glutInitWindowPosition( 0, 0 ); - glutInitWindowSize( 600, 100 ); - glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); - glutCreateWindow(argv[0]); - glutReshapeFunc( Reshape ); - glutKeyboardFunc( Key ); - glutSpecialFunc( SpecialKey ); - glutDisplayFunc( Display ); - Init(); - glutMainLoop(); - return 0; -} diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 18ea559b46..cd6c496961 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -83,6 +83,7 @@ SOURCES = \ subtexrate.c \ tex1d.c \ texcompress2.c \ + texdown \ texfilt.c \ texline.c \ texobjshare.c \ diff --git a/progs/tests/texdown.c b/progs/tests/texdown.c new file mode 100644 index 0000000000..7e46045832 --- /dev/null +++ b/progs/tests/texdown.c @@ -0,0 +1,477 @@ + +/* + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +/* + * texdown + * + * Measure texture download speed. + * Use keyboard to change texture size, format, datatype, scale/bias, + * subimageload, etc. + * + * Brian Paul 28 January 2000 + */ + + +#include +#include +#include +#include + + +static GLsizei MaxSize = 2048; +static GLsizei TexWidth = 1024, TexHeight = 1024, TexBorder = 0; +static GLboolean ScaleAndBias = GL_FALSE; +static GLboolean SubImage = GL_FALSE; +static GLdouble DownloadRate = 0.0; /* texels/sec */ + +static GLuint Mode = 0; + + +/* Try and avoid L2 cache effects by cycling through a small number of + * textures. + * + * At the initial size of 1024x1024x4 == 4mbyte, say 8 textures will + * keep us out of most caches at 32mb total. + * + * This turns into a fairly interesting question of what exactly you + * expect to be in cache in normal usage, and what you think should be + * outside. There's no rules for this, no reason to favour one usage + * over another except what the application you care about happens to + * resemble most closely. + * + * - Should the client texture image be in L2 cache? Has it just been + * generated or read from disk? + * - Does the application really use >1 texture, or is it constantly + * updating one image in-place? + * + * Different answers will favour different texture upload mechanisms. + * To upload an image that is purely outside of cache, a DMA-based + * upload will probably win, whereas for small, in-cache textures, + * copying looks good. + */ +#define NR_TEXOBJ 4 +static GLuint TexObj[NR_TEXOBJ]; + + +struct FormatRec { + GLenum Format; + GLenum Type; + GLenum IntFormat; + GLint TexelSize; +}; + + +static const struct FormatRec FormatTable[] = { + /* Format Type IntFormat TexelSize */ + { GL_BGRA, GL_UNSIGNED_BYTE, GL_RGBA, 4 }, + { GL_RGB, GL_UNSIGNED_BYTE, GL_RGB, 3 }, + { GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA, 4 }, + { GL_RGBA, GL_UNSIGNED_BYTE, GL_RGB, 4 }, + { GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB, 2 }, + { GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE, 1 }, + { GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE_ALPHA, 2 }, + { GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA, 1 }, +}; +static GLint Format; + +#define NUM_FORMATS (sizeof(FormatTable)/sizeof(FormatTable[0])) + +static int +BytesPerTexel(GLint format) +{ + return FormatTable[format].TexelSize; +} + + +static const char * +FormatStr(GLenum format) +{ + switch (format) { + case GL_RGB: + return "GL_RGB"; + case GL_RGBA: + return "GL_RGBA"; + case GL_BGRA: + return "GL_BGRA"; + case GL_LUMINANCE: + return "GL_LUMINANCE"; + case GL_LUMINANCE_ALPHA: + return "GL_LUMINANCE_ALPHA"; + case GL_ALPHA: + return "GL_ALPHA"; + default: + return ""; + } +} + + +static const char * +TypeStr(GLenum type) +{ + switch (type) { + case GL_UNSIGNED_BYTE: + return "GL_UNSIGNED_BYTE"; + case GL_UNSIGNED_SHORT: + return "GL_UNSIGNED_SHORT"; + case GL_UNSIGNED_SHORT_5_6_5: + return "GL_UNSIGNED_SHORT_5_6_5"; + case GL_UNSIGNED_SHORT_5_6_5_REV: + return "GL_UNSIGNED_SHORT_5_6_5_REV"; + default: + return ""; + } +} + +/* On x86, there is a performance cliff for memcpy to texture memory + * for sources below 64 byte alignment. We do our best with this in + * the driver, but it is better if the images are correctly aligned to + * start with: + */ +#define ALIGN (1<<12) + +static unsigned long align(unsigned long value, unsigned long a) +{ + return (value + a - 1) & ~(a-1); +} + +static void +MeasureDownloadRate(void) +{ + const int w = TexWidth + 2 * TexBorder; + const int h = TexHeight + 2 * TexBorder; + const int image_bytes = align(w * h * BytesPerTexel(Format), ALIGN); + const int bytes = image_bytes * NR_TEXOBJ; + GLubyte *orig_texImage, *orig_getImage; + GLubyte *texImage, *getImage; + GLdouble t0, t1, time; + int count; + int i; + int offset = 0; + GLdouble total = 0; /* ints will tend to overflow */ + + printf("allocating %d bytes for %d %dx%d images\n", + bytes, NR_TEXOBJ, w, h); + + orig_texImage = (GLubyte *) malloc(bytes + ALIGN); + orig_getImage = (GLubyte *) malloc(image_bytes + ALIGN); + if (!orig_texImage || !orig_getImage) { + DownloadRate = 0.0; + return; + } + + printf("alloc %p %p\n", orig_texImage, orig_getImage); + + texImage = (GLubyte *)align((unsigned long)orig_texImage, ALIGN); + getImage = (GLubyte *)align((unsigned long)orig_getImage, ALIGN); + + for (i = 1; !(((unsigned long)texImage) & i); i<<=1) + ; + printf("texture image alignment: %d bytes (%p)\n", i, texImage); + + for (i = 0; i < bytes; i++) { + texImage[i] = i & 0xff; + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + if (ScaleAndBias) { + glPixelTransferf(GL_RED_SCALE, 0.5); + glPixelTransferf(GL_GREEN_SCALE, 0.5); + glPixelTransferf(GL_BLUE_SCALE, 0.5); + glPixelTransferf(GL_RED_BIAS, 0.5); + glPixelTransferf(GL_GREEN_BIAS, 0.5); + glPixelTransferf(GL_BLUE_BIAS, 0.5); + } + else { + glPixelTransferf(GL_RED_SCALE, 1.0); + glPixelTransferf(GL_GREEN_SCALE, 1.0); + glPixelTransferf(GL_BLUE_SCALE, 1.0); + glPixelTransferf(GL_RED_BIAS, 0.0); + glPixelTransferf(GL_GREEN_BIAS, 0.0); + glPixelTransferf(GL_BLUE_BIAS, 0.0); + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glEnable(GL_TEXTURE_2D); + + count = 0; + t0 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + do { + int img = count%NR_TEXOBJ; + GLubyte *img_ptr = texImage + img * image_bytes; + + glBindTexture(GL_TEXTURE_2D, TexObj[img]); + + if (SubImage && count > 0) { + /* Only update a portion of the image each iteration. This + * is presumably why you'd want to use texsubimage, otherwise + * you may as well just call teximage again. + * + * A bigger question is whether to use a pointer that moves + * with each call, ie does the incoming data come from L2 + * cache under normal circumstances, or is it pulled from + * uncached memory? + * + * There's a good argument to say L2 cache, ie you'd expect + * the data to have been recently generated. It's possible + * that it could have come from a file read, which may or may + * not have gone through the cpu. + */ + glTexSubImage2D(GL_TEXTURE_2D, 0, + -TexBorder, + -TexBorder + offset * h/8, + w, + h/8, + FormatTable[Format].Format, + FormatTable[Format].Type, +#if 1 + texImage /* likely in L2$ */ +#else + img_ptr + offset * bytes/8 /* unlikely in L2$ */ +#endif + ); + offset += 1; + offset %= 8; + total += w * h / 8; + } + else { + glTexImage2D(GL_TEXTURE_2D, 0, + FormatTable[Format].IntFormat, w, h, TexBorder, + FormatTable[Format].Format, + FormatTable[Format].Type, + img_ptr); + total += w*h; + } + + /* draw a tiny polygon to force texture into texram */ + glBegin(GL_TRIANGLES); + glTexCoord2f(0, 0); glVertex2f(1, 1); + glTexCoord2f(1, 0); glVertex2f(3, 1); + glTexCoord2f(0.5, 1); glVertex2f(2, 3); + glEnd(); + + t1 = glutGet(GLUT_ELAPSED_TIME) * 0.001; + time = t1 - t0; + count++; + } while (time < 3.0); + + glDisable(GL_TEXTURE_2D); + + printf("total texels=%f time=%f\n", total, time); + DownloadRate = total / time; + + + free(orig_texImage); + free(orig_getImage); + + { + GLint err = glGetError(); + if (err) + printf("GL error %d\n", err); + } +} + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + +static void +Display(void) +{ + const int w = TexWidth + 2 * TexBorder; + const int h = TexHeight + 2 * TexBorder; + char s[1000]; + + glClear(GL_COLOR_BUFFER_BIT); + + glRasterPos2i(10, 80); + sprintf(s, "Texture size[cursor]: %d x %d Border[b]: %d", w, h, TexBorder); + PrintString(s); + + glRasterPos2i(10, 65); + sprintf(s, "Format[f]: %s Type: %s IntFormat: %s", + FormatStr(FormatTable[Format].Format), + TypeStr( FormatTable[Format].Type), + FormatStr(FormatTable[Format].IntFormat)); + PrintString(s); + + glRasterPos2i(10, 50); + sprintf(s, "Pixel Scale&Bias[p]: %s TexSubImage[s]: %s", + ScaleAndBias ? "Yes" : "No", + SubImage ? "Yes" : "No"); + PrintString(s); + + if (Mode == 0) { + glRasterPos2i(200, 10); + sprintf(s, "...Measuring..."); + PrintString(s); + glutSwapBuffers(); + glutPostRedisplay(); + Mode++; + } + else if (Mode == 1) { + MeasureDownloadRate(); + glutPostRedisplay(); + Mode++; + } + else { + /* show results */ + glRasterPos2i(10, 10); + sprintf(s, "Download rate: %g Mtexels/second %g MB/second", + DownloadRate / 1000000.0, + DownloadRate * BytesPerTexel(Format) / 1000000.0); + PrintString(s); + { + GLint r, g, b, a, l, i; + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &r); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_GREEN_SIZE, &g); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_BLUE_SIZE, &b); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_ALPHA_SIZE, &a); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_LUMINANCE_SIZE, &l); + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_INTENSITY_SIZE, &i); + sprintf(s, "TexelBits: R=%d G=%d B=%d A=%d L=%d I=%d", r, g, b, a, l, i); + glRasterPos2i(10, 25); + PrintString(s); + } + + glutSwapBuffers(); + } +} + + +static void +Reshape(int width, int height) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(0, width, 0, height, -1, 1); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); +} + + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case ' ': + Mode = 0; + break; + case 'b': + /* toggle border */ + TexBorder = 1 - TexBorder; + Mode = 0; + break; + case 'f': + /* change format */ + Format = (Format + 1) % NUM_FORMATS; + Mode = 0; + break; + case 'F': + /* change format */ + Format = (Format - 1) % NUM_FORMATS; + Mode = 0; + break; + case 'p': + /* toggle border */ + ScaleAndBias = !ScaleAndBias; + Mode = 0; + break; + case 's': + SubImage = !SubImage; + Mode = 0; + break; + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +SpecialKey(int key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_UP: + if (TexHeight < MaxSize) + TexHeight *= 2; + break; + case GLUT_KEY_DOWN: + if (TexHeight > 1) + TexHeight /= 2; + break; + case GLUT_KEY_LEFT: + if (TexWidth > 1) + TexWidth /= 2; + break; + case GLUT_KEY_RIGHT: + if (TexWidth < MaxSize) + TexWidth *= 2; + break; + } + Mode = 0; + glutPostRedisplay(); +} + + +static void +Init(void) +{ + printf("GL_VENDOR = %s\n", (const char *) glGetString(GL_VENDOR)); + printf("GL_VERSION = %s\n", (const char *) glGetString(GL_VERSION)); + printf("GL_RENDERER = %s\n", (const char *) glGetString(GL_RENDERER)); +} + + +int +main(int argc, char *argv[]) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 600, 100 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 292e1920930dad242b1130cb2b7b4ced2a3024f8 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 13:00:48 -0600 Subject: demos: move tests/fbotexture.c to demos/ --- progs/demos/Makefile | 1 + progs/demos/fbotexture.c | 621 +++++++++++++++++++++++++++++++++++++++++++++++ progs/tests/Makefile | 1 - progs/tests/fbotexture.c | 621 ----------------------------------------------- 4 files changed, 622 insertions(+), 622 deletions(-) create mode 100644 progs/demos/fbotexture.c delete mode 100644 progs/tests/fbotexture.c (limited to 'progs') diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 0f72595c23..a1c99c6c54 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -22,6 +22,7 @@ PROGS = \ drawpix \ engine \ fbo_firecube \ + fbotexture \ fire \ fogcoord \ fplight \ diff --git a/progs/demos/fbotexture.c b/progs/demos/fbotexture.c new file mode 100644 index 0000000000..50a4b00afc --- /dev/null +++ b/progs/demos/fbotexture.c @@ -0,0 +1,621 @@ +/* + * Test GL_EXT_framebuffer_object render-to-texture + * + * Draw a teapot into a texture image with stenciling. + * Then draw a textured quad using that texture. + * + * Brian Paul + * 18 Apr 2005 + */ + + +#include +#include +#include +#include +#include +#include +#include + +/* For debug */ +#define DEPTH 1 +#define STENCIL 1 +#define DRAW 1 + + +static int Win = 0; +static int Width = 400, Height = 400; + +#if 1 +static GLenum TexTarget = GL_TEXTURE_2D; +static int TexWidth = 512, TexHeight = 512; +static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */ +#else +static GLenum TexTarget = GL_TEXTURE_RECTANGLE_ARB; +static int TexWidth = 200, TexHeight = 200; +static GLenum TexIntFormat = GL_RGB5; /* either GL_RGB or GL_RGBA */ +#endif +static GLuint TextureLevel = 0; /* which texture level to render to */ + +static GLuint MyFB; +static GLuint TexObj; +static GLuint DepthRB = 0, StencilRB = 0; +static GLboolean Anim = GL_FALSE; +static GLfloat Rot = 0.0; +static GLboolean UsePackedDepthStencil = GL_FALSE; +static GLboolean UsePackedDepthStencilBoth = GL_FALSE; +static GLboolean Use_ARB_fbo = GL_FALSE; +static GLboolean Cull = GL_FALSE; +static GLboolean Wireframe = GL_FALSE; + + +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("GL Error 0x%x at line %d\n", (int) err, line); + } +} + + +static void +Idle(void) +{ + Rot = glutGet(GLUT_ELAPSED_TIME) * 0.1; + glutPostRedisplay(); +} + + +static void +RenderTexture(void) +{ + GLenum status; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -15.0); + + /* draw to texture image */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + printf("Framebuffer incomplete!!!\n"); + } + + glViewport(0, 0, TexWidth, TexHeight); + + glClearColor(0.5, 0.5, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + CheckError(__LINE__); + +#if DEPTH + glEnable(GL_DEPTH_TEST); +#endif + +#if STENCIL + glEnable(GL_STENCIL_TEST); + glStencilFunc(GL_NEVER, 1, ~0); + glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE); +#endif + + CheckError(__LINE__); + +#if DEPTH || STENCIL + /* draw diamond-shaped stencil pattern */ + glColor3f(0, 1, 0); + glBegin(GL_POLYGON); + glVertex2f(-0.2, 0.0); + glVertex2f( 0.0, -0.2); + glVertex2f( 0.2, 0.0); + glVertex2f( 0.0, 0.2); + glEnd(); +#endif + + /* draw teapot where stencil != 1 */ +#if STENCIL + glStencilFunc(GL_NOTEQUAL, 1, ~0); + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); +#endif + + CheckError(__LINE__); + + if (Wireframe) { + glPolygonMode(GL_FRONT, GL_LINE); + } + else { + glPolygonMode(GL_FRONT, GL_FILL); + } + + if (Cull) { + /* cull back */ + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + } + else { + glDisable(GL_CULL_FACE); + } + +#if 0 + glBegin(GL_POLYGON); + glColor3f(1, 0, 0); + glVertex2f(-1, -1); + glColor3f(0, 1, 0); + glVertex2f(1, -1); + glColor3f(0, 0, 1); + glVertex2f(0, 1); + glEnd(); +#else + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glPushMatrix(); + glRotatef(0.5 * Rot, 1.0, 0.0, 0.0); + glFrontFace(GL_CW); /* Teapot patches backward */ + glutSolidTeapot(0.5); + glFrontFace(GL_CCW); + glPopMatrix(); + glDisable(GL_LIGHTING); + /* + PrintStencilHistogram(TexWidth, TexHeight); + */ +#endif + + glDisable(GL_DEPTH_TEST); + glDisable(GL_STENCIL_TEST); + glDisable(GL_CULL_FACE); + glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); + +#if DRAW + /* Bind normal framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); +#endif + + CheckError(__LINE__); +} + + + +static void +Display(void) +{ + float ar = (float) Width / (float) Height; + + RenderTexture(); + + /* draw textured quad in the window */ +#if DRAW + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -7.0); + + glViewport(0, 0, Width, Height); + + glClearColor(0.25, 0.25, 0.25, 0); + glClear(GL_COLOR_BUFFER_BIT); + + glPushMatrix(); + glRotatef(Rot, 0, 1, 0); + glEnable(TexTarget); + glBindTexture(TexTarget, TexObj); + glBegin(GL_POLYGON); + glColor3f(0.25, 0.25, 0.25); + if (TexTarget == GL_TEXTURE_2D) { + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(1, 0); + glVertex2f(1, -1); + glColor3f(1.0, 1.0, 1.0); + glTexCoord2f(1, 1); + glVertex2f(1, 1); + glTexCoord2f(0, 1); + glVertex2f(-1, 1); + } + else { + assert(TexTarget == GL_TEXTURE_RECTANGLE_ARB); + glTexCoord2f(0, 0); + glVertex2f(-1, -1); + glTexCoord2f(TexWidth, 0); + glVertex2f(1, -1); + glColor3f(1.0, 1.0, 1.0); + glTexCoord2f(TexWidth, TexHeight); + glVertex2f(1, 1); + glTexCoord2f(0, TexHeight); + glVertex2f(-1, 1); + } + glEnd(); + glPopMatrix(); + glDisable(TexTarget); +#endif + + glutSwapBuffers(); + CheckError(__LINE__); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + Width = width; + Height = height; +} + + +static void +CleanUp(void) +{ +#if DEPTH + glDeleteRenderbuffersEXT(1, &DepthRB); +#endif +#if STENCIL + glDeleteRenderbuffersEXT(1, &StencilRB); +#endif + glDeleteFramebuffersEXT(1, &MyFB); + + glDeleteTextures(1, &TexObj); + + glutDestroyWindow(Win); + + exit(0); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 'c': + Cull = !Cull; + break; + case 'w': + Wireframe = !Wireframe; + break; + case 's': + Rot += 2.0; + break; + case 'S': + Rot -= 2.0; + break; + case 27: + CleanUp(); + break; + } + glutPostRedisplay(); +} + + +/** + * Attach depth and stencil renderbuffer(s) to the given framebuffer object. + * \param tryDepthStencil if true, try to use a combined depth+stencil buffer + * \param bindDepthStencil if true, and tryDepthStencil is true, bind with + * the GL_DEPTH_STENCIL_ATTACHMENT target. + * \return GL_TRUE for success, GL_FALSE for failure + */ +static GLboolean +AttachDepthAndStencilBuffers(GLuint fbo, + GLsizei width, GLsizei height, + GLboolean tryDepthStencil, + GLboolean bindDepthStencil, + GLuint *depthRbOut, GLuint *stencilRbOut) +{ + GLenum status; + + *depthRbOut = *stencilRbOut = 0; + + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); + + if (tryDepthStencil) { + GLuint rb; + + glGenRenderbuffersEXT(1, &rb); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, + GL_DEPTH24_STENCIL8_EXT, + width, height); + if (glGetError()) + return GL_FALSE; + + if (bindDepthStencil) { + /* attach to both depth and stencil at once */ + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_DEPTH_STENCIL_ATTACHMENT, + GL_RENDERBUFFER_EXT, rb); + if (glGetError()) + return GL_FALSE; + } + else { + /* attach to depth attachment point */ + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_DEPTH_ATTACHMENT_EXT, + GL_RENDERBUFFER_EXT, rb); + if (glGetError()) + return GL_FALSE; + + /* and attach to stencil attachment point */ + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_STENCIL_ATTACHMENT_EXT, + GL_RENDERBUFFER_EXT, rb); + if (glGetError()) + return GL_FALSE; + } + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) + return GL_FALSE; + + *depthRbOut = *stencilRbOut = rb; + return GL_TRUE; + } + + /* just depth renderbuffer */ + { + GLuint rb; + + glGenRenderbuffersEXT(1, &rb); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, + GL_DEPTH_COMPONENT, + width, height); + if (glGetError()) + return GL_FALSE; + + /* attach to depth attachment point */ + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_DEPTH_ATTACHMENT_EXT, + GL_RENDERBUFFER_EXT, rb); + if (glGetError()) + return GL_FALSE; + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) + return GL_FALSE; + + *depthRbOut = rb; + } + + /* just stencil renderbuffer */ + { + GLuint rb; + + glGenRenderbuffersEXT(1, &rb); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, + GL_STENCIL_INDEX, + width, height); + if (glGetError()) + return GL_FALSE; + + /* attach to depth attachment point */ + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, + GL_STENCIL_ATTACHMENT_EXT, + GL_RENDERBUFFER_EXT, rb); + if (glGetError()) + return GL_FALSE; + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + glDeleteRenderbuffersEXT(1, depthRbOut); + *depthRbOut = 0; + glDeleteRenderbuffersEXT(1, &rb); + return GL_FALSE; + } + + *stencilRbOut = rb; + } + + return GL_TRUE; +} + + +static void +ParseArgs(int argc, char *argv[]) +{ + GLint i; + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-ds") == 0) { + if (!glutExtensionSupported("GL_EXT_packed_depth_stencil")) { + printf("GL_EXT_packed_depth_stencil not found!\n"); + exit(0); + } + UsePackedDepthStencil = GL_TRUE; + printf("Using GL_EXT_packed_depth_stencil\n"); + } + else if (strcmp(argv[i], "-ds2") == 0) { + if (!glutExtensionSupported("GL_EXT_packed_depth_stencil")) { + printf("GL_EXT_packed_depth_stencil not found!\n"); + exit(0); + } + if (!glutExtensionSupported("GL_ARB_framebuffer_object")) { + printf("GL_ARB_framebuffer_object not found!\n"); + exit(0); + } + UsePackedDepthStencilBoth = GL_TRUE; + printf("Using GL_EXT_packed_depth_stencil and GL_DEPTH_STENCIL attachment point\n"); + } + else if (strcmp(argv[i], "-arb") == 0) { + if (!glutExtensionSupported("GL_ARB_framebuffer_object")) { + printf("Sorry, GL_ARB_framebuffer object not supported!\n"); + } + else { + Use_ARB_fbo = GL_TRUE; + } + } + else { + printf("Unknown option: %s\n", argv[i]); + } + } +} + + +/* + * Make FBO to render into given texture. + */ +static GLuint +MakeFBO_RenderTexture(GLuint TexObj) +{ + GLuint fb; + GLint sizeFudge = 0; + + glGenFramebuffersEXT(1, &fb); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); + /* Render color to texture */ + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + TexTarget, TexObj, TextureLevel); + + if (Use_ARB_fbo) { + /* use a smaller depth buffer to see what happens */ + sizeFudge = 90; + } + + /* Setup depth and stencil buffers */ + { + GLboolean b; + b = AttachDepthAndStencilBuffers(fb, + TexWidth - sizeFudge, + TexHeight - sizeFudge, + UsePackedDepthStencil, + UsePackedDepthStencilBoth, + &DepthRB, &StencilRB); + if (!b) { + /* try !UsePackedDepthStencil */ + b = AttachDepthAndStencilBuffers(fb, + TexWidth - sizeFudge, + TexHeight - sizeFudge, + !UsePackedDepthStencil, + UsePackedDepthStencilBoth, + &DepthRB, &StencilRB); + } + if (!b) { + printf("Unable to create/attach depth and stencil renderbuffers " + " to FBO!\n"); + exit(1); + } + } + + /* queries */ + { + GLint bits, w, h; + + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, DepthRB); + glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, + GL_RENDERBUFFER_WIDTH_EXT, &w); + glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, + GL_RENDERBUFFER_HEIGHT_EXT, &h); + printf("Color/Texture size: %d x %d\n", TexWidth, TexHeight); + printf("Depth buffer size: %d x %d\n", w, h); + + glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, + GL_RENDERBUFFER_DEPTH_SIZE_EXT, &bits); + printf("Depth renderbuffer size = %d bits\n", bits); + + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, StencilRB); + glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, + GL_RENDERBUFFER_STENCIL_SIZE_EXT, &bits); + printf("Stencil renderbuffer size = %d bits\n", bits); + } + + /* bind the regular framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + + return fb; +} + + +static void +Init(void) +{ + if (!glutExtensionSupported("GL_EXT_framebuffer_object")) { + printf("GL_EXT_framebuffer_object not found!\n"); + exit(0); + } + + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + /* lighting */ + { + static const GLfloat mat[4] = { 1.0, 0.5, 0.5, 1.0 }; + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat); + } + + /* + * Make texture object/image (we'll render into this texture) + */ + { + glGenTextures(1, &TexObj); + glBindTexture(TexTarget, TexObj); + + /* make two image levels */ + glTexImage2D(TexTarget, 0, TexIntFormat, TexWidth, TexHeight, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + if (TexTarget == GL_TEXTURE_2D) { + glTexImage2D(TexTarget, 1, TexIntFormat, TexWidth/2, TexHeight/2, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + TexWidth = TexWidth >> TextureLevel; + TexHeight = TexHeight >> TextureLevel; + glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel); + } + + glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameteri(TexTarget, GL_TEXTURE_BASE_LEVEL, TextureLevel); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + } + + MyFB = MakeFBO_RenderTexture(TexObj); +} + + +static void +Usage(void) +{ + printf("Usage:\n"); + printf(" -ds Use combined depth/stencil renderbuffer\n"); + printf(" -arb Try GL_ARB_framebuffer_object's mismatched buffer sizes\n"); + printf(" -ds2 Try GL_ARB_framebuffer_object's GL_DEPTH_STENCIL_ATTACHMENT\n"); + printf("Keys:\n"); + printf(" a Toggle animation\n"); + printf(" s/s Step/rotate\n"); + printf(" c Toggle back-face culling\n"); + printf(" w Toggle wireframe mode (front-face only)\n"); + printf(" Esc Exit\n"); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(Width, Height); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + Win = glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Display); + if (Anim) + glutIdleFunc(Idle); + + ParseArgs(argc, argv); + Init(); + Usage(); + + glutMainLoop(); + return 0; +} diff --git a/progs/tests/Makefile b/progs/tests/Makefile index cd6c496961..7dfc65807a 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -43,7 +43,6 @@ SOURCES = \ floattex.c \ fbotest1.c \ fbotest2.c \ - fbotexture.c \ fillrate.c \ fog.c \ fogcoord.c \ diff --git a/progs/tests/fbotexture.c b/progs/tests/fbotexture.c deleted file mode 100644 index 50a4b00afc..0000000000 --- a/progs/tests/fbotexture.c +++ /dev/null @@ -1,621 +0,0 @@ -/* - * Test GL_EXT_framebuffer_object render-to-texture - * - * Draw a teapot into a texture image with stenciling. - * Then draw a textured quad using that texture. - * - * Brian Paul - * 18 Apr 2005 - */ - - -#include -#include -#include -#include -#include -#include -#include - -/* For debug */ -#define DEPTH 1 -#define STENCIL 1 -#define DRAW 1 - - -static int Win = 0; -static int Width = 400, Height = 400; - -#if 1 -static GLenum TexTarget = GL_TEXTURE_2D; -static int TexWidth = 512, TexHeight = 512; -static GLenum TexIntFormat = GL_RGB; /* either GL_RGB or GL_RGBA */ -#else -static GLenum TexTarget = GL_TEXTURE_RECTANGLE_ARB; -static int TexWidth = 200, TexHeight = 200; -static GLenum TexIntFormat = GL_RGB5; /* either GL_RGB or GL_RGBA */ -#endif -static GLuint TextureLevel = 0; /* which texture level to render to */ - -static GLuint MyFB; -static GLuint TexObj; -static GLuint DepthRB = 0, StencilRB = 0; -static GLboolean Anim = GL_FALSE; -static GLfloat Rot = 0.0; -static GLboolean UsePackedDepthStencil = GL_FALSE; -static GLboolean UsePackedDepthStencilBoth = GL_FALSE; -static GLboolean Use_ARB_fbo = GL_FALSE; -static GLboolean Cull = GL_FALSE; -static GLboolean Wireframe = GL_FALSE; - - -static void -CheckError(int line) -{ - GLenum err = glGetError(); - if (err) { - printf("GL Error 0x%x at line %d\n", (int) err, line); - } -} - - -static void -Idle(void) -{ - Rot = glutGet(GLUT_ELAPSED_TIME) * 0.1; - glutPostRedisplay(); -} - - -static void -RenderTexture(void) -{ - GLenum status; - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -15.0); - - /* draw to texture image */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); - - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - printf("Framebuffer incomplete!!!\n"); - } - - glViewport(0, 0, TexWidth, TexHeight); - - glClearColor(0.5, 0.5, 1.0, 0.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - CheckError(__LINE__); - -#if DEPTH - glEnable(GL_DEPTH_TEST); -#endif - -#if STENCIL - glEnable(GL_STENCIL_TEST); - glStencilFunc(GL_NEVER, 1, ~0); - glStencilOp(GL_REPLACE, GL_KEEP, GL_REPLACE); -#endif - - CheckError(__LINE__); - -#if DEPTH || STENCIL - /* draw diamond-shaped stencil pattern */ - glColor3f(0, 1, 0); - glBegin(GL_POLYGON); - glVertex2f(-0.2, 0.0); - glVertex2f( 0.0, -0.2); - glVertex2f( 0.2, 0.0); - glVertex2f( 0.0, 0.2); - glEnd(); -#endif - - /* draw teapot where stencil != 1 */ -#if STENCIL - glStencilFunc(GL_NOTEQUAL, 1, ~0); - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); -#endif - - CheckError(__LINE__); - - if (Wireframe) { - glPolygonMode(GL_FRONT, GL_LINE); - } - else { - glPolygonMode(GL_FRONT, GL_FILL); - } - - if (Cull) { - /* cull back */ - glCullFace(GL_BACK); - glEnable(GL_CULL_FACE); - } - else { - glDisable(GL_CULL_FACE); - } - -#if 0 - glBegin(GL_POLYGON); - glColor3f(1, 0, 0); - glVertex2f(-1, -1); - glColor3f(0, 1, 0); - glVertex2f(1, -1); - glColor3f(0, 0, 1); - glVertex2f(0, 1); - glEnd(); -#else - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glPushMatrix(); - glRotatef(0.5 * Rot, 1.0, 0.0, 0.0); - glFrontFace(GL_CW); /* Teapot patches backward */ - glutSolidTeapot(0.5); - glFrontFace(GL_CCW); - glPopMatrix(); - glDisable(GL_LIGHTING); - /* - PrintStencilHistogram(TexWidth, TexHeight); - */ -#endif - - glDisable(GL_DEPTH_TEST); - glDisable(GL_STENCIL_TEST); - glDisable(GL_CULL_FACE); - glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - -#if DRAW - /* Bind normal framebuffer */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); -#endif - - CheckError(__LINE__); -} - - - -static void -Display(void) -{ - float ar = (float) Width / (float) Height; - - RenderTexture(); - - /* draw textured quad in the window */ -#if DRAW - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum(-ar, ar, -1.0, 1.0, 5.0, 25.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef(0.0, 0.0, -7.0); - - glViewport(0, 0, Width, Height); - - glClearColor(0.25, 0.25, 0.25, 0); - glClear(GL_COLOR_BUFFER_BIT); - - glPushMatrix(); - glRotatef(Rot, 0, 1, 0); - glEnable(TexTarget); - glBindTexture(TexTarget, TexObj); - glBegin(GL_POLYGON); - glColor3f(0.25, 0.25, 0.25); - if (TexTarget == GL_TEXTURE_2D) { - glTexCoord2f(0, 0); - glVertex2f(-1, -1); - glTexCoord2f(1, 0); - glVertex2f(1, -1); - glColor3f(1.0, 1.0, 1.0); - glTexCoord2f(1, 1); - glVertex2f(1, 1); - glTexCoord2f(0, 1); - glVertex2f(-1, 1); - } - else { - assert(TexTarget == GL_TEXTURE_RECTANGLE_ARB); - glTexCoord2f(0, 0); - glVertex2f(-1, -1); - glTexCoord2f(TexWidth, 0); - glVertex2f(1, -1); - glColor3f(1.0, 1.0, 1.0); - glTexCoord2f(TexWidth, TexHeight); - glVertex2f(1, 1); - glTexCoord2f(0, TexHeight); - glVertex2f(-1, 1); - } - glEnd(); - glPopMatrix(); - glDisable(TexTarget); -#endif - - glutSwapBuffers(); - CheckError(__LINE__); -} - - -static void -Reshape(int width, int height) -{ - glViewport(0, 0, width, height); - Width = width; - Height = height; -} - - -static void -CleanUp(void) -{ -#if DEPTH - glDeleteRenderbuffersEXT(1, &DepthRB); -#endif -#if STENCIL - glDeleteRenderbuffersEXT(1, &StencilRB); -#endif - glDeleteFramebuffersEXT(1, &MyFB); - - glDeleteTextures(1, &TexObj); - - glutDestroyWindow(Win); - - exit(0); -} - - -static void -Key(unsigned char key, int x, int y) -{ - (void) x; - (void) y; - switch (key) { - case 'a': - Anim = !Anim; - if (Anim) - glutIdleFunc(Idle); - else - glutIdleFunc(NULL); - break; - case 'c': - Cull = !Cull; - break; - case 'w': - Wireframe = !Wireframe; - break; - case 's': - Rot += 2.0; - break; - case 'S': - Rot -= 2.0; - break; - case 27: - CleanUp(); - break; - } - glutPostRedisplay(); -} - - -/** - * Attach depth and stencil renderbuffer(s) to the given framebuffer object. - * \param tryDepthStencil if true, try to use a combined depth+stencil buffer - * \param bindDepthStencil if true, and tryDepthStencil is true, bind with - * the GL_DEPTH_STENCIL_ATTACHMENT target. - * \return GL_TRUE for success, GL_FALSE for failure - */ -static GLboolean -AttachDepthAndStencilBuffers(GLuint fbo, - GLsizei width, GLsizei height, - GLboolean tryDepthStencil, - GLboolean bindDepthStencil, - GLuint *depthRbOut, GLuint *stencilRbOut) -{ - GLenum status; - - *depthRbOut = *stencilRbOut = 0; - - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); - - if (tryDepthStencil) { - GLuint rb; - - glGenRenderbuffersEXT(1, &rb); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, - GL_DEPTH24_STENCIL8_EXT, - width, height); - if (glGetError()) - return GL_FALSE; - - if (bindDepthStencil) { - /* attach to both depth and stencil at once */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_DEPTH_STENCIL_ATTACHMENT, - GL_RENDERBUFFER_EXT, rb); - if (glGetError()) - return GL_FALSE; - } - else { - /* attach to depth attachment point */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, rb); - if (glGetError()) - return GL_FALSE; - - /* and attach to stencil attachment point */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_STENCIL_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, rb); - if (glGetError()) - return GL_FALSE; - } - - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) - return GL_FALSE; - - *depthRbOut = *stencilRbOut = rb; - return GL_TRUE; - } - - /* just depth renderbuffer */ - { - GLuint rb; - - glGenRenderbuffersEXT(1, &rb); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, - GL_DEPTH_COMPONENT, - width, height); - if (glGetError()) - return GL_FALSE; - - /* attach to depth attachment point */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_DEPTH_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, rb); - if (glGetError()) - return GL_FALSE; - - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) - return GL_FALSE; - - *depthRbOut = rb; - } - - /* just stencil renderbuffer */ - { - GLuint rb; - - glGenRenderbuffersEXT(1, &rb); - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rb); - glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, - GL_STENCIL_INDEX, - width, height); - if (glGetError()) - return GL_FALSE; - - /* attach to depth attachment point */ - glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, - GL_STENCIL_ATTACHMENT_EXT, - GL_RENDERBUFFER_EXT, rb); - if (glGetError()) - return GL_FALSE; - - status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { - glDeleteRenderbuffersEXT(1, depthRbOut); - *depthRbOut = 0; - glDeleteRenderbuffersEXT(1, &rb); - return GL_FALSE; - } - - *stencilRbOut = rb; - } - - return GL_TRUE; -} - - -static void -ParseArgs(int argc, char *argv[]) -{ - GLint i; - for (i = 1; i < argc; i++) { - if (strcmp(argv[i], "-ds") == 0) { - if (!glutExtensionSupported("GL_EXT_packed_depth_stencil")) { - printf("GL_EXT_packed_depth_stencil not found!\n"); - exit(0); - } - UsePackedDepthStencil = GL_TRUE; - printf("Using GL_EXT_packed_depth_stencil\n"); - } - else if (strcmp(argv[i], "-ds2") == 0) { - if (!glutExtensionSupported("GL_EXT_packed_depth_stencil")) { - printf("GL_EXT_packed_depth_stencil not found!\n"); - exit(0); - } - if (!glutExtensionSupported("GL_ARB_framebuffer_object")) { - printf("GL_ARB_framebuffer_object not found!\n"); - exit(0); - } - UsePackedDepthStencilBoth = GL_TRUE; - printf("Using GL_EXT_packed_depth_stencil and GL_DEPTH_STENCIL attachment point\n"); - } - else if (strcmp(argv[i], "-arb") == 0) { - if (!glutExtensionSupported("GL_ARB_framebuffer_object")) { - printf("Sorry, GL_ARB_framebuffer object not supported!\n"); - } - else { - Use_ARB_fbo = GL_TRUE; - } - } - else { - printf("Unknown option: %s\n", argv[i]); - } - } -} - - -/* - * Make FBO to render into given texture. - */ -static GLuint -MakeFBO_RenderTexture(GLuint TexObj) -{ - GLuint fb; - GLint sizeFudge = 0; - - glGenFramebuffersEXT(1, &fb); - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb); - /* Render color to texture */ - glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, - TexTarget, TexObj, TextureLevel); - - if (Use_ARB_fbo) { - /* use a smaller depth buffer to see what happens */ - sizeFudge = 90; - } - - /* Setup depth and stencil buffers */ - { - GLboolean b; - b = AttachDepthAndStencilBuffers(fb, - TexWidth - sizeFudge, - TexHeight - sizeFudge, - UsePackedDepthStencil, - UsePackedDepthStencilBoth, - &DepthRB, &StencilRB); - if (!b) { - /* try !UsePackedDepthStencil */ - b = AttachDepthAndStencilBuffers(fb, - TexWidth - sizeFudge, - TexHeight - sizeFudge, - !UsePackedDepthStencil, - UsePackedDepthStencilBoth, - &DepthRB, &StencilRB); - } - if (!b) { - printf("Unable to create/attach depth and stencil renderbuffers " - " to FBO!\n"); - exit(1); - } - } - - /* queries */ - { - GLint bits, w, h; - - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, DepthRB); - glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, - GL_RENDERBUFFER_WIDTH_EXT, &w); - glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, - GL_RENDERBUFFER_HEIGHT_EXT, &h); - printf("Color/Texture size: %d x %d\n", TexWidth, TexHeight); - printf("Depth buffer size: %d x %d\n", w, h); - - glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, - GL_RENDERBUFFER_DEPTH_SIZE_EXT, &bits); - printf("Depth renderbuffer size = %d bits\n", bits); - - glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, StencilRB); - glGetRenderbufferParameterivEXT(GL_RENDERBUFFER_EXT, - GL_RENDERBUFFER_STENCIL_SIZE_EXT, &bits); - printf("Stencil renderbuffer size = %d bits\n", bits); - } - - /* bind the regular framebuffer */ - glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); - - return fb; -} - - -static void -Init(void) -{ - if (!glutExtensionSupported("GL_EXT_framebuffer_object")) { - printf("GL_EXT_framebuffer_object not found!\n"); - exit(0); - } - - printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); - - /* lighting */ - { - static const GLfloat mat[4] = { 1.0, 0.5, 0.5, 1.0 }; - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat); - } - - /* - * Make texture object/image (we'll render into this texture) - */ - { - glGenTextures(1, &TexObj); - glBindTexture(TexTarget, TexObj); - - /* make two image levels */ - glTexImage2D(TexTarget, 0, TexIntFormat, TexWidth, TexHeight, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); - if (TexTarget == GL_TEXTURE_2D) { - glTexImage2D(TexTarget, 1, TexIntFormat, TexWidth/2, TexHeight/2, 0, - GL_RGBA, GL_UNSIGNED_BYTE, NULL); - TexWidth = TexWidth >> TextureLevel; - TexHeight = TexHeight >> TextureLevel; - glTexParameteri(TexTarget, GL_TEXTURE_MAX_LEVEL, TextureLevel); - } - - glTexParameteri(TexTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(TexTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glTexParameteri(TexTarget, GL_TEXTURE_BASE_LEVEL, TextureLevel); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - } - - MyFB = MakeFBO_RenderTexture(TexObj); -} - - -static void -Usage(void) -{ - printf("Usage:\n"); - printf(" -ds Use combined depth/stencil renderbuffer\n"); - printf(" -arb Try GL_ARB_framebuffer_object's mismatched buffer sizes\n"); - printf(" -ds2 Try GL_ARB_framebuffer_object's GL_DEPTH_STENCIL_ATTACHMENT\n"); - printf("Keys:\n"); - printf(" a Toggle animation\n"); - printf(" s/s Step/rotate\n"); - printf(" c Toggle back-face culling\n"); - printf(" w Toggle wireframe mode (front-face only)\n"); - printf(" Esc Exit\n"); -} - - -int -main(int argc, char *argv[]) -{ - glutInit(&argc, argv); - glutInitWindowPosition(0, 0); - glutInitWindowSize(Width, Height); - glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); - Win = glutCreateWindow(argv[0]); - glewInit(); - glutReshapeFunc(Reshape); - glutKeyboardFunc(Key); - glutDisplayFunc(Display); - if (Anim) - glutIdleFunc(Idle); - - ParseArgs(argc, argv); - Init(); - Usage(); - - glutMainLoop(); - return 0; -} -- cgit v1.2.3 From 49c3e7172db1ee2afef6bcd19c3cd55dbe60bd33 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 13:05:51 -0600 Subject: demos: move tests/projtex.c to demos/ And fix compiler warnings. --- progs/demos/Makefile | 1 + progs/demos/projtex.c | 1028 ++++++++++++++++++++++++++++++++++++++++++++++++ progs/tests/Makefile | 1 - progs/tests/projtex.c | 1030 ------------------------------------------------- 4 files changed, 1029 insertions(+), 1031 deletions(-) create mode 100644 progs/demos/projtex.c delete mode 100644 progs/tests/projtex.c (limited to 'progs') diff --git a/progs/demos/Makefile b/progs/demos/Makefile index a1c99c6c54..2fe407972d 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -41,6 +41,7 @@ PROGS = \ multiarb \ paltex \ pointblast \ + projtex \ rain \ ray \ readpix \ diff --git a/progs/demos/projtex.c b/progs/demos/projtex.c new file mode 100644 index 0000000000..99154d7bdc --- /dev/null +++ b/progs/demos/projtex.c @@ -0,0 +1,1028 @@ + +/* projtex.c - by David Yu and David Blythe, SGI */ + +/** + ** Demonstrates simple projective texture mapping. + ** + ** Button1 changes view, Button2 moves texture. + ** + ** (See: Segal, Korobkin, van Widenfelt, Foran, and Haeberli + ** "Fast Shadows and Lighting Effects Using Texture Mapping", SIGGRAPH '92) + ** + ** 1994,1995 -- David G Yu + ** + ** cc -o projtex projtex.c texture.c -lglut -lGLU -lGL -lX11 -lm + **/ + +#include +#include +#include +#include +#include +#include +#include "readtex.h" + + +/* Some files do not define M_PI... */ +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +#define MAX_TEX 4 +int NumTextures = 1; + +int winWidth, winHeight; + +GLboolean redrawContinuously = GL_FALSE; + +float angle, axis[3]; +enum MoveModes { + MoveNone, MoveView, MoveObject, MoveTexture +}; +enum MoveModes mode = MoveNone; + +GLfloat objectXform[4][4]; +GLfloat textureXform[MAX_TEX][4][4]; + +void (*drawObject) (void); +void (*loadTexture) (void); +GLboolean textureEnabled = GL_TRUE; +GLboolean showProjection = GL_TRUE; +GLboolean linearFilter = GL_TRUE; + +char *texFilename[MAX_TEX] = { + "../images/girl.rgb", + "../images/tile.rgb", + "../images/bw.rgb", + "../images/reflect.rgb" +}; + + +GLfloat zoomFactor = 1.0; + +/*****************************************************************/ + + +static void +ActiveTexture(int i) +{ + glActiveTextureARB(i); +} + + +/* matrix = identity */ +static void +matrixIdentity(GLfloat matrix[16]) +{ + matrix[0] = 1.0; + matrix[1] = 0.0; + matrix[2] = 0.0; + matrix[3] = 0.0; + matrix[4] = 0.0; + matrix[5] = 1.0; + matrix[6] = 0.0; + matrix[7] = 0.0; + matrix[8] = 0.0; + matrix[9] = 0.0; + matrix[10] = 1.0; + matrix[11] = 0.0; + matrix[12] = 0.0; + matrix[13] = 0.0; + matrix[14] = 0.0; + matrix[15] = 1.0; +} + +/* matrix2 = transpose(matrix1) */ +static void +matrixTranspose(GLfloat matrix2[16], GLfloat matrix1[16]) +{ + matrix2[0] = matrix1[0]; + matrix2[1] = matrix1[4]; + matrix2[2] = matrix1[8]; + matrix2[3] = matrix1[12]; + + matrix2[4] = matrix1[1]; + matrix2[5] = matrix1[5]; + matrix2[6] = matrix1[9]; + matrix2[7] = matrix1[13]; + + matrix2[8] = matrix1[2]; + matrix2[9] = matrix1[6]; + matrix2[10] = matrix1[10]; + matrix2[11] = matrix1[14]; + + matrix2[12] = matrix1[3]; + matrix2[13] = matrix1[7]; + matrix2[14] = matrix1[14]; + matrix2[15] = matrix1[15]; +} + +/*****************************************************************/ + +/* load SGI .rgb image (pad with a border of the specified width and color) */ +#if 0 +static void +imgLoad(char *filenameIn, int borderIn, GLfloat borderColorIn[4], + int *wOut, int *hOut, GLubyte ** imgOut) +{ + int border = borderIn; + int width, height; + int w, h; + GLubyte *image, *img, *p; + int i, j, components; + + image = (GLubyte *) read_texture(filenameIn, &width, &height, &components); + w = width + 2 * border; + h = height + 2 * border; + img = (GLubyte *) calloc(w * h, 4 * sizeof(unsigned char)); + + p = img; + for (j = -border; j < height + border; ++j) { + for (i = -border; i < width + border; ++i) { + if (0 <= j && j <= height - 1 && 0 <= i && i <= width - 1) { + p[0] = image[4 * (j * width + i) + 0]; + p[1] = image[4 * (j * width + i) + 1]; + p[2] = image[4 * (j * width + i) + 2]; + p[3] = 0xff; + } else { + p[0] = borderColorIn[0] * 0xff; + p[1] = borderColorIn[1] * 0xff; + p[2] = borderColorIn[2] * 0xff; + p[3] = borderColorIn[3] * 0xff; + } + p += 4; + } + } + free(image); + *wOut = w; + *hOut = h; + *imgOut = img; +} +#endif + + +/*****************************************************************/ + +/* Load the image file specified on the command line as the current texture */ +static void +loadImageTextures(void) +{ + GLfloat borderColor[4] = + {1.0, 1.0, 1.0, 1.0}; + int tex; + + for (tex = 0; tex < NumTextures; tex++) { + GLubyte *image, *texData3, *texData4; + GLint imgWidth, imgHeight; + GLenum imgFormat; + int i, j; + + printf("loading %s\n", texFilename[tex]); + image = LoadRGBImage(texFilename[tex], &imgWidth, &imgHeight, &imgFormat); + if (!image) { + printf("can't find %s\n", texFilename[tex]); + exit(1); + } + assert(imgFormat == GL_RGB); + + /* scale to 256x256 */ + texData3 = malloc(256 * 256 * 4); + texData4 = malloc(256 * 256 * 4); + assert(texData3); + assert(texData4); + gluScaleImage(imgFormat, imgWidth, imgHeight, GL_UNSIGNED_BYTE, image, + 256, 256, GL_UNSIGNED_BYTE, texData3); + + /* convert to rgba */ + for (i = 0; i < 256 * 256; i++) { + texData4[i*4+0] = texData3[i*3+0]; + texData4[i*4+1] = texData3[i*3+1]; + texData4[i*4+2] = texData3[i*3+2]; + texData4[i*4+3] = 128; + } + + /* put transparent border around image */ + for (i = 0; i < 256; i++) { + texData4[i*4+0] = 255; + texData4[i*4+1] = 255; + texData4[i*4+2] = 255; + texData4[i*4+3] = 0; + } + j = 256 * 255 * 4; + for (i = 0; i < 256; i++) { + texData4[j + i*4+0] = 255; + texData4[j + i*4+1] = 255; + texData4[j + i*4+2] = 255; + texData4[j + i*4+3] = 0; + } + for (i = 0; i < 256; i++) { + j = i * 256 * 4; + texData4[j+0] = 255; + texData4[j+1] = 255; + texData4[j+2] = 255; + texData4[j+3] = 0; + } + for (i = 0; i < 256; i++) { + j = i * 256 * 4 + 255 * 4; + texData4[j+0] = 255; + texData4[j+1] = 255; + texData4[j+2] = 255; + texData4[j+3] = 0; + } + + ActiveTexture(GL_TEXTURE0_ARB + tex); + glBindTexture(GL_TEXTURE_2D, tex + 1); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, + GL_RGBA, GL_UNSIGNED_BYTE, texData4); + + if (linearFilter) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); + } +} + +/* Create a simple spotlight pattern and make it the current texture */ +static void +loadSpotlightTexture(void) +{ + static int texWidth = 64, texHeight = 64; + static GLubyte *texData; + GLfloat borderColor[4] = + {0.1, 0.1, 0.1, 1.0}; + + if (!texData) { + GLubyte *p; + int i, j; + + texData = (GLubyte *) malloc(texWidth * texHeight * 4 * sizeof(GLubyte)); + + p = texData; + for (j = 0; j < texHeight; ++j) { + float dy = (texHeight * 0.5 - j + 0.5) / (texHeight * 0.5); + + for (i = 0; i < texWidth; ++i) { + float dx = (texWidth * 0.5 - i + 0.5) / (texWidth * 0.5); + float r = cos(M_PI / 2.0 * sqrt(dx * dx + dy * dy)); + float c; + + r = (r < 0) ? 0 : r * r; + c = 0xff * (r + borderColor[0]); + p[0] = (c <= 0xff) ? c : 0xff; + c = 0xff * (r + borderColor[1]); + p[1] = (c <= 0xff) ? c : 0xff; + c = 0xff * (r + borderColor[2]); + p[2] = (c <= 0xff) ? c : 0xff; + c = 0xff * (r + borderColor[3]); + p[3] = (c <= 0xff) ? c : 0xff; + p += 4; + } + } + } + if (linearFilter) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); + gluBuild2DMipmaps(GL_TEXTURE_2D, 4, texWidth, texHeight, + GL_RGBA, GL_UNSIGNED_BYTE, texData); +} + +/*****************************************************************/ + +static void +checkErrors(void) +{ + GLenum error; + while ((error = glGetError()) != GL_NO_ERROR) { + fprintf(stderr, "Error: %s\n", (char *) gluErrorString(error)); + } +} + +static void +drawCube(void) +{ + glBegin(GL_QUADS); + + glNormal3f(-1.0, 0.0, 0.0); + glColor3f(0.80, 0.50, 0.50); + glVertex3f(-0.5, -0.5, -0.5); + glVertex3f(-0.5, -0.5, 0.5); + glVertex3f(-0.5, 0.5, 0.5); + glVertex3f(-0.5, 0.5, -0.5); + + glNormal3f(1.0, 0.0, 0.0); + glColor3f(0.50, 0.80, 0.50); + glVertex3f(0.5, 0.5, 0.5); + glVertex3f(0.5, -0.5, 0.5); + glVertex3f(0.5, -0.5, -0.5); + glVertex3f(0.5, 0.5, -0.5); + + glNormal3f(0.0, -1.0, 0.0); + glColor3f(0.50, 0.50, 0.80); + glVertex3f(-0.5, -0.5, -0.5); + glVertex3f(0.5, -0.5, -0.5); + glVertex3f(0.5, -0.5, 0.5); + glVertex3f(-0.5, -0.5, 0.5); + + glNormal3f(0.0, 1.0, 0.0); + glColor3f(0.50, 0.80, 0.80); + glVertex3f(0.5, 0.5, 0.5); + glVertex3f(0.5, 0.5, -0.5); + glVertex3f(-0.5, 0.5, -0.5); + glVertex3f(-0.5, 0.5, 0.5); + + glNormal3f(0.0, 0.0, -1.0); + glColor3f(0.80, 0.50, 0.80); + glVertex3f(-0.5, -0.5, -0.5); + glVertex3f(-0.5, 0.5, -0.5); + glVertex3f(0.5, 0.5, -0.5); + glVertex3f(0.5, -0.5, -0.5); + + glNormal3f(0.0, 0.0, 1.0); + glColor3f(1.00, 0.80, 0.50); + glVertex3f(0.5, 0.5, 0.5); + glVertex3f(-0.5, 0.5, 0.5); + glVertex3f(-0.5, -0.5, 0.5); + glVertex3f(0.5, -0.5, 0.5); + glEnd(); +} + +static void +drawDodecahedron(void) +{ +#define A (0.5 * 1.61803) /* (sqrt(5) + 1) / 2 */ +#define B (0.5 * 0.61803) /* (sqrt(5) - 1) / 2 */ +#define C (0.5 * 1.0) + GLfloat vertexes[20][3] = + { + {-A, 0.0, B}, + {-A, 0.0, -B}, + {A, 0.0, -B}, + {A, 0.0, B}, + {B, -A, 0.0}, + {-B, -A, 0.0}, + {-B, A, 0.0}, + {B, A, 0.0}, + {0.0, B, -A}, + {0.0, -B, -A}, + {0.0, -B, A}, + {0.0, B, A}, + {-C, -C, C}, + {-C, -C, -C}, + {C, -C, -C}, + {C, -C, C}, + {-C, C, C}, + {-C, C, -C}, + {C, C, -C}, + {C, C, C}, + }; +#undef A +#undef B +#undef C + GLint polygons[12][5] = + { + {0, 12, 10, 11, 16}, + {1, 17, 8, 9, 13}, + {2, 14, 9, 8, 18}, + {3, 19, 11, 10, 15}, + {4, 14, 2, 3, 15}, + {5, 12, 0, 1, 13}, + {6, 17, 1, 0, 16}, + {7, 19, 3, 2, 18}, + {8, 17, 6, 7, 18}, + {9, 14, 4, 5, 13}, + {10, 12, 5, 4, 15}, + {11, 19, 7, 6, 16}, + }; + int i; + + glColor3f(0.75, 0.75, 0.75); + for (i = 0; i < 12; ++i) { + GLfloat *p0, *p1, *p2, d; + GLfloat u[3], v[3], n[3]; + + p0 = &vertexes[polygons[i][0]][0]; + p1 = &vertexes[polygons[i][1]][0]; + p2 = &vertexes[polygons[i][2]][0]; + + u[0] = p2[0] - p1[0]; + u[1] = p2[1] - p1[1]; + u[2] = p2[2] - p1[2]; + + v[0] = p0[0] - p1[0]; + v[1] = p0[1] - p1[1]; + v[2] = p0[2] - p1[2]; + + n[0] = u[1] * v[2] - u[2] * v[1]; + n[1] = u[2] * v[0] - u[0] * v[2]; + n[2] = u[0] * v[1] - u[1] * v[0]; + + d = 1.0 / sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); + n[0] *= d; + n[1] *= d; + n[2] *= d; + + glBegin(GL_POLYGON); + glNormal3fv(n); + glVertex3fv(p0); + glVertex3fv(p1); + glVertex3fv(p2); + glVertex3fv(vertexes[polygons[i][3]]); + glVertex3fv(vertexes[polygons[i][4]]); + glEnd(); + } +} + +static void +drawSphere(void) +{ + int numMajor = 24; + int numMinor = 32; + float radius = 0.8; + double majorStep = (M_PI / numMajor); + double minorStep = (2.0 * M_PI / numMinor); + int i, j; + + glColor3f(0.50, 0.50, 0.50); + for (i = 0; i < numMajor; ++i) { + double a = i * majorStep; + double b = a + majorStep; + double r0 = radius * sin(a); + double r1 = radius * sin(b); + GLfloat z0 = radius * cos(a); + GLfloat z1 = radius * cos(b); + + glBegin(GL_TRIANGLE_STRIP); + for (j = 0; j <= numMinor; ++j) { + double c = j * minorStep; + GLfloat x = cos(c); + GLfloat y = sin(c); + + glNormal3f((x * r0) / radius, (y * r0) / radius, z0 / radius); + glTexCoord2f(j / (GLfloat) numMinor, i / (GLfloat) numMajor); + glVertex3f(x * r0, y * r0, z0); + + glNormal3f((x * r1) / radius, (y * r1) / radius, z1 / radius); + glTexCoord2f(j / (GLfloat) numMinor, (i + 1) / (GLfloat) numMajor); + glVertex3f(x * r1, y * r1, z1); + } + glEnd(); + } +} + +/*****************************************************************/ + +float xmin = -0.035, xmax = 0.035; +float ymin = -0.035, ymax = 0.035; +float nnear = 0.1; +float ffar = 1.9; +float distance = -1.0; + +static void +loadTextureProjection(int texUnit, GLfloat m[16]) +{ + GLfloat mInverse[4][4]; + + /* Should use true inverse, but since m consists only of rotations, we can + just use the transpose. */ + matrixTranspose((GLfloat *) mInverse, m); + + ActiveTexture(GL_TEXTURE0_ARB + texUnit); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glTranslatef(0.5, 0.5, 0.0); + glScalef(0.5, 0.5, 1.0); + glFrustum(xmin, xmax, ymin, ymax, nnear, ffar); + glTranslatef(0.0, 0.0, distance); + glMultMatrixf((GLfloat *) mInverse); + glMatrixMode(GL_MODELVIEW); +} + +static void +drawTextureProjection(void) +{ + float t = ffar / nnear; + GLfloat n[4][3]; + GLfloat f[4][3]; + + n[0][0] = xmin; + n[0][1] = ymin; + n[0][2] = -(nnear + distance); + + n[1][0] = xmax; + n[1][1] = ymin; + n[1][2] = -(nnear + distance); + + n[2][0] = xmax; + n[2][1] = ymax; + n[2][2] = -(nnear + distance); + + n[3][0] = xmin; + n[3][1] = ymax; + n[3][2] = -(nnear + distance); + + f[0][0] = xmin * t; + f[0][1] = ymin * t; + f[0][2] = -(ffar + distance); + + f[1][0] = xmax * t; + f[1][1] = ymin * t; + f[1][2] = -(ffar + distance); + + f[2][0] = xmax * t; + f[2][1] = ymax * t; + f[2][2] = -(ffar + distance); + + f[3][0] = xmin * t; + f[3][1] = ymax * t; + f[3][2] = -(ffar + distance); + + glColor3f(1.0, 1.0, 0.0); + glBegin(GL_LINE_LOOP); + glVertex3fv(n[0]); + glVertex3fv(n[1]); + glVertex3fv(n[2]); + glVertex3fv(n[3]); + glVertex3fv(f[3]); + glVertex3fv(f[2]); + glVertex3fv(f[1]); + glVertex3fv(f[0]); + glVertex3fv(n[0]); + glVertex3fv(n[1]); + glVertex3fv(f[1]); + glVertex3fv(f[0]); + glVertex3fv(f[3]); + glVertex3fv(f[2]); + glVertex3fv(n[2]); + glVertex3fv(n[3]); + glEnd(); +} + +/*****************************************************************/ + +static void +initialize(void) +{ + GLfloat light0Pos[4] = + {0.3, 0.3, 0.0, 1.0}; + GLfloat matAmb[4] = + {0.01, 0.01, 0.01, 1.00}; + GLfloat matDiff[4] = + {0.65, 0.65, 0.65, 1.00}; + GLfloat matSpec[4] = + {0.30, 0.30, 0.30, 1.00}; + GLfloat matShine = 10.0; + GLfloat eyePlaneS[] = + {1.0, 0.0, 0.0, 0.0}; + GLfloat eyePlaneT[] = + {0.0, 1.0, 0.0, 0.0}; + GLfloat eyePlaneR[] = + {0.0, 0.0, 1.0, 0.0}; + GLfloat eyePlaneQ[] = + {0.0, 0.0, 0.0, 1.0}; + int i; + + /* Setup Misc. */ + glClearColor(0.41, 0.41, 0.31, 0.0); + + glEnable(GL_DEPTH_TEST); + + /* glLineWidth(2.0);*/ + + glCullFace(GL_FRONT); + glEnable(GL_CULL_FACE); + + glMatrixMode(GL_PROJECTION); + glFrustum(-0.5, 0.5, -0.5, 0.5, 1, 3); + glMatrixMode(GL_MODELVIEW); + glTranslatef(0, 0, -2); + + matrixIdentity((GLfloat *) objectXform); + for (i = 0; i < NumTextures; i++) { + matrixIdentity((GLfloat *) textureXform[i]); + } + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, 1, 0, 1, -1, 1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glRasterPos2i(0, 0); + + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + + /* Setup Lighting */ + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmb); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiff); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpec); + glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, matShine); + + glEnable(GL_COLOR_MATERIAL); + + glLightfv(GL_LIGHT0, GL_POSITION, light0Pos); + glEnable(GL_LIGHT0); + + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + glEnable(GL_LIGHTING); + + /* Setup Texture */ + + (*loadTexture) (); + + + for (i = 0; i < NumTextures; i++) { + ActiveTexture(GL_TEXTURE0_ARB + i); + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); + + glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGenfv(GL_S, GL_EYE_PLANE, eyePlaneS); + + glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGenfv(GL_T, GL_EYE_PLANE, eyePlaneT); + + glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGenfv(GL_R, GL_EYE_PLANE, eyePlaneR); + + glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); + glTexGenfv(GL_Q, GL_EYE_PLANE, eyePlaneQ); + } +} + +static void +display(void) +{ + int i; + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + if (textureEnabled) { + if (mode == MoveTexture || mode == MoveView) { + /* Have OpenGL compute the new transformation (simple but slow). */ + for (i = 0; i < NumTextures; i++) { + glPushMatrix(); + glLoadIdentity(); +#if 0 + if (i & 1) + glRotatef(angle, axis[0], axis[1], axis[2]); + else +#endif + glRotatef(angle*(i+1), axis[0], axis[1], axis[2]); + + glMultMatrixf((GLfloat *) textureXform[i]); + glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) textureXform[i]); + glPopMatrix(); + } + } + for (i = 0; i < NumTextures; i++) { + loadTextureProjection(i, (GLfloat *) textureXform[i]); + } + + if (showProjection) { + for (i = 0; i < NumTextures; i++) { + ActiveTexture(GL_TEXTURE0_ARB + i); + glPushMatrix(); + glMultMatrixf((GLfloat *) textureXform[i]); + glDisable(GL_LIGHTING); + drawTextureProjection(); + glEnable(GL_LIGHTING); + glPopMatrix(); + } + } + for (i = 0; i < NumTextures; i++) { + ActiveTexture(GL_TEXTURE0_ARB + i); + glEnable(GL_TEXTURE_2D); + glEnable(GL_TEXTURE_GEN_S); + glEnable(GL_TEXTURE_GEN_T); + glEnable(GL_TEXTURE_GEN_R); + glEnable(GL_TEXTURE_GEN_Q); + } + } + if (mode == MoveObject || mode == MoveView) { + /* Have OpenGL compute the new transformation (simple but slow). */ + glPushMatrix(); + glLoadIdentity(); + glRotatef(angle, axis[0], axis[1], axis[2]); + glMultMatrixf((GLfloat *) objectXform); + glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) objectXform); + glPopMatrix(); + } + glPushMatrix(); + glMultMatrixf((GLfloat *) objectXform); + (*drawObject) (); + glPopMatrix(); + + for (i = 0; i < NumTextures; i++) { + ActiveTexture(GL_TEXTURE0_ARB + i); + glDisable(GL_TEXTURE_2D); + glDisable(GL_TEXTURE_GEN_S); + glDisable(GL_TEXTURE_GEN_T); + glDisable(GL_TEXTURE_GEN_R); + glDisable(GL_TEXTURE_GEN_Q); + } + + if (zoomFactor > 1.0) { + glDisable(GL_DEPTH_TEST); + glCopyPixels(0, 0, winWidth / zoomFactor, winHeight / zoomFactor, GL_COLOR); + glEnable(GL_DEPTH_TEST); + } + glFlush(); + glutSwapBuffers(); + checkErrors(); +} + +/*****************************************************************/ + +/* simple trackball-like motion control */ +static float lastPos[3]; +static int lastTime; + +static void +ptov(int x, int y, int width, int height, float v[3]) +{ + float d, a; + + /* project x,y onto a hemi-sphere centered within width, height */ + v[0] = (2.0 * x - width) / width; + v[1] = (height - 2.0 * y) / height; + d = sqrt(v[0] * v[0] + v[1] * v[1]); + v[2] = cos((M_PI / 2.0) * ((d < 1.0) ? d : 1.0)); + a = 1.0 / sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + v[0] *= a; + v[1] *= a; + v[2] *= a; +} + +static void +startMotion(int x, int y, int but, int time) +{ + if (but == GLUT_LEFT_BUTTON) { + mode = MoveView; + } else if (but == GLUT_MIDDLE_BUTTON) { + mode = MoveTexture; + } else { + return; + } + + lastTime = time; + ptov(x, y, winWidth, winHeight, lastPos); +} + +static void +animate(void) +{ + glutPostRedisplay(); +} + +static void +vis(int visible) +{ + if (visible == GLUT_VISIBLE) { + if (redrawContinuously) + glutIdleFunc(animate); + } else { + if (redrawContinuously) + glutIdleFunc(NULL); + } +} + +static void +stopMotion(int but, int time) +{ + if ((but == GLUT_LEFT_BUTTON && mode == MoveView) || + (but == GLUT_MIDDLE_BUTTON && mode == MoveTexture)) { + } else { + return; + } + + if (time == lastTime) { + /* redrawContinuously = GL_TRUE;*/ + glutIdleFunc(animate); + } else { + angle = 0.0; + redrawContinuously = GL_FALSE; + glutIdleFunc(0); + } + if (!redrawContinuously) { + mode = MoveNone; + } +} + +static void +trackMotion(int x, int y) +{ + float curPos[3], dx, dy, dz; + + ptov(x, y, winWidth, winHeight, curPos); + + dx = curPos[0] - lastPos[0]; + dy = curPos[1] - lastPos[1]; + dz = curPos[2] - lastPos[2]; + angle = 90.0 * sqrt(dx * dx + dy * dy + dz * dz); + + axis[0] = lastPos[1] * curPos[2] - lastPos[2] * curPos[1]; + axis[1] = lastPos[2] * curPos[0] - lastPos[0] * curPos[2]; + axis[2] = lastPos[0] * curPos[1] - lastPos[1] * curPos[0]; + + lastTime = glutGet(GLUT_ELAPSED_TIME); + lastPos[0] = curPos[0]; + lastPos[1] = curPos[1]; + lastPos[2] = curPos[2]; + glutPostRedisplay(); +} + +/*****************************************************************/ + +static void +object(void) +{ + static int object; + + object++; + object %= 3; + switch (object) { + case 0: + drawObject = drawCube; + break; + case 1: + drawObject = drawDodecahedron; + break; + case 2: + drawObject = drawSphere; + break; + default: + break; + } +} + +static void +nop(void) +{ +} + +static void +texture(void) +{ + static int texture = 0; + + texture++; + texture %= 3; + if (texture == 1 && texFilename == NULL) { + /* Skip file texture if not loaded. */ + texture++; + } + switch (texture) { + case 0: + loadTexture = nop; + textureEnabled = GL_FALSE; + break; + case 1: + loadTexture = loadImageTextures; + (*loadTexture) (); + textureEnabled = GL_TRUE; + break; + case 2: + loadTexture = loadSpotlightTexture; + (*loadTexture) (); + textureEnabled = GL_TRUE; + break; + default: + break; + } +} + +static void +help(void) +{ + printf("'h' - help\n"); + printf("'l' - toggle linear/nearest filter\n"); + printf("'s' - toggle projection frustum\n"); + printf("'t' - toggle projected texture\n"); + printf("'o' - toggle object\n"); + printf("'z' - increase zoom factor\n"); + printf("'Z' - decrease zoom factor\n"); + printf("left mouse - move view\n"); + printf("middle mouse - move projection\n"); +} + +/* ARGSUSED1 */ +static void +key(unsigned char key, int x, int y) +{ + switch (key) { + case '\033': + exit(0); + break; + case 'l': + linearFilter = !linearFilter; + (*loadTexture) (); + break; + case 's': + showProjection = !showProjection; + break; + case 't': + texture(); + break; + case 'o': + object(); + break; + case 'z': + zoomFactor += 1.0; + glPixelZoom(zoomFactor, zoomFactor); + glViewport(0, 0, winWidth / zoomFactor, winHeight / zoomFactor); + break; + case 'Z': + zoomFactor -= 1.0; + if (zoomFactor < 1.0) + zoomFactor = 1.0; + glPixelZoom(zoomFactor, zoomFactor); + glViewport(0, 0, winWidth / zoomFactor, winHeight / zoomFactor); + break; + case 'h': + help(); + break; + } + glutPostRedisplay(); +} + +static void +mouse(int button, int state, int x, int y) +{ + if (state == GLUT_DOWN) + startMotion(x, y, button, glutGet(GLUT_ELAPSED_TIME)); + else if (state == GLUT_UP) + stopMotion(button, glutGet(GLUT_ELAPSED_TIME)); + glutPostRedisplay(); +} + +static void +reshape(int w, int h) +{ + winWidth = w; + winHeight = h; + glViewport(0, 0, w / zoomFactor, h / zoomFactor); +} + + +static void +menu(int selection) +{ + if (selection == 666) { + exit(0); + } + key((unsigned char) selection, 0, 0); +} + +int +main(int argc, char **argv) +{ + glutInit(&argc, argv); + + if (argc > 1) { + NumTextures = atoi(argv[1]); + } + assert(NumTextures <= MAX_TEX); + + glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); + glutInitWindowSize(500,500); + (void) glutCreateWindow("projtex"); + glewInit(); + + loadTexture = loadImageTextures; + drawObject = drawCube; + initialize(); + glutDisplayFunc(display); + glutKeyboardFunc(key); + glutReshapeFunc(reshape); + glutMouseFunc(mouse); + glutMotionFunc(trackMotion); + glutVisibilityFunc(vis); + glutCreateMenu(menu); + glutAddMenuEntry("Toggle showing projection", 's'); + glutAddMenuEntry("Switch texture", 't'); + glutAddMenuEntry("Switch object", 'o'); + glutAddMenuEntry("Toggle filtering", 'l'); + glutAddMenuEntry("Quit", 666); + glutAttachMenu(GLUT_RIGHT_BUTTON); + texture(); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 7dfc65807a..24275fdc2f 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -66,7 +66,6 @@ SOURCES = \ packedpixels.c \ pbo.c \ prog_parameter.c \ - projtex.c \ quads.c \ random.c \ readrate.c \ diff --git a/progs/tests/projtex.c b/progs/tests/projtex.c deleted file mode 100644 index 800d81ecd6..0000000000 --- a/progs/tests/projtex.c +++ /dev/null @@ -1,1030 +0,0 @@ - -/* projtex.c - by David Yu and David Blythe, SGI */ - -/** - ** Demonstrates simple projective texture mapping. - ** - ** Button1 changes view, Button2 moves texture. - ** - ** (See: Segal, Korobkin, van Widenfelt, Foran, and Haeberli - ** "Fast Shadows and Lighting Effects Using Texture Mapping", SIGGRAPH '92) - ** - ** 1994,1995 -- David G Yu - ** - ** cc -o projtex projtex.c texture.c -lglut -lGLU -lGL -lX11 -lm - **/ - -#include -#include -#include -#include -#include -#include -#if 0 -#include "texture.h" -#else -#include "../util/readtex.c" -#endif - - -/* Some files do not define M_PI... */ -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -#define MAX_TEX 4 -int NumTextures = 1; - -int winWidth, winHeight; - -GLboolean redrawContinuously = GL_FALSE; - -float angle, axis[3]; -enum MoveModes { - MoveNone, MoveView, MoveObject, MoveTexture -}; -enum MoveModes mode = MoveNone; - -GLfloat objectXform[4][4]; -GLfloat textureXform[MAX_TEX][4][4]; - -void (*drawObject) (void); -void (*loadTexture) (void); -GLboolean textureEnabled = GL_TRUE; -GLboolean showProjection = GL_TRUE; -GLboolean linearFilter = GL_TRUE; - -char *texFilename[MAX_TEX] = { - "../images/girl.rgb", - "../images/tile.rgb", - "../images/bw.rgb", - "../images/reflect.rgb" -}; - - -GLfloat zoomFactor = 1.0; - -/*****************************************************************/ - - -void ActiveTexture(int i) -{ - glActiveTextureARB(i); -} - - -/* matrix = identity */ -void -matrixIdentity(GLfloat matrix[16]) -{ - matrix[0] = 1.0; - matrix[1] = 0.0; - matrix[2] = 0.0; - matrix[3] = 0.0; - matrix[4] = 0.0; - matrix[5] = 1.0; - matrix[6] = 0.0; - matrix[7] = 0.0; - matrix[8] = 0.0; - matrix[9] = 0.0; - matrix[10] = 1.0; - matrix[11] = 0.0; - matrix[12] = 0.0; - matrix[13] = 0.0; - matrix[14] = 0.0; - matrix[15] = 1.0; -} - -/* matrix2 = transpose(matrix1) */ -void -matrixTranspose(GLfloat matrix2[16], GLfloat matrix1[16]) -{ - matrix2[0] = matrix1[0]; - matrix2[1] = matrix1[4]; - matrix2[2] = matrix1[8]; - matrix2[3] = matrix1[12]; - - matrix2[4] = matrix1[1]; - matrix2[5] = matrix1[5]; - matrix2[6] = matrix1[9]; - matrix2[7] = matrix1[13]; - - matrix2[8] = matrix1[2]; - matrix2[9] = matrix1[6]; - matrix2[10] = matrix1[10]; - matrix2[11] = matrix1[14]; - - matrix2[12] = matrix1[3]; - matrix2[13] = matrix1[7]; - matrix2[14] = matrix1[14]; - matrix2[15] = matrix1[15]; -} - -/*****************************************************************/ - -/* load SGI .rgb image (pad with a border of the specified width and color) */ -#if 0 -static void -imgLoad(char *filenameIn, int borderIn, GLfloat borderColorIn[4], - int *wOut, int *hOut, GLubyte ** imgOut) -{ - int border = borderIn; - int width, height; - int w, h; - GLubyte *image, *img, *p; - int i, j, components; - - image = (GLubyte *) read_texture(filenameIn, &width, &height, &components); - w = width + 2 * border; - h = height + 2 * border; - img = (GLubyte *) calloc(w * h, 4 * sizeof(unsigned char)); - - p = img; - for (j = -border; j < height + border; ++j) { - for (i = -border; i < width + border; ++i) { - if (0 <= j && j <= height - 1 && 0 <= i && i <= width - 1) { - p[0] = image[4 * (j * width + i) + 0]; - p[1] = image[4 * (j * width + i) + 1]; - p[2] = image[4 * (j * width + i) + 2]; - p[3] = 0xff; - } else { - p[0] = borderColorIn[0] * 0xff; - p[1] = borderColorIn[1] * 0xff; - p[2] = borderColorIn[2] * 0xff; - p[3] = borderColorIn[3] * 0xff; - } - p += 4; - } - } - free(image); - *wOut = w; - *hOut = h; - *imgOut = img; -} -#endif - - -/*****************************************************************/ - -/* Load the image file specified on the command line as the current texture */ -void -loadImageTextures(void) -{ - GLfloat borderColor[4] = - {1.0, 1.0, 1.0, 1.0}; - int tex; - - for (tex = 0; tex < NumTextures; tex++) { - GLubyte *image, *texData3, *texData4; - GLint imgWidth, imgHeight; - GLenum imgFormat; - int i, j; - - printf("loading %s\n", texFilename[tex]); - image = LoadRGBImage(texFilename[tex], &imgWidth, &imgHeight, &imgFormat); - if (!image) { - printf("can't find %s\n", texFilename[tex]); - exit(1); - } - assert(imgFormat == GL_RGB); - - /* scale to 256x256 */ - texData3 = malloc(256 * 256 * 4); - texData4 = malloc(256 * 256 * 4); - assert(texData3); - assert(texData4); - gluScaleImage(imgFormat, imgWidth, imgHeight, GL_UNSIGNED_BYTE, image, - 256, 256, GL_UNSIGNED_BYTE, texData3); - - /* convert to rgba */ - for (i = 0; i < 256 * 256; i++) { - texData4[i*4+0] = texData3[i*3+0]; - texData4[i*4+1] = texData3[i*3+1]; - texData4[i*4+2] = texData3[i*3+2]; - texData4[i*4+3] = 128; - } - - /* put transparent border around image */ - for (i = 0; i < 256; i++) { - texData4[i*4+0] = 255; - texData4[i*4+1] = 255; - texData4[i*4+2] = 255; - texData4[i*4+3] = 0; - } - j = 256 * 255 * 4; - for (i = 0; i < 256; i++) { - texData4[j + i*4+0] = 255; - texData4[j + i*4+1] = 255; - texData4[j + i*4+2] = 255; - texData4[j + i*4+3] = 0; - } - for (i = 0; i < 256; i++) { - j = i * 256 * 4; - texData4[j+0] = 255; - texData4[j+1] = 255; - texData4[j+2] = 255; - texData4[j+3] = 0; - } - for (i = 0; i < 256; i++) { - j = i * 256 * 4 + 255 * 4; - texData4[j+0] = 255; - texData4[j+1] = 255; - texData4[j+2] = 255; - texData4[j+3] = 0; - } - - ActiveTexture(GL_TEXTURE0_ARB + tex); - glBindTexture(GL_TEXTURE_2D, tex + 1); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, - GL_RGBA, GL_UNSIGNED_BYTE, texData4); - - if (linearFilter) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - } else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - } - glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); - } -} - -/* Create a simple spotlight pattern and make it the current texture */ -void -loadSpotlightTexture(void) -{ - static int texWidth = 64, texHeight = 64; - static GLubyte *texData; - GLfloat borderColor[4] = - {0.1, 0.1, 0.1, 1.0}; - - if (!texData) { - GLubyte *p; - int i, j; - - texData = (GLubyte *) malloc(texWidth * texHeight * 4 * sizeof(GLubyte)); - - p = texData; - for (j = 0; j < texHeight; ++j) { - float dy = (texHeight * 0.5 - j + 0.5) / (texHeight * 0.5); - - for (i = 0; i < texWidth; ++i) { - float dx = (texWidth * 0.5 - i + 0.5) / (texWidth * 0.5); - float r = cos(M_PI / 2.0 * sqrt(dx * dx + dy * dy)); - float c; - - r = (r < 0) ? 0 : r * r; - c = 0xff * (r + borderColor[0]); - p[0] = (c <= 0xff) ? c : 0xff; - c = 0xff * (r + borderColor[1]); - p[1] = (c <= 0xff) ? c : 0xff; - c = 0xff * (r + borderColor[2]); - p[2] = (c <= 0xff) ? c : 0xff; - c = 0xff * (r + borderColor[3]); - p[3] = (c <= 0xff) ? c : 0xff; - p += 4; - } - } - } - if (linearFilter) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - } else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - } - glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor); - gluBuild2DMipmaps(GL_TEXTURE_2D, 4, texWidth, texHeight, - GL_RGBA, GL_UNSIGNED_BYTE, texData); -} - -/*****************************************************************/ - -void -checkErrors(void) -{ - GLenum error; - while ((error = glGetError()) != GL_NO_ERROR) { - fprintf(stderr, "Error: %s\n", (char *) gluErrorString(error)); - } -} - -void -drawCube(void) -{ - glBegin(GL_QUADS); - - glNormal3f(-1.0, 0.0, 0.0); - glColor3f(0.80, 0.50, 0.50); - glVertex3f(-0.5, -0.5, -0.5); - glVertex3f(-0.5, -0.5, 0.5); - glVertex3f(-0.5, 0.5, 0.5); - glVertex3f(-0.5, 0.5, -0.5); - - glNormal3f(1.0, 0.0, 0.0); - glColor3f(0.50, 0.80, 0.50); - glVertex3f(0.5, 0.5, 0.5); - glVertex3f(0.5, -0.5, 0.5); - glVertex3f(0.5, -0.5, -0.5); - glVertex3f(0.5, 0.5, -0.5); - - glNormal3f(0.0, -1.0, 0.0); - glColor3f(0.50, 0.50, 0.80); - glVertex3f(-0.5, -0.5, -0.5); - glVertex3f(0.5, -0.5, -0.5); - glVertex3f(0.5, -0.5, 0.5); - glVertex3f(-0.5, -0.5, 0.5); - - glNormal3f(0.0, 1.0, 0.0); - glColor3f(0.50, 0.80, 0.80); - glVertex3f(0.5, 0.5, 0.5); - glVertex3f(0.5, 0.5, -0.5); - glVertex3f(-0.5, 0.5, -0.5); - glVertex3f(-0.5, 0.5, 0.5); - - glNormal3f(0.0, 0.0, -1.0); - glColor3f(0.80, 0.50, 0.80); - glVertex3f(-0.5, -0.5, -0.5); - glVertex3f(-0.5, 0.5, -0.5); - glVertex3f(0.5, 0.5, -0.5); - glVertex3f(0.5, -0.5, -0.5); - - glNormal3f(0.0, 0.0, 1.0); - glColor3f(1.00, 0.80, 0.50); - glVertex3f(0.5, 0.5, 0.5); - glVertex3f(-0.5, 0.5, 0.5); - glVertex3f(-0.5, -0.5, 0.5); - glVertex3f(0.5, -0.5, 0.5); - glEnd(); -} - -void -drawDodecahedron(void) -{ -#define A (0.5 * 1.61803) /* (sqrt(5) + 1) / 2 */ -#define B (0.5 * 0.61803) /* (sqrt(5) - 1) / 2 */ -#define C (0.5 * 1.0) - GLfloat vertexes[20][3] = - { - {-A, 0.0, B}, - {-A, 0.0, -B}, - {A, 0.0, -B}, - {A, 0.0, B}, - {B, -A, 0.0}, - {-B, -A, 0.0}, - {-B, A, 0.0}, - {B, A, 0.0}, - {0.0, B, -A}, - {0.0, -B, -A}, - {0.0, -B, A}, - {0.0, B, A}, - {-C, -C, C}, - {-C, -C, -C}, - {C, -C, -C}, - {C, -C, C}, - {-C, C, C}, - {-C, C, -C}, - {C, C, -C}, - {C, C, C}, - }; -#undef A -#undef B -#undef C - GLint polygons[12][5] = - { - {0, 12, 10, 11, 16}, - {1, 17, 8, 9, 13}, - {2, 14, 9, 8, 18}, - {3, 19, 11, 10, 15}, - {4, 14, 2, 3, 15}, - {5, 12, 0, 1, 13}, - {6, 17, 1, 0, 16}, - {7, 19, 3, 2, 18}, - {8, 17, 6, 7, 18}, - {9, 14, 4, 5, 13}, - {10, 12, 5, 4, 15}, - {11, 19, 7, 6, 16}, - }; - int i; - - glColor3f(0.75, 0.75, 0.75); - for (i = 0; i < 12; ++i) { - GLfloat *p0, *p1, *p2, d; - GLfloat u[3], v[3], n[3]; - - p0 = &vertexes[polygons[i][0]][0]; - p1 = &vertexes[polygons[i][1]][0]; - p2 = &vertexes[polygons[i][2]][0]; - - u[0] = p2[0] - p1[0]; - u[1] = p2[1] - p1[1]; - u[2] = p2[2] - p1[2]; - - v[0] = p0[0] - p1[0]; - v[1] = p0[1] - p1[1]; - v[2] = p0[2] - p1[2]; - - n[0] = u[1] * v[2] - u[2] * v[1]; - n[1] = u[2] * v[0] - u[0] * v[2]; - n[2] = u[0] * v[1] - u[1] * v[0]; - - d = 1.0 / sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); - n[0] *= d; - n[1] *= d; - n[2] *= d; - - glBegin(GL_POLYGON); - glNormal3fv(n); - glVertex3fv(p0); - glVertex3fv(p1); - glVertex3fv(p2); - glVertex3fv(vertexes[polygons[i][3]]); - glVertex3fv(vertexes[polygons[i][4]]); - glEnd(); - } -} - -void -drawSphere(void) -{ - int numMajor = 24; - int numMinor = 32; - float radius = 0.8; - double majorStep = (M_PI / numMajor); - double minorStep = (2.0 * M_PI / numMinor); - int i, j; - - glColor3f(0.50, 0.50, 0.50); - for (i = 0; i < numMajor; ++i) { - double a = i * majorStep; - double b = a + majorStep; - double r0 = radius * sin(a); - double r1 = radius * sin(b); - GLfloat z0 = radius * cos(a); - GLfloat z1 = radius * cos(b); - - glBegin(GL_TRIANGLE_STRIP); - for (j = 0; j <= numMinor; ++j) { - double c = j * minorStep; - GLfloat x = cos(c); - GLfloat y = sin(c); - - glNormal3f((x * r0) / radius, (y * r0) / radius, z0 / radius); - glTexCoord2f(j / (GLfloat) numMinor, i / (GLfloat) numMajor); - glVertex3f(x * r0, y * r0, z0); - - glNormal3f((x * r1) / radius, (y * r1) / radius, z1 / radius); - glTexCoord2f(j / (GLfloat) numMinor, (i + 1) / (GLfloat) numMajor); - glVertex3f(x * r1, y * r1, z1); - } - glEnd(); - } -} - -/*****************************************************************/ - -float xmin = -0.035, xmax = 0.035; -float ymin = -0.035, ymax = 0.035; -float nnear = 0.1; -float ffar = 1.9; -float distance = -1.0; - -static void -loadTextureProjection(int texUnit, GLfloat m[16]) -{ - GLfloat mInverse[4][4]; - - /* Should use true inverse, but since m consists only of rotations, we can - just use the transpose. */ - matrixTranspose((GLfloat *) mInverse, m); - - ActiveTexture(GL_TEXTURE0_ARB + texUnit); - glMatrixMode(GL_TEXTURE); - glLoadIdentity(); - glTranslatef(0.5, 0.5, 0.0); - glScalef(0.5, 0.5, 1.0); - glFrustum(xmin, xmax, ymin, ymax, nnear, ffar); - glTranslatef(0.0, 0.0, distance); - glMultMatrixf((GLfloat *) mInverse); - glMatrixMode(GL_MODELVIEW); -} - -static void -drawTextureProjection(void) -{ - float t = ffar / nnear; - GLfloat n[4][3]; - GLfloat f[4][3]; - - n[0][0] = xmin; - n[0][1] = ymin; - n[0][2] = -(nnear + distance); - - n[1][0] = xmax; - n[1][1] = ymin; - n[1][2] = -(nnear + distance); - - n[2][0] = xmax; - n[2][1] = ymax; - n[2][2] = -(nnear + distance); - - n[3][0] = xmin; - n[3][1] = ymax; - n[3][2] = -(nnear + distance); - - f[0][0] = xmin * t; - f[0][1] = ymin * t; - f[0][2] = -(ffar + distance); - - f[1][0] = xmax * t; - f[1][1] = ymin * t; - f[1][2] = -(ffar + distance); - - f[2][0] = xmax * t; - f[2][1] = ymax * t; - f[2][2] = -(ffar + distance); - - f[3][0] = xmin * t; - f[3][1] = ymax * t; - f[3][2] = -(ffar + distance); - - glColor3f(1.0, 1.0, 0.0); - glBegin(GL_LINE_LOOP); - glVertex3fv(n[0]); - glVertex3fv(n[1]); - glVertex3fv(n[2]); - glVertex3fv(n[3]); - glVertex3fv(f[3]); - glVertex3fv(f[2]); - glVertex3fv(f[1]); - glVertex3fv(f[0]); - glVertex3fv(n[0]); - glVertex3fv(n[1]); - glVertex3fv(f[1]); - glVertex3fv(f[0]); - glVertex3fv(f[3]); - glVertex3fv(f[2]); - glVertex3fv(n[2]); - glVertex3fv(n[3]); - glEnd(); -} - -/*****************************************************************/ - -void -initialize(void) -{ - GLfloat light0Pos[4] = - {0.3, 0.3, 0.0, 1.0}; - GLfloat matAmb[4] = - {0.01, 0.01, 0.01, 1.00}; - GLfloat matDiff[4] = - {0.65, 0.65, 0.65, 1.00}; - GLfloat matSpec[4] = - {0.30, 0.30, 0.30, 1.00}; - GLfloat matShine = 10.0; - GLfloat eyePlaneS[] = - {1.0, 0.0, 0.0, 0.0}; - GLfloat eyePlaneT[] = - {0.0, 1.0, 0.0, 0.0}; - GLfloat eyePlaneR[] = - {0.0, 0.0, 1.0, 0.0}; - GLfloat eyePlaneQ[] = - {0.0, 0.0, 0.0, 1.0}; - int i; - - /* Setup Misc. */ - glClearColor(0.41, 0.41, 0.31, 0.0); - - glEnable(GL_DEPTH_TEST); - - /* glLineWidth(2.0);*/ - - glCullFace(GL_FRONT); - glEnable(GL_CULL_FACE); - - glMatrixMode(GL_PROJECTION); - glFrustum(-0.5, 0.5, -0.5, 0.5, 1, 3); - glMatrixMode(GL_MODELVIEW); - glTranslatef(0, 0, -2); - - matrixIdentity((GLfloat *) objectXform); - for (i = 0; i < NumTextures; i++) { - matrixIdentity((GLfloat *) textureXform[i]); - } - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(0, 1, 0, 1, -1, 1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - glRasterPos2i(0, 0); - - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - - /* Setup Lighting */ - glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmb); - glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiff); - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpec); - glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, matShine); - - glEnable(GL_COLOR_MATERIAL); - - glLightfv(GL_LIGHT0, GL_POSITION, light0Pos); - glEnable(GL_LIGHT0); - - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); - glEnable(GL_LIGHTING); - - /* Setup Texture */ - - (*loadTexture) (); - - - for (i = 0; i < NumTextures; i++) { - ActiveTexture(GL_TEXTURE0_ARB + i); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); - glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - - glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); - glTexGenfv(GL_S, GL_EYE_PLANE, eyePlaneS); - - glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); - glTexGenfv(GL_T, GL_EYE_PLANE, eyePlaneT); - - glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); - glTexGenfv(GL_R, GL_EYE_PLANE, eyePlaneR); - - glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); - glTexGenfv(GL_Q, GL_EYE_PLANE, eyePlaneQ); - } -} - -void -display(void) -{ - int i; - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - if (textureEnabled) { - if (mode == MoveTexture || mode == MoveView) { - /* Have OpenGL compute the new transformation (simple but slow). */ - for (i = 0; i < NumTextures; i++) { - glPushMatrix(); - glLoadIdentity(); -#if 0 - if (i & 1) - glRotatef(angle, axis[0], axis[1], axis[2]); - else -#endif - glRotatef(angle*(i+1), axis[0], axis[1], axis[2]); - - glMultMatrixf((GLfloat *) textureXform[i]); - glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) textureXform[i]); - glPopMatrix(); - } - } - for (i = 0; i < NumTextures; i++) { - loadTextureProjection(i, (GLfloat *) textureXform[i]); - } - - if (showProjection) { - for (i = 0; i < NumTextures; i++) { - ActiveTexture(GL_TEXTURE0_ARB + i); - glPushMatrix(); - glMultMatrixf((GLfloat *) textureXform[i]); - glDisable(GL_LIGHTING); - drawTextureProjection(); - glEnable(GL_LIGHTING); - glPopMatrix(); - } - } - for (i = 0; i < NumTextures; i++) { - ActiveTexture(GL_TEXTURE0_ARB + i); - glEnable(GL_TEXTURE_2D); - glEnable(GL_TEXTURE_GEN_S); - glEnable(GL_TEXTURE_GEN_T); - glEnable(GL_TEXTURE_GEN_R); - glEnable(GL_TEXTURE_GEN_Q); - } - } - if (mode == MoveObject || mode == MoveView) { - /* Have OpenGL compute the new transformation (simple but slow). */ - glPushMatrix(); - glLoadIdentity(); - glRotatef(angle, axis[0], axis[1], axis[2]); - glMultMatrixf((GLfloat *) objectXform); - glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *) objectXform); - glPopMatrix(); - } - glPushMatrix(); - glMultMatrixf((GLfloat *) objectXform); - (*drawObject) (); - glPopMatrix(); - - for (i = 0; i < NumTextures; i++) { - ActiveTexture(GL_TEXTURE0_ARB + i); - glDisable(GL_TEXTURE_2D); - glDisable(GL_TEXTURE_GEN_S); - glDisable(GL_TEXTURE_GEN_T); - glDisable(GL_TEXTURE_GEN_R); - glDisable(GL_TEXTURE_GEN_Q); - } - - if (zoomFactor > 1.0) { - glDisable(GL_DEPTH_TEST); - glCopyPixels(0, 0, winWidth / zoomFactor, winHeight / zoomFactor, GL_COLOR); - glEnable(GL_DEPTH_TEST); - } - glFlush(); - glutSwapBuffers(); - checkErrors(); -} - -/*****************************************************************/ - -/* simple trackball-like motion control */ -float lastPos[3]; -int lastTime; - -void -ptov(int x, int y, int width, int height, float v[3]) -{ - float d, a; - - /* project x,y onto a hemi-sphere centered within width, height */ - v[0] = (2.0 * x - width) / width; - v[1] = (height - 2.0 * y) / height; - d = sqrt(v[0] * v[0] + v[1] * v[1]); - v[2] = cos((M_PI / 2.0) * ((d < 1.0) ? d : 1.0)); - a = 1.0 / sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); - v[0] *= a; - v[1] *= a; - v[2] *= a; -} - -void -startMotion(int x, int y, int but, int time) -{ - if (but == GLUT_LEFT_BUTTON) { - mode = MoveView; - } else if (but == GLUT_MIDDLE_BUTTON) { - mode = MoveTexture; - } else { - return; - } - - lastTime = time; - ptov(x, y, winWidth, winHeight, lastPos); -} - -void -animate(void) -{ - glutPostRedisplay(); -} - -void -vis(int visible) -{ - if (visible == GLUT_VISIBLE) { - if (redrawContinuously) - glutIdleFunc(animate); - } else { - if (redrawContinuously) - glutIdleFunc(NULL); - } -} - -void -stopMotion(int but, int time) -{ - if ((but == GLUT_LEFT_BUTTON && mode == MoveView) || - (but == GLUT_MIDDLE_BUTTON && mode == MoveTexture)) { - } else { - return; - } - - if (time == lastTime) { - /* redrawContinuously = GL_TRUE;*/ - glutIdleFunc(animate); - } else { - angle = 0.0; - redrawContinuously = GL_FALSE; - glutIdleFunc(0); - } - if (!redrawContinuously) { - mode = MoveNone; - } -} - -void -trackMotion(int x, int y) -{ - float curPos[3], dx, dy, dz; - - ptov(x, y, winWidth, winHeight, curPos); - - dx = curPos[0] - lastPos[0]; - dy = curPos[1] - lastPos[1]; - dz = curPos[2] - lastPos[2]; - angle = 90.0 * sqrt(dx * dx + dy * dy + dz * dz); - - axis[0] = lastPos[1] * curPos[2] - lastPos[2] * curPos[1]; - axis[1] = lastPos[2] * curPos[0] - lastPos[0] * curPos[2]; - axis[2] = lastPos[0] * curPos[1] - lastPos[1] * curPos[0]; - - lastTime = glutGet(GLUT_ELAPSED_TIME); - lastPos[0] = curPos[0]; - lastPos[1] = curPos[1]; - lastPos[2] = curPos[2]; - glutPostRedisplay(); -} - -/*****************************************************************/ - -void -object(void) -{ - static int object; - - object++; - object %= 3; - switch (object) { - case 0: - drawObject = drawCube; - break; - case 1: - drawObject = drawDodecahedron; - break; - case 2: - drawObject = drawSphere; - break; - default: - break; - } -} - -static void -nop(void) -{ -} - -void -texture(void) -{ - static int texture = 0; - - texture++; - texture %= 3; - if (texture == 1 && texFilename == NULL) { - /* Skip file texture if not loaded. */ - texture++; - } - switch (texture) { - case 0: - loadTexture = nop; - textureEnabled = GL_FALSE; - break; - case 1: - loadTexture = loadImageTextures; - (*loadTexture) (); - textureEnabled = GL_TRUE; - break; - case 2: - loadTexture = loadSpotlightTexture; - (*loadTexture) (); - textureEnabled = GL_TRUE; - break; - default: - break; - } -} - -void -help(void) -{ - printf("'h' - help\n"); - printf("'l' - toggle linear/nearest filter\n"); - printf("'s' - toggle projection frustum\n"); - printf("'t' - toggle projected texture\n"); - printf("'o' - toggle object\n"); - printf("'z' - increase zoom factor\n"); - printf("'Z' - decrease zoom factor\n"); - printf("left mouse - move view\n"); - printf("middle mouse - move projection\n"); -} - -/* ARGSUSED1 */ -void -key(unsigned char key, int x, int y) -{ - switch (key) { - case '\033': - exit(0); - break; - case 'l': - linearFilter = !linearFilter; - (*loadTexture) (); - break; - case 's': - showProjection = !showProjection; - break; - case 't': - texture(); - break; - case 'o': - object(); - break; - case 'z': - zoomFactor += 1.0; - glPixelZoom(zoomFactor, zoomFactor); - glViewport(0, 0, winWidth / zoomFactor, winHeight / zoomFactor); - break; - case 'Z': - zoomFactor -= 1.0; - if (zoomFactor < 1.0) - zoomFactor = 1.0; - glPixelZoom(zoomFactor, zoomFactor); - glViewport(0, 0, winWidth / zoomFactor, winHeight / zoomFactor); - break; - case 'h': - help(); - break; - } - glutPostRedisplay(); -} - -void -mouse(int button, int state, int x, int y) -{ - if (state == GLUT_DOWN) - startMotion(x, y, button, glutGet(GLUT_ELAPSED_TIME)); - else if (state == GLUT_UP) - stopMotion(button, glutGet(GLUT_ELAPSED_TIME)); - glutPostRedisplay(); -} - -void -reshape(int w, int h) -{ - winWidth = w; - winHeight = h; - glViewport(0, 0, w / zoomFactor, h / zoomFactor); -} - - -void -menu(int selection) -{ - if (selection == 666) { - exit(0); - } - key((unsigned char) selection, 0, 0); -} - -int -main(int argc, char **argv) -{ - glutInit(&argc, argv); - - if (argc > 1) { - NumTextures = atoi(argv[1]); - } - assert(NumTextures <= MAX_TEX); - - glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); - (void) glutCreateWindow("projtex"); - glewInit(); - - loadTexture = loadImageTextures; - drawObject = drawCube; - initialize(); - glutDisplayFunc(display); - glutKeyboardFunc(key); - glutReshapeFunc(reshape); - glutMouseFunc(mouse); - glutMotionFunc(trackMotion); - glutVisibilityFunc(vis); - glutCreateMenu(menu); - glutAddMenuEntry("Toggle showing projection", 's'); - glutAddMenuEntry("Switch texture", 't'); - glutAddMenuEntry("Switch object", 'o'); - glutAddMenuEntry("Toggle filtering", 'l'); - glutAddMenuEntry("Quit", 666); - glutAttachMenu(GLUT_RIGHT_BUTTON); - texture(); - glutMainLoop(); - return 0; /* ANSI C requires main to return int. */ -} -- cgit v1.2.3 From 22af013f85debd0030f2fb00061ce0412fdc0797 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 13:08:48 -0600 Subject: demos: move tests/dinoshade.c to demos/ --- progs/demos/Makefile | 1 + progs/demos/dinoshade.c | 912 ++++++++++++++++++++++++++++++++++++++++++++++++ progs/tests/Makefile | 1 - progs/tests/dinoshade.c | 912 ------------------------------------------------ 4 files changed, 913 insertions(+), 913 deletions(-) create mode 100644 progs/demos/dinoshade.c delete mode 100644 progs/tests/dinoshade.c (limited to 'progs') diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 2fe407972d..8febc14d41 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -19,6 +19,7 @@ PROGS = \ clearspd \ copypix \ cubemap \ + dinoshade \ drawpix \ engine \ fbo_firecube \ diff --git a/progs/demos/dinoshade.c b/progs/demos/dinoshade.c new file mode 100644 index 0000000000..451da2ec89 --- /dev/null +++ b/progs/demos/dinoshade.c @@ -0,0 +1,912 @@ + +/* Copyright (c) Mark J. Kilgard, 1994, 1997. */ + +/* This program is freely distributable without licensing fees + and is provided without guarantee or warrantee expressed or + implied. This program is -not- in the public domain. */ + +/* Example for PC game developers to show how to *combine* texturing, + reflections, and projected shadows all in real-time with OpenGL. + Robust reflections use stenciling. Robust projected shadows + use both stenciling and polygon offset. PC game programmers + should realize that neither stenciling nor polygon offset are + supported by Direct3D, so these real-time rendering algorithms + are only really viable with OpenGL. + + The program has modes for disabling the stenciling and polygon + offset uses. It is worth running this example with these features + toggled off so you can see the sort of artifacts that result. + + Notice that the floor texturing, reflections, and shadowing + all co-exist properly. */ + +/* When you run this program: Left mouse button controls the + view. Middle mouse button controls light position (left & + right rotates light around dino; up & down moves light + position up and down). Right mouse button pops up menu. */ + +/* Check out the comments in the "redraw" routine to see how the + reflection blending and surface stenciling is done. You can + also see in "redraw" how the projected shadows are rendered, + including the use of stenciling and polygon offset. */ + +/* This program is derived from glutdino.c */ + +/* Compile: cc -o dinoshade dinoshade.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */ + +#include +#include +#include +#include /* for cos(), sin(), and sqrt() */ +#include /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */ +#ifdef _WIN32 +#include +#endif +#define GL_GLEXT_LEGACY +#include /* OpenGL Utility Toolkit header */ +#include /* OpenGL Utility Toolkit header */ + +/* Some files do not define M_PI... */ +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif + +/* Variable controlling various rendering modes. */ +static int stencilReflection = 1, stencilShadow = 1, offsetShadow = 1; +static int renderShadow = 1, renderDinosaur = 1, renderReflection = 1; +static int linearFiltering = 0, useMipmaps = 0, useTexture = 1; +static int reportSpeed = 0; +static int animation = 1; +static GLboolean lightSwitch = GL_TRUE; +static int directionalLight = 1; +static int forceExtension = 0; + +/* Time varying or user-controled variables. */ +static float jump = 0.0; +static float lightAngle = 0.0, lightHeight = 20; +GLfloat angle = -150; /* in degrees */ +GLfloat angle2 = 30; /* in degrees */ + +int moving, startx, starty; +int lightMoving = 0, lightStartX, lightStartY; + +enum { + MISSING, EXTENSION, ONE_DOT_ONE +}; +int polygonOffsetVersion; + +static GLdouble bodyWidth = 3.0; +/* *INDENT-OFF* */ +static GLfloat body[][2] = { {0, 3}, {1, 1}, {5, 1}, {8, 4}, {10, 4}, {11, 5}, + {11, 11.5}, {13, 12}, {13, 13}, {10, 13.5}, {13, 14}, {13, 15}, {11, 16}, + {8, 16}, {7, 15}, {7, 13}, {8, 12}, {7, 11}, {6, 6}, {4, 3}, {3, 2}, + {1, 2} }; +static GLfloat arm[][2] = { {8, 10}, {9, 9}, {10, 9}, {13, 8}, {14, 9}, {16, 9}, + {15, 9.5}, {16, 10}, {15, 10}, {15.5, 11}, {14.5, 10}, {14, 11}, {14, 10}, + {13, 9}, {11, 11}, {9, 11} }; +static GLfloat leg[][2] = { {8, 6}, {8, 4}, {9, 3}, {9, 2}, {8, 1}, {8, 0.5}, {9, 0}, + {12, 0}, {10, 1}, {10, 2}, {12, 4}, {11, 6}, {10, 7}, {9, 7} }; +static GLfloat eye[][2] = { {8.75, 15}, {9, 14.7}, {9.6, 14.7}, {10.1, 15}, + {9.6, 15.25}, {9, 15.25} }; +static GLfloat lightPosition[4]; +static GLfloat lightColor[] = {0.8, 1.0, 0.8, 1.0}; /* green-tinted */ +static GLfloat skinColor[] = {0.1, 1.0, 0.1, 1.0}, eyeColor[] = {1.0, 0.2, 0.2, 1.0}; +/* *INDENT-ON* */ + +/* Nice floor texture tiling pattern. */ +static char *circles[] = { + "....xxxx........", + "..xxxxxxxx......", + ".xxxxxxxxxx.....", + ".xxx....xxx.....", + "xxx......xxx....", + "xxx......xxx....", + "xxx......xxx....", + "xxx......xxx....", + ".xxx....xxx.....", + ".xxxxxxxxxx.....", + "..xxxxxxxx......", + "....xxxx........", + "................", + "................", + "................", + "................", +}; + +static void +makeFloorTexture(void) +{ + GLubyte floorTexture[16][16][3]; + GLubyte *loc; + int s, t; + + /* Setup RGB image for the texture. */ + loc = (GLubyte*) floorTexture; + for (t = 0; t < 16; t++) { + for (s = 0; s < 16; s++) { + if (circles[t][s] == 'x') { + /* Nice green. */ + loc[0] = 0x1f; + loc[1] = 0x8f; + loc[2] = 0x1f; + } else { + /* Light gray. */ + loc[0] = 0xaa; + loc[1] = 0xaa; + loc[2] = 0xaa; + } + loc += 3; + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + if (useMipmaps) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 16, 16, + GL_RGB, GL_UNSIGNED_BYTE, floorTexture); + } else { + if (linearFiltering) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + } + glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0, + GL_RGB, GL_UNSIGNED_BYTE, floorTexture); + } +} + +enum { + X, Y, Z, W +}; +enum { + A, B, C, D +}; + +/* Create a matrix that will project the desired shadow. */ +static void +shadowMatrix(GLfloat shadowMat[4][4], + GLfloat groundplane[4], + GLfloat lightpos[4]) +{ + GLfloat dot; + + /* Find dot product between light position vector and ground plane normal. */ + dot = groundplane[X] * lightpos[X] + + groundplane[Y] * lightpos[Y] + + groundplane[Z] * lightpos[Z] + + groundplane[W] * lightpos[W]; + + shadowMat[0][0] = dot - lightpos[X] * groundplane[X]; + shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y]; + shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z]; + shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W]; + + shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X]; + shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y]; + shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z]; + shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W]; + + shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X]; + shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y]; + shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z]; + shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W]; + + shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X]; + shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y]; + shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z]; + shadowMat[3][3] = dot - lightpos[W] * groundplane[W]; + +} + +/* Find the plane equation given 3 points. */ +static void +findPlane(GLfloat plane[4], + GLfloat v0[3], GLfloat v1[3], GLfloat v2[3]) +{ + GLfloat vec0[3], vec1[3]; + + /* Need 2 vectors to find cross product. */ + vec0[X] = v1[X] - v0[X]; + vec0[Y] = v1[Y] - v0[Y]; + vec0[Z] = v1[Z] - v0[Z]; + + vec1[X] = v2[X] - v0[X]; + vec1[Y] = v2[Y] - v0[Y]; + vec1[Z] = v2[Z] - v0[Z]; + + /* find cross product to get A, B, and C of plane equation */ + plane[A] = vec0[Y] * vec1[Z] - vec0[Z] * vec1[Y]; + plane[B] = -(vec0[X] * vec1[Z] - vec0[Z] * vec1[X]); + plane[C] = vec0[X] * vec1[Y] - vec0[Y] * vec1[X]; + + plane[D] = -(plane[A] * v0[X] + plane[B] * v0[Y] + plane[C] * v0[Z]); +} + +static void +extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize, + GLdouble thickness, GLuint side, GLuint edge, GLuint whole) +{ + static GLUtriangulatorObj *tobj = NULL; + GLdouble vertex[3], dx, dy, len; + int i; + int count = (int) (dataSize / (2 * sizeof(GLfloat))); + + if (tobj == NULL) { + tobj = gluNewTess(); /* create and initialize a GLU + polygon tesselation object */ + gluTessCallback(tobj, GLU_BEGIN, glBegin); + gluTessCallback(tobj, GLU_VERTEX, glVertex2fv); /* semi-tricky */ + gluTessCallback(tobj, GLU_END, glEnd); + } + glNewList(side, GL_COMPILE); + glShadeModel(GL_SMOOTH); /* smooth minimizes seeing + tessellation */ + gluBeginPolygon(tobj); + for (i = 0; i < count; i++) { + vertex[0] = data[i][0]; + vertex[1] = data[i][1]; + vertex[2] = 0; + gluTessVertex(tobj, vertex, data[i]); + } + gluEndPolygon(tobj); + glEndList(); + glNewList(edge, GL_COMPILE); + glShadeModel(GL_FLAT); /* flat shade keeps angular hands + from being "smoothed" */ + glBegin(GL_QUAD_STRIP); + for (i = 0; i <= count; i++) { +#if 1 /* weird, but seems to be legal */ + /* mod function handles closing the edge */ + glVertex3f(data[i % count][0], data[i % count][1], 0.0); + glVertex3f(data[i % count][0], data[i % count][1], thickness); + /* Calculate a unit normal by dividing by Euclidean + distance. We * could be lazy and use + glEnable(GL_NORMALIZE) so we could pass in * arbitrary + normals for a very slight performance hit. */ + dx = data[(i + 1) % count][1] - data[i % count][1]; + dy = data[i % count][0] - data[(i + 1) % count][0]; + len = sqrt(dx * dx + dy * dy); + glNormal3f(dx / len, dy / len, 0.0); +#else /* the nice way of doing it */ + /* Calculate a unit normal by dividing by Euclidean + distance. We * could be lazy and use + glEnable(GL_NORMALIZE) so we could pass in * arbitrary + normals for a very slight performance hit. */ + dx = data[i % count][1] - data[(i - 1 + count) % count][1]; + dy = data[(i - 1 + count) % count][0] - data[i % count][0]; + len = sqrt(dx * dx + dy * dy); + glNormal3f(dx / len, dy / len, 0.0); + /* mod function handles closing the edge */ + glVertex3f(data[i % count][0], data[i % count][1], 0.0); + glVertex3f(data[i % count][0], data[i % count][1], thickness); +#endif + } + glEnd(); + glEndList(); + glNewList(whole, GL_COMPILE); + glFrontFace(GL_CW); + glCallList(edge); + glNormal3f(0.0, 0.0, -1.0); /* constant normal for side */ + glCallList(side); + glPushMatrix(); + glTranslatef(0.0, 0.0, thickness); + glFrontFace(GL_CCW); + glNormal3f(0.0, 0.0, 1.0); /* opposite normal for other side */ + glCallList(side); + glPopMatrix(); + glEndList(); +} + +/* Enumerants for refering to display lists. */ +typedef enum { + RESERVED, BODY_SIDE, BODY_EDGE, BODY_WHOLE, ARM_SIDE, ARM_EDGE, ARM_WHOLE, + LEG_SIDE, LEG_EDGE, LEG_WHOLE, EYE_SIDE, EYE_EDGE, EYE_WHOLE +} displayLists; + +static void +makeDinosaur(void) +{ + extrudeSolidFromPolygon(body, sizeof(body), bodyWidth, + BODY_SIDE, BODY_EDGE, BODY_WHOLE); + extrudeSolidFromPolygon(arm, sizeof(arm), bodyWidth / 4, + ARM_SIDE, ARM_EDGE, ARM_WHOLE); + extrudeSolidFromPolygon(leg, sizeof(leg), bodyWidth / 2, + LEG_SIDE, LEG_EDGE, LEG_WHOLE); + extrudeSolidFromPolygon(eye, sizeof(eye), bodyWidth + 0.2, + EYE_SIDE, EYE_EDGE, EYE_WHOLE); +} + +static void +drawDinosaur(void) + +{ + glPushMatrix(); + /* Translate the dinosaur to be at (0,8,0). */ + glTranslatef(-8, 0, -bodyWidth / 2); + glTranslatef(0.0, jump, 0.0); + glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor); + glCallList(BODY_WHOLE); + glTranslatef(0.0, 0.0, bodyWidth); + glCallList(ARM_WHOLE); + glCallList(LEG_WHOLE); + glTranslatef(0.0, 0.0, -bodyWidth - bodyWidth / 4); + glCallList(ARM_WHOLE); + glTranslatef(0.0, 0.0, -bodyWidth / 4); + glCallList(LEG_WHOLE); + glTranslatef(0.0, 0.0, bodyWidth / 2 - 0.1); + glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor); + glCallList(EYE_WHOLE); + glPopMatrix(); +} + +static GLfloat floorVertices[4][3] = { + { -20.0, 0.0, 20.0 }, + { 20.0, 0.0, 20.0 }, + { 20.0, 0.0, -20.0 }, + { -20.0, 0.0, -20.0 }, +}; + +/* Draw a floor (possibly textured). */ +static void +drawFloor(void) +{ + glDisable(GL_LIGHTING); + + if (useTexture) { + glEnable(GL_TEXTURE_2D); + } + + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); + glVertex3fv(floorVertices[0]); + glTexCoord2f(0.0, 16.0); + glVertex3fv(floorVertices[1]); + glTexCoord2f(16.0, 16.0); + glVertex3fv(floorVertices[2]); + glTexCoord2f(16.0, 0.0); + glVertex3fv(floorVertices[3]); + glEnd(); + + if (useTexture) { + glDisable(GL_TEXTURE_2D); + } + + glEnable(GL_LIGHTING); +} + +static GLfloat floorPlane[4]; +static GLfloat floorShadow[4][4]; + +static void +redraw(void) +{ + int start, end; + + if (reportSpeed) { + start = glutGet(GLUT_ELAPSED_TIME); + } + + /* Clear; default stencil clears to zero. */ + if ((stencilReflection && renderReflection) || (stencilShadow && renderShadow)) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); + } else { + /* Avoid clearing stencil when not using it. */ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + } + + /* Reposition the light source. */ + lightPosition[0] = 12*cos(lightAngle); + lightPosition[1] = lightHeight; + lightPosition[2] = 12*sin(lightAngle); + if (directionalLight) { + lightPosition[3] = 0.0; + } else { + lightPosition[3] = 1.0; + } + + shadowMatrix(floorShadow, floorPlane, lightPosition); + + glPushMatrix(); + /* Perform scene rotations based on user mouse input. */ + glRotatef(angle2, 1.0, 0.0, 0.0); + glRotatef(angle, 0.0, 1.0, 0.0); + + /* Tell GL new light source position. */ + glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); + + if (renderReflection) { + if (stencilReflection) { + /* We can eliminate the visual "artifact" of seeing the "flipped" + dinosaur underneath the floor by using stencil. The idea is + draw the floor without color or depth update but so that + a stencil value of one is where the floor will be. Later when + rendering the dinosaur reflection, we will only update pixels + with a stencil value of 1 to make sure the reflection only + lives on the floor, not below the floor. */ + + /* Don't update color or depth. */ + glDisable(GL_DEPTH_TEST); + glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); + + /* Draw 1 into the stencil buffer. */ + glEnable(GL_STENCIL_TEST); + glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); + glStencilFunc(GL_ALWAYS, 1, 0xffffffff); + + /* Now render floor; floor pixels just get their stencil set to 1. */ + drawFloor(); + + /* Re-enable update of color and depth. */ + glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); + glEnable(GL_DEPTH_TEST); + + /* Now, only render where stencil is set to 1. */ + glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */ + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); + } + + glPushMatrix(); + + /* The critical reflection step: Reflect dinosaur through the floor + (the Y=0 plane) to make a relection. */ + glScalef(1.0, -1.0, 1.0); + + /* Reflect the light position. */ + glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); + + /* To avoid our normals getting reversed and hence botched lighting + on the reflection, turn on normalize. */ + glEnable(GL_NORMALIZE); + glCullFace(GL_FRONT); + + /* Draw the reflected dinosaur. */ + drawDinosaur(); + + /* Disable noramlize again and re-enable back face culling. */ + glDisable(GL_NORMALIZE); + glCullFace(GL_BACK); + + glPopMatrix(); + + /* Switch back to the unreflected light position. */ + glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); + + if (stencilReflection) { + glDisable(GL_STENCIL_TEST); + } + } + + /* Back face culling will get used to only draw either the top or the + bottom floor. This let's us get a floor with two distinct + appearances. The top floor surface is reflective and kind of red. + The bottom floor surface is not reflective and blue. */ + + /* Draw "bottom" of floor in blue. */ + glFrontFace(GL_CW); /* Switch face orientation. */ + glColor4f(0.1, 0.1, 0.7, 1.0); + drawFloor(); + glFrontFace(GL_CCW); + + if (renderShadow) { + if (stencilShadow) { + /* Draw the floor with stencil value 3. This helps us only + draw the shadow once per floor pixel (and only on the + floor pixels). */ + glEnable(GL_STENCIL_TEST); + glStencilFunc(GL_ALWAYS, 3, 0xffffffff); + glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); + } + } + + /* Draw "top" of floor. Use blending to blend in reflection. */ + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor4f(0.7, 0.0, 0.0, 0.3); + glColor4f(1.0, 1.0, 1.0, 0.3); + drawFloor(); + glDisable(GL_BLEND); + + if (renderDinosaur) { + /* Draw "actual" dinosaur, not its reflection. */ + drawDinosaur(); + } + + if (renderShadow) { + + /* Render the projected shadow. */ + + if (stencilShadow) { + + /* Now, only render where stencil is set above 2 (ie, 3 where + the top floor is). Update stencil with 2 where the shadow + gets drawn so we don't redraw (and accidently reblend) the + shadow). */ + glStencilFunc(GL_LESS, 2, 0xffffffff); /* draw if ==1 */ + glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); + } + + /* To eliminate depth buffer artifacts, we use polygon offset + to raise the depth of the projected shadow slightly so + that it does not depth buffer alias with the floor. */ + if (offsetShadow) { + switch (polygonOffsetVersion) { + case EXTENSION: +#ifdef GL_EXT_polygon_offset + glEnable(GL_POLYGON_OFFSET_EXT); + break; +#endif +#ifdef GL_VERSION_1_1 + case ONE_DOT_ONE: + glEnable(GL_POLYGON_OFFSET_FILL); + break; +#endif + case MISSING: + /* Oh well. */ + break; + } + } + + /* Render 50% black shadow color on top of whatever the + floor appareance is. */ + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_LIGHTING); /* Force the 50% black. */ + glColor4f(0.0, 0.0, 0.0, 0.5); + + glPushMatrix(); + /* Project the shadow. */ + glMultMatrixf((GLfloat *) floorShadow); + drawDinosaur(); + glPopMatrix(); + + glDisable(GL_BLEND); + glEnable(GL_LIGHTING); + + if (offsetShadow) { + switch (polygonOffsetVersion) { +#ifdef GL_EXT_polygon_offset + case EXTENSION: + glDisable(GL_POLYGON_OFFSET_EXT); + break; +#endif +#ifdef GL_VERSION_1_1 + case ONE_DOT_ONE: + glDisable(GL_POLYGON_OFFSET_FILL); + break; +#endif + case MISSING: + /* Oh well. */ + break; + } + } + if (stencilShadow) { + glDisable(GL_STENCIL_TEST); + } + } + + glPushMatrix(); + glDisable(GL_LIGHTING); + glColor3f(1.0, 1.0, 0.0); + if (directionalLight) { + /* Draw an arrowhead. */ + glDisable(GL_CULL_FACE); + glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); + glRotatef(lightAngle * -180.0 / M_PI, 0, 1, 0); + glRotatef(atan(lightHeight/12) * 180.0 / M_PI, 0, 0, 1); + glBegin(GL_TRIANGLE_FAN); + glVertex3f(0, 0, 0); + glVertex3f(2, 1, 1); + glVertex3f(2, -1, 1); + glVertex3f(2, -1, -1); + glVertex3f(2, 1, -1); + glVertex3f(2, 1, 1); + glEnd(); + /* Draw a white line from light direction. */ + glColor3f(1.0, 1.0, 1.0); + glBegin(GL_LINES); + glVertex3f(0, 0, 0); + glVertex3f(5, 0, 0); + glEnd(); + glEnable(GL_CULL_FACE); + } else { + /* Draw a yellow ball at the light source. */ + glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); + glutSolidSphere(1.0, 5, 5); + } + glEnable(GL_LIGHTING); + glPopMatrix(); + + glPopMatrix(); + + if (reportSpeed) { + glFinish(); + end = glutGet(GLUT_ELAPSED_TIME); + printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start); + } + + glutSwapBuffers(); +} + +/* ARGSUSED2 */ +static void +mouse(int button, int state, int x, int y) +{ + if (button == GLUT_LEFT_BUTTON) { + if (state == GLUT_DOWN) { + moving = 1; + startx = x; + starty = y; + } + if (state == GLUT_UP) { + moving = 0; + } + } + if (button == GLUT_MIDDLE_BUTTON) { + if (state == GLUT_DOWN) { + lightMoving = 1; + lightStartX = x; + lightStartY = y; + } + if (state == GLUT_UP) { + lightMoving = 0; + } + } +} + +/* ARGSUSED1 */ +static void +motion(int x, int y) +{ + if (moving) { + angle = angle + (x - startx); + angle2 = angle2 + (y - starty); + startx = x; + starty = y; + glutPostRedisplay(); + } + if (lightMoving) { + lightAngle += (x - lightStartX)/40.0; + lightHeight += (lightStartY - y)/20.0; + lightStartX = x; + lightStartY = y; + glutPostRedisplay(); + } +} + +/* Advance time varying state when idle callback registered. */ +static void +idle(void) +{ + static float time = 0.0; + + time = glutGet(GLUT_ELAPSED_TIME) / 500.0; + + jump = 4.0 * fabs(sin(time)*0.5); + if (!lightMoving) { + lightAngle += 0.03; + } + glutPostRedisplay(); +} + +enum { + M_NONE, M_MOTION, M_LIGHT, M_TEXTURE, M_SHADOWS, M_REFLECTION, M_DINOSAUR, + M_STENCIL_REFLECTION, M_STENCIL_SHADOW, M_OFFSET_SHADOW, + M_POSITIONAL, M_DIRECTIONAL, M_PERFORMANCE +}; + +static void +controlLights(int value) +{ + switch (value) { + case M_NONE: + return; + case M_MOTION: + animation = 1 - animation; + if (animation) { + glutIdleFunc(idle); + } else { + glutIdleFunc(NULL); + } + break; + case M_LIGHT: + lightSwitch = !lightSwitch; + if (lightSwitch) { + glEnable(GL_LIGHT0); + } else { + glDisable(GL_LIGHT0); + } + break; + case M_TEXTURE: + useTexture = !useTexture; + break; + case M_SHADOWS: + renderShadow = 1 - renderShadow; + break; + case M_REFLECTION: + renderReflection = 1 - renderReflection; + break; + case M_DINOSAUR: + renderDinosaur = 1 - renderDinosaur; + break; + case M_STENCIL_REFLECTION: + stencilReflection = 1 - stencilReflection; + break; + case M_STENCIL_SHADOW: + stencilShadow = 1 - stencilShadow; + break; + case M_OFFSET_SHADOW: + offsetShadow = 1 - offsetShadow; + break; + case M_POSITIONAL: + directionalLight = 0; + break; + case M_DIRECTIONAL: + directionalLight = 1; + break; + case M_PERFORMANCE: + reportSpeed = 1 - reportSpeed; + break; + } + glutPostRedisplay(); +} + +/* When not visible, stop animating. Restart when visible again. */ +static void +visible(int vis) +{ + if (vis == GLUT_VISIBLE) { + if (animation) + glutIdleFunc(idle); + } else { + if (!animation) + glutIdleFunc(NULL); + } +} + +/* Press any key to redraw; good when motion stopped and + performance reporting on. */ +/* ARGSUSED */ +static void +key(unsigned char c, int x, int y) +{ + if (c == 27) { + exit(0); /* IRIS GLism, Escape quits. */ + } + glutPostRedisplay(); +} + +/* Press any key to redraw; good when motion stopped and + performance reporting on. */ +/* ARGSUSED */ +static void +special(int k, int x, int y) +{ + glutPostRedisplay(); +} + +static int +supportsOneDotOne(void) +{ + const char *version; + int major, minor; + + version = (char *) glGetString(GL_VERSION); + if (sscanf(version, "%d.%d", &major, &minor) == 2) + return major * 10 + minor >= 11; + return 0; /* OpenGL version string malformed! */ +} + +int +main(int argc, char **argv) +{ + int i; + + glutInit(&argc, argv); + + for (i=1; i=2 rgb double depth"); +#endif + + glutCreateWindow("Shadowy Leapin' Lizards"); + glewInit(); + + if (glutGet(GLUT_WINDOW_STENCIL_SIZE) <= 1) { + printf("dinoshade: Sorry, I need at least 2 bits of stencil.\n"); + exit(1); + } + + /* Register GLUT callbacks. */ + glutDisplayFunc(redraw); + glutMouseFunc(mouse); + glutMotionFunc(motion); + glutVisibilityFunc(visible); + glutKeyboardFunc(key); + glutSpecialFunc(special); + + glutCreateMenu(controlLights); + + glutAddMenuEntry("Toggle motion", M_MOTION); + glutAddMenuEntry("-----------------------", M_NONE); + glutAddMenuEntry("Toggle light", M_LIGHT); + glutAddMenuEntry("Toggle texture", M_TEXTURE); + glutAddMenuEntry("Toggle shadows", M_SHADOWS); + glutAddMenuEntry("Toggle reflection", M_REFLECTION); + glutAddMenuEntry("Toggle dinosaur", M_DINOSAUR); + glutAddMenuEntry("-----------------------", M_NONE); + glutAddMenuEntry("Toggle reflection stenciling", M_STENCIL_REFLECTION); + glutAddMenuEntry("Toggle shadow stenciling", M_STENCIL_SHADOW); + glutAddMenuEntry("Toggle shadow offset", M_OFFSET_SHADOW); + glutAddMenuEntry("----------------------", M_NONE); + glutAddMenuEntry("Positional light", M_POSITIONAL); + glutAddMenuEntry("Directional light", M_DIRECTIONAL); + glutAddMenuEntry("-----------------------", M_NONE); + glutAddMenuEntry("Toggle performance", M_PERFORMANCE); + glutAttachMenu(GLUT_RIGHT_BUTTON); + makeDinosaur(); + +#ifdef GL_VERSION_1_1 + if (supportsOneDotOne() && !forceExtension) { + polygonOffsetVersion = ONE_DOT_ONE; + glPolygonOffset(-2.0, -9.0); + } else +#endif + { +#ifdef GL_EXT_polygon_offset + /* check for the polygon offset extension */ + if (glutExtensionSupported("GL_EXT_polygon_offset")) { + polygonOffsetVersion = EXTENSION; + glPolygonOffsetEXT(-2.0, -0.002); + } else +#endif + { + polygonOffsetVersion = MISSING; + printf("\ndinoshine: Missing polygon offset.\n"); + printf(" Expect shadow depth aliasing artifacts.\n\n"); + } + } + + glEnable(GL_CULL_FACE); + glEnable(GL_DEPTH_TEST); + glEnable(GL_TEXTURE_2D); + glLineWidth(3.0); + + glMatrixMode(GL_PROJECTION); + gluPerspective( /* field of view in degree */ 40.0, + /* aspect ratio */ 1.0, + /* Z near */ 20.0, /* Z far */ 100.0); + glMatrixMode(GL_MODELVIEW); + gluLookAt(0.0, 8.0, 60.0, /* eye is at (0,8,60) */ + 0.0, 8.0, 0.0, /* center is at (0,8,0) */ + 0.0, 1.0, 0.); /* up is in postivie Y direction */ + + glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); + glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); + glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1); + glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05); + glEnable(GL_LIGHT0); + glEnable(GL_LIGHTING); + + makeFloorTexture(); + + /* Setup floor plane for projected shadow calculations. */ + findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]); + + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 24275fdc2f..e5da72a3e4 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -37,7 +37,6 @@ SOURCES = \ copypixrate.c \ crossbar.c \ cva.c \ - dinoshade.c \ drawbuffers.c \ exactrast.c \ floattex.c \ diff --git a/progs/tests/dinoshade.c b/progs/tests/dinoshade.c deleted file mode 100644 index fb7c3f4535..0000000000 --- a/progs/tests/dinoshade.c +++ /dev/null @@ -1,912 +0,0 @@ - -/* Copyright (c) Mark J. Kilgard, 1994, 1997. */ - -/* This program is freely distributable without licensing fees - and is provided without guarantee or warrantee expressed or - implied. This program is -not- in the public domain. */ - -/* Example for PC game developers to show how to *combine* texturing, - reflections, and projected shadows all in real-time with OpenGL. - Robust reflections use stenciling. Robust projected shadows - use both stenciling and polygon offset. PC game programmers - should realize that neither stenciling nor polygon offset are - supported by Direct3D, so these real-time rendering algorithms - are only really viable with OpenGL. - - The program has modes for disabling the stenciling and polygon - offset uses. It is worth running this example with these features - toggled off so you can see the sort of artifacts that result. - - Notice that the floor texturing, reflections, and shadowing - all co-exist properly. */ - -/* When you run this program: Left mouse button controls the - view. Middle mouse button controls light position (left & - right rotates light around dino; up & down moves light - position up and down). Right mouse button pops up menu. */ - -/* Check out the comments in the "redraw" routine to see how the - reflection blending and surface stenciling is done. You can - also see in "redraw" how the projected shadows are rendered, - including the use of stenciling and polygon offset. */ - -/* This program is derived from glutdino.c */ - -/* Compile: cc -o dinoshade dinoshade.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */ - -#include -#include -#include -#include /* for cos(), sin(), and sqrt() */ -#include /* for ptrdiff_t, referenced by GL.h when GL_GLEXT_LEGACY defined */ -#ifdef _WIN32 -#include -#endif -#define GL_GLEXT_LEGACY -#include /* OpenGL Utility Toolkit header */ -#include /* OpenGL Utility Toolkit header */ - -/* Some files do not define M_PI... */ -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -/* Variable controlling various rendering modes. */ -static int stencilReflection = 1, stencilShadow = 1, offsetShadow = 1; -static int renderShadow = 1, renderDinosaur = 1, renderReflection = 1; -static int linearFiltering = 0, useMipmaps = 0, useTexture = 1; -static int reportSpeed = 0; -static int animation = 1; -static GLboolean lightSwitch = GL_TRUE; -static int directionalLight = 1; -static int forceExtension = 0; - -/* Time varying or user-controled variables. */ -static float jump = 0.0; -static float lightAngle = 0.0, lightHeight = 20; -GLfloat angle = -150; /* in degrees */ -GLfloat angle2 = 30; /* in degrees */ - -int moving, startx, starty; -int lightMoving = 0, lightStartX, lightStartY; - -enum { - MISSING, EXTENSION, ONE_DOT_ONE -}; -int polygonOffsetVersion; - -static GLdouble bodyWidth = 3.0; -/* *INDENT-OFF* */ -static GLfloat body[][2] = { {0, 3}, {1, 1}, {5, 1}, {8, 4}, {10, 4}, {11, 5}, - {11, 11.5}, {13, 12}, {13, 13}, {10, 13.5}, {13, 14}, {13, 15}, {11, 16}, - {8, 16}, {7, 15}, {7, 13}, {8, 12}, {7, 11}, {6, 6}, {4, 3}, {3, 2}, - {1, 2} }; -static GLfloat arm[][2] = { {8, 10}, {9, 9}, {10, 9}, {13, 8}, {14, 9}, {16, 9}, - {15, 9.5}, {16, 10}, {15, 10}, {15.5, 11}, {14.5, 10}, {14, 11}, {14, 10}, - {13, 9}, {11, 11}, {9, 11} }; -static GLfloat leg[][2] = { {8, 6}, {8, 4}, {9, 3}, {9, 2}, {8, 1}, {8, 0.5}, {9, 0}, - {12, 0}, {10, 1}, {10, 2}, {12, 4}, {11, 6}, {10, 7}, {9, 7} }; -static GLfloat eye[][2] = { {8.75, 15}, {9, 14.7}, {9.6, 14.7}, {10.1, 15}, - {9.6, 15.25}, {9, 15.25} }; -static GLfloat lightPosition[4]; -static GLfloat lightColor[] = {0.8, 1.0, 0.8, 1.0}; /* green-tinted */ -static GLfloat skinColor[] = {0.1, 1.0, 0.1, 1.0}, eyeColor[] = {1.0, 0.2, 0.2, 1.0}; -/* *INDENT-ON* */ - -/* Nice floor texture tiling pattern. */ -static char *circles[] = { - "....xxxx........", - "..xxxxxxxx......", - ".xxxxxxxxxx.....", - ".xxx....xxx.....", - "xxx......xxx....", - "xxx......xxx....", - "xxx......xxx....", - "xxx......xxx....", - ".xxx....xxx.....", - ".xxxxxxxxxx.....", - "..xxxxxxxx......", - "....xxxx........", - "................", - "................", - "................", - "................", -}; - -static void -makeFloorTexture(void) -{ - GLubyte floorTexture[16][16][3]; - GLubyte *loc; - int s, t; - - /* Setup RGB image for the texture. */ - loc = (GLubyte*) floorTexture; - for (t = 0; t < 16; t++) { - for (s = 0; s < 16; s++) { - if (circles[t][s] == 'x') { - /* Nice green. */ - loc[0] = 0x1f; - loc[1] = 0x8f; - loc[2] = 0x1f; - } else { - /* Light gray. */ - loc[0] = 0xaa; - loc[1] = 0xaa; - loc[2] = 0xaa; - } - loc += 3; - } - } - - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - if (useMipmaps) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, - GL_LINEAR_MIPMAP_LINEAR); - gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 16, 16, - GL_RGB, GL_UNSIGNED_BYTE, floorTexture); - } else { - if (linearFiltering) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - } else { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - } - glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0, - GL_RGB, GL_UNSIGNED_BYTE, floorTexture); - } -} - -enum { - X, Y, Z, W -}; -enum { - A, B, C, D -}; - -/* Create a matrix that will project the desired shadow. */ -void -shadowMatrix(GLfloat shadowMat[4][4], - GLfloat groundplane[4], - GLfloat lightpos[4]) -{ - GLfloat dot; - - /* Find dot product between light position vector and ground plane normal. */ - dot = groundplane[X] * lightpos[X] + - groundplane[Y] * lightpos[Y] + - groundplane[Z] * lightpos[Z] + - groundplane[W] * lightpos[W]; - - shadowMat[0][0] = dot - lightpos[X] * groundplane[X]; - shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y]; - shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z]; - shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W]; - - shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X]; - shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y]; - shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z]; - shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W]; - - shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X]; - shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y]; - shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z]; - shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W]; - - shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X]; - shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y]; - shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z]; - shadowMat[3][3] = dot - lightpos[W] * groundplane[W]; - -} - -/* Find the plane equation given 3 points. */ -void -findPlane(GLfloat plane[4], - GLfloat v0[3], GLfloat v1[3], GLfloat v2[3]) -{ - GLfloat vec0[3], vec1[3]; - - /* Need 2 vectors to find cross product. */ - vec0[X] = v1[X] - v0[X]; - vec0[Y] = v1[Y] - v0[Y]; - vec0[Z] = v1[Z] - v0[Z]; - - vec1[X] = v2[X] - v0[X]; - vec1[Y] = v2[Y] - v0[Y]; - vec1[Z] = v2[Z] - v0[Z]; - - /* find cross product to get A, B, and C of plane equation */ - plane[A] = vec0[Y] * vec1[Z] - vec0[Z] * vec1[Y]; - plane[B] = -(vec0[X] * vec1[Z] - vec0[Z] * vec1[X]); - plane[C] = vec0[X] * vec1[Y] - vec0[Y] * vec1[X]; - - plane[D] = -(plane[A] * v0[X] + plane[B] * v0[Y] + plane[C] * v0[Z]); -} - -void -extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize, - GLdouble thickness, GLuint side, GLuint edge, GLuint whole) -{ - static GLUtriangulatorObj *tobj = NULL; - GLdouble vertex[3], dx, dy, len; - int i; - int count = (int) (dataSize / (2 * sizeof(GLfloat))); - - if (tobj == NULL) { - tobj = gluNewTess(); /* create and initialize a GLU - polygon tesselation object */ - gluTessCallback(tobj, GLU_BEGIN, glBegin); - gluTessCallback(tobj, GLU_VERTEX, glVertex2fv); /* semi-tricky */ - gluTessCallback(tobj, GLU_END, glEnd); - } - glNewList(side, GL_COMPILE); - glShadeModel(GL_SMOOTH); /* smooth minimizes seeing - tessellation */ - gluBeginPolygon(tobj); - for (i = 0; i < count; i++) { - vertex[0] = data[i][0]; - vertex[1] = data[i][1]; - vertex[2] = 0; - gluTessVertex(tobj, vertex, data[i]); - } - gluEndPolygon(tobj); - glEndList(); - glNewList(edge, GL_COMPILE); - glShadeModel(GL_FLAT); /* flat shade keeps angular hands - from being "smoothed" */ - glBegin(GL_QUAD_STRIP); - for (i = 0; i <= count; i++) { -#if 1 /* weird, but seems to be legal */ - /* mod function handles closing the edge */ - glVertex3f(data[i % count][0], data[i % count][1], 0.0); - glVertex3f(data[i % count][0], data[i % count][1], thickness); - /* Calculate a unit normal by dividing by Euclidean - distance. We * could be lazy and use - glEnable(GL_NORMALIZE) so we could pass in * arbitrary - normals for a very slight performance hit. */ - dx = data[(i + 1) % count][1] - data[i % count][1]; - dy = data[i % count][0] - data[(i + 1) % count][0]; - len = sqrt(dx * dx + dy * dy); - glNormal3f(dx / len, dy / len, 0.0); -#else /* the nice way of doing it */ - /* Calculate a unit normal by dividing by Euclidean - distance. We * could be lazy and use - glEnable(GL_NORMALIZE) so we could pass in * arbitrary - normals for a very slight performance hit. */ - dx = data[i % count][1] - data[(i - 1 + count) % count][1]; - dy = data[(i - 1 + count) % count][0] - data[i % count][0]; - len = sqrt(dx * dx + dy * dy); - glNormal3f(dx / len, dy / len, 0.0); - /* mod function handles closing the edge */ - glVertex3f(data[i % count][0], data[i % count][1], 0.0); - glVertex3f(data[i % count][0], data[i % count][1], thickness); -#endif - } - glEnd(); - glEndList(); - glNewList(whole, GL_COMPILE); - glFrontFace(GL_CW); - glCallList(edge); - glNormal3f(0.0, 0.0, -1.0); /* constant normal for side */ - glCallList(side); - glPushMatrix(); - glTranslatef(0.0, 0.0, thickness); - glFrontFace(GL_CCW); - glNormal3f(0.0, 0.0, 1.0); /* opposite normal for other side */ - glCallList(side); - glPopMatrix(); - glEndList(); -} - -/* Enumerants for refering to display lists. */ -typedef enum { - RESERVED, BODY_SIDE, BODY_EDGE, BODY_WHOLE, ARM_SIDE, ARM_EDGE, ARM_WHOLE, - LEG_SIDE, LEG_EDGE, LEG_WHOLE, EYE_SIDE, EYE_EDGE, EYE_WHOLE -} displayLists; - -static void -makeDinosaur(void) -{ - extrudeSolidFromPolygon(body, sizeof(body), bodyWidth, - BODY_SIDE, BODY_EDGE, BODY_WHOLE); - extrudeSolidFromPolygon(arm, sizeof(arm), bodyWidth / 4, - ARM_SIDE, ARM_EDGE, ARM_WHOLE); - extrudeSolidFromPolygon(leg, sizeof(leg), bodyWidth / 2, - LEG_SIDE, LEG_EDGE, LEG_WHOLE); - extrudeSolidFromPolygon(eye, sizeof(eye), bodyWidth + 0.2, - EYE_SIDE, EYE_EDGE, EYE_WHOLE); -} - -static void -drawDinosaur(void) - -{ - glPushMatrix(); - /* Translate the dinosaur to be at (0,8,0). */ - glTranslatef(-8, 0, -bodyWidth / 2); - glTranslatef(0.0, jump, 0.0); - glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor); - glCallList(BODY_WHOLE); - glTranslatef(0.0, 0.0, bodyWidth); - glCallList(ARM_WHOLE); - glCallList(LEG_WHOLE); - glTranslatef(0.0, 0.0, -bodyWidth - bodyWidth / 4); - glCallList(ARM_WHOLE); - glTranslatef(0.0, 0.0, -bodyWidth / 4); - glCallList(LEG_WHOLE); - glTranslatef(0.0, 0.0, bodyWidth / 2 - 0.1); - glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor); - glCallList(EYE_WHOLE); - glPopMatrix(); -} - -static GLfloat floorVertices[4][3] = { - { -20.0, 0.0, 20.0 }, - { 20.0, 0.0, 20.0 }, - { 20.0, 0.0, -20.0 }, - { -20.0, 0.0, -20.0 }, -}; - -/* Draw a floor (possibly textured). */ -static void -drawFloor(void) -{ - glDisable(GL_LIGHTING); - - if (useTexture) { - glEnable(GL_TEXTURE_2D); - } - - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex3fv(floorVertices[0]); - glTexCoord2f(0.0, 16.0); - glVertex3fv(floorVertices[1]); - glTexCoord2f(16.0, 16.0); - glVertex3fv(floorVertices[2]); - glTexCoord2f(16.0, 0.0); - glVertex3fv(floorVertices[3]); - glEnd(); - - if (useTexture) { - glDisable(GL_TEXTURE_2D); - } - - glEnable(GL_LIGHTING); -} - -static GLfloat floorPlane[4]; -static GLfloat floorShadow[4][4]; - -static void -redraw(void) -{ - int start, end; - - if (reportSpeed) { - start = glutGet(GLUT_ELAPSED_TIME); - } - - /* Clear; default stencil clears to zero. */ - if ((stencilReflection && renderReflection) || (stencilShadow && renderShadow)) { - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - } else { - /* Avoid clearing stencil when not using it. */ - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - } - - /* Reposition the light source. */ - lightPosition[0] = 12*cos(lightAngle); - lightPosition[1] = lightHeight; - lightPosition[2] = 12*sin(lightAngle); - if (directionalLight) { - lightPosition[3] = 0.0; - } else { - lightPosition[3] = 1.0; - } - - shadowMatrix(floorShadow, floorPlane, lightPosition); - - glPushMatrix(); - /* Perform scene rotations based on user mouse input. */ - glRotatef(angle2, 1.0, 0.0, 0.0); - glRotatef(angle, 0.0, 1.0, 0.0); - - /* Tell GL new light source position. */ - glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - - if (renderReflection) { - if (stencilReflection) { - /* We can eliminate the visual "artifact" of seeing the "flipped" - dinosaur underneath the floor by using stencil. The idea is - draw the floor without color or depth update but so that - a stencil value of one is where the floor will be. Later when - rendering the dinosaur reflection, we will only update pixels - with a stencil value of 1 to make sure the reflection only - lives on the floor, not below the floor. */ - - /* Don't update color or depth. */ - glDisable(GL_DEPTH_TEST); - glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); - - /* Draw 1 into the stencil buffer. */ - glEnable(GL_STENCIL_TEST); - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - glStencilFunc(GL_ALWAYS, 1, 0xffffffff); - - /* Now render floor; floor pixels just get their stencil set to 1. */ - drawFloor(); - - /* Re-enable update of color and depth. */ - glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); - glEnable(GL_DEPTH_TEST); - - /* Now, only render where stencil is set to 1. */ - glStencilFunc(GL_EQUAL, 1, 0xffffffff); /* draw if ==1 */ - glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); - } - - glPushMatrix(); - - /* The critical reflection step: Reflect dinosaur through the floor - (the Y=0 plane) to make a relection. */ - glScalef(1.0, -1.0, 1.0); - - /* Reflect the light position. */ - glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - - /* To avoid our normals getting reversed and hence botched lighting - on the reflection, turn on normalize. */ - glEnable(GL_NORMALIZE); - glCullFace(GL_FRONT); - - /* Draw the reflected dinosaur. */ - drawDinosaur(); - - /* Disable noramlize again and re-enable back face culling. */ - glDisable(GL_NORMALIZE); - glCullFace(GL_BACK); - - glPopMatrix(); - - /* Switch back to the unreflected light position. */ - glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); - - if (stencilReflection) { - glDisable(GL_STENCIL_TEST); - } - } - - /* Back face culling will get used to only draw either the top or the - bottom floor. This let's us get a floor with two distinct - appearances. The top floor surface is reflective and kind of red. - The bottom floor surface is not reflective and blue. */ - - /* Draw "bottom" of floor in blue. */ - glFrontFace(GL_CW); /* Switch face orientation. */ - glColor4f(0.1, 0.1, 0.7, 1.0); - drawFloor(); - glFrontFace(GL_CCW); - - if (renderShadow) { - if (stencilShadow) { - /* Draw the floor with stencil value 3. This helps us only - draw the shadow once per floor pixel (and only on the - floor pixels). */ - glEnable(GL_STENCIL_TEST); - glStencilFunc(GL_ALWAYS, 3, 0xffffffff); - glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); - } - } - - /* Draw "top" of floor. Use blending to blend in reflection. */ - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor4f(0.7, 0.0, 0.0, 0.3); - glColor4f(1.0, 1.0, 1.0, 0.3); - drawFloor(); - glDisable(GL_BLEND); - - if (renderDinosaur) { - /* Draw "actual" dinosaur, not its reflection. */ - drawDinosaur(); - } - - if (renderShadow) { - - /* Render the projected shadow. */ - - if (stencilShadow) { - - /* Now, only render where stencil is set above 2 (ie, 3 where - the top floor is). Update stencil with 2 where the shadow - gets drawn so we don't redraw (and accidently reblend) the - shadow). */ - glStencilFunc(GL_LESS, 2, 0xffffffff); /* draw if ==1 */ - glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); - } - - /* To eliminate depth buffer artifacts, we use polygon offset - to raise the depth of the projected shadow slightly so - that it does not depth buffer alias with the floor. */ - if (offsetShadow) { - switch (polygonOffsetVersion) { - case EXTENSION: -#ifdef GL_EXT_polygon_offset - glEnable(GL_POLYGON_OFFSET_EXT); - break; -#endif -#ifdef GL_VERSION_1_1 - case ONE_DOT_ONE: - glEnable(GL_POLYGON_OFFSET_FILL); - break; -#endif - case MISSING: - /* Oh well. */ - break; - } - } - - /* Render 50% black shadow color on top of whatever the - floor appareance is. */ - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glDisable(GL_LIGHTING); /* Force the 50% black. */ - glColor4f(0.0, 0.0, 0.0, 0.5); - - glPushMatrix(); - /* Project the shadow. */ - glMultMatrixf((GLfloat *) floorShadow); - drawDinosaur(); - glPopMatrix(); - - glDisable(GL_BLEND); - glEnable(GL_LIGHTING); - - if (offsetShadow) { - switch (polygonOffsetVersion) { -#ifdef GL_EXT_polygon_offset - case EXTENSION: - glDisable(GL_POLYGON_OFFSET_EXT); - break; -#endif -#ifdef GL_VERSION_1_1 - case ONE_DOT_ONE: - glDisable(GL_POLYGON_OFFSET_FILL); - break; -#endif - case MISSING: - /* Oh well. */ - break; - } - } - if (stencilShadow) { - glDisable(GL_STENCIL_TEST); - } - } - - glPushMatrix(); - glDisable(GL_LIGHTING); - glColor3f(1.0, 1.0, 0.0); - if (directionalLight) { - /* Draw an arrowhead. */ - glDisable(GL_CULL_FACE); - glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); - glRotatef(lightAngle * -180.0 / M_PI, 0, 1, 0); - glRotatef(atan(lightHeight/12) * 180.0 / M_PI, 0, 0, 1); - glBegin(GL_TRIANGLE_FAN); - glVertex3f(0, 0, 0); - glVertex3f(2, 1, 1); - glVertex3f(2, -1, 1); - glVertex3f(2, -1, -1); - glVertex3f(2, 1, -1); - glVertex3f(2, 1, 1); - glEnd(); - /* Draw a white line from light direction. */ - glColor3f(1.0, 1.0, 1.0); - glBegin(GL_LINES); - glVertex3f(0, 0, 0); - glVertex3f(5, 0, 0); - glEnd(); - glEnable(GL_CULL_FACE); - } else { - /* Draw a yellow ball at the light source. */ - glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]); - glutSolidSphere(1.0, 5, 5); - } - glEnable(GL_LIGHTING); - glPopMatrix(); - - glPopMatrix(); - - if (reportSpeed) { - glFinish(); - end = glutGet(GLUT_ELAPSED_TIME); - printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start); - } - - glutSwapBuffers(); -} - -/* ARGSUSED2 */ -static void -mouse(int button, int state, int x, int y) -{ - if (button == GLUT_LEFT_BUTTON) { - if (state == GLUT_DOWN) { - moving = 1; - startx = x; - starty = y; - } - if (state == GLUT_UP) { - moving = 0; - } - } - if (button == GLUT_MIDDLE_BUTTON) { - if (state == GLUT_DOWN) { - lightMoving = 1; - lightStartX = x; - lightStartY = y; - } - if (state == GLUT_UP) { - lightMoving = 0; - } - } -} - -/* ARGSUSED1 */ -static void -motion(int x, int y) -{ - if (moving) { - angle = angle + (x - startx); - angle2 = angle2 + (y - starty); - startx = x; - starty = y; - glutPostRedisplay(); - } - if (lightMoving) { - lightAngle += (x - lightStartX)/40.0; - lightHeight += (lightStartY - y)/20.0; - lightStartX = x; - lightStartY = y; - glutPostRedisplay(); - } -} - -/* Advance time varying state when idle callback registered. */ -static void -idle(void) -{ - static float time = 0.0; - - time = glutGet(GLUT_ELAPSED_TIME) / 500.0; - - jump = 4.0 * fabs(sin(time)*0.5); - if (!lightMoving) { - lightAngle += 0.03; - } - glutPostRedisplay(); -} - -enum { - M_NONE, M_MOTION, M_LIGHT, M_TEXTURE, M_SHADOWS, M_REFLECTION, M_DINOSAUR, - M_STENCIL_REFLECTION, M_STENCIL_SHADOW, M_OFFSET_SHADOW, - M_POSITIONAL, M_DIRECTIONAL, M_PERFORMANCE -}; - -static void -controlLights(int value) -{ - switch (value) { - case M_NONE: - return; - case M_MOTION: - animation = 1 - animation; - if (animation) { - glutIdleFunc(idle); - } else { - glutIdleFunc(NULL); - } - break; - case M_LIGHT: - lightSwitch = !lightSwitch; - if (lightSwitch) { - glEnable(GL_LIGHT0); - } else { - glDisable(GL_LIGHT0); - } - break; - case M_TEXTURE: - useTexture = !useTexture; - break; - case M_SHADOWS: - renderShadow = 1 - renderShadow; - break; - case M_REFLECTION: - renderReflection = 1 - renderReflection; - break; - case M_DINOSAUR: - renderDinosaur = 1 - renderDinosaur; - break; - case M_STENCIL_REFLECTION: - stencilReflection = 1 - stencilReflection; - break; - case M_STENCIL_SHADOW: - stencilShadow = 1 - stencilShadow; - break; - case M_OFFSET_SHADOW: - offsetShadow = 1 - offsetShadow; - break; - case M_POSITIONAL: - directionalLight = 0; - break; - case M_DIRECTIONAL: - directionalLight = 1; - break; - case M_PERFORMANCE: - reportSpeed = 1 - reportSpeed; - break; - } - glutPostRedisplay(); -} - -/* When not visible, stop animating. Restart when visible again. */ -static void -visible(int vis) -{ - if (vis == GLUT_VISIBLE) { - if (animation) - glutIdleFunc(idle); - } else { - if (!animation) - glutIdleFunc(NULL); - } -} - -/* Press any key to redraw; good when motion stopped and - performance reporting on. */ -/* ARGSUSED */ -static void -key(unsigned char c, int x, int y) -{ - if (c == 27) { - exit(0); /* IRIS GLism, Escape quits. */ - } - glutPostRedisplay(); -} - -/* Press any key to redraw; good when motion stopped and - performance reporting on. */ -/* ARGSUSED */ -static void -special(int k, int x, int y) -{ - glutPostRedisplay(); -} - -static int -supportsOneDotOne(void) -{ - const char *version; - int major, minor; - - version = (char *) glGetString(GL_VERSION); - if (sscanf(version, "%d.%d", &major, &minor) == 2) - return major * 10 + minor >= 11; - return 0; /* OpenGL version string malformed! */ -} - -int -main(int argc, char **argv) -{ - int i; - - glutInit(&argc, argv); - - for (i=1; i=2 rgb double depth"); -#endif - - glutCreateWindow("Shadowy Leapin' Lizards"); - glewInit(); - - if (glutGet(GLUT_WINDOW_STENCIL_SIZE) <= 1) { - printf("dinoshade: Sorry, I need at least 2 bits of stencil.\n"); - exit(1); - } - - /* Register GLUT callbacks. */ - glutDisplayFunc(redraw); - glutMouseFunc(mouse); - glutMotionFunc(motion); - glutVisibilityFunc(visible); - glutKeyboardFunc(key); - glutSpecialFunc(special); - - glutCreateMenu(controlLights); - - glutAddMenuEntry("Toggle motion", M_MOTION); - glutAddMenuEntry("-----------------------", M_NONE); - glutAddMenuEntry("Toggle light", M_LIGHT); - glutAddMenuEntry("Toggle texture", M_TEXTURE); - glutAddMenuEntry("Toggle shadows", M_SHADOWS); - glutAddMenuEntry("Toggle reflection", M_REFLECTION); - glutAddMenuEntry("Toggle dinosaur", M_DINOSAUR); - glutAddMenuEntry("-----------------------", M_NONE); - glutAddMenuEntry("Toggle reflection stenciling", M_STENCIL_REFLECTION); - glutAddMenuEntry("Toggle shadow stenciling", M_STENCIL_SHADOW); - glutAddMenuEntry("Toggle shadow offset", M_OFFSET_SHADOW); - glutAddMenuEntry("----------------------", M_NONE); - glutAddMenuEntry("Positional light", M_POSITIONAL); - glutAddMenuEntry("Directional light", M_DIRECTIONAL); - glutAddMenuEntry("-----------------------", M_NONE); - glutAddMenuEntry("Toggle performance", M_PERFORMANCE); - glutAttachMenu(GLUT_RIGHT_BUTTON); - makeDinosaur(); - -#ifdef GL_VERSION_1_1 - if (supportsOneDotOne() && !forceExtension) { - polygonOffsetVersion = ONE_DOT_ONE; - glPolygonOffset(-2.0, -9.0); - } else -#endif - { -#ifdef GL_EXT_polygon_offset - /* check for the polygon offset extension */ - if (glutExtensionSupported("GL_EXT_polygon_offset")) { - polygonOffsetVersion = EXTENSION; - glPolygonOffsetEXT(-2.0, -0.002); - } else -#endif - { - polygonOffsetVersion = MISSING; - printf("\ndinoshine: Missing polygon offset.\n"); - printf(" Expect shadow depth aliasing artifacts.\n\n"); - } - } - - glEnable(GL_CULL_FACE); - glEnable(GL_DEPTH_TEST); - glEnable(GL_TEXTURE_2D); - glLineWidth(3.0); - - glMatrixMode(GL_PROJECTION); - gluPerspective( /* field of view in degree */ 40.0, - /* aspect ratio */ 1.0, - /* Z near */ 20.0, /* Z far */ 100.0); - glMatrixMode(GL_MODELVIEW); - gluLookAt(0.0, 8.0, 60.0, /* eye is at (0,8,60) */ - 0.0, 8.0, 0.0, /* center is at (0,8,0) */ - 0.0, 1.0, 0.); /* up is in postivie Y direction */ - - glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); - glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor); - glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1); - glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05); - glEnable(GL_LIGHT0); - glEnable(GL_LIGHTING); - - makeFloorTexture(); - - /* Setup floor plane for projected shadow calculations. */ - findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]); - - glutMainLoop(); - return 0; /* ANSI C requires main to return int. */ -} -- cgit v1.2.3 From 30e80f6e559727dd157fbca4e7e537710e9ea199 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 13:10:51 -0600 Subject: demos: move demos/occlude.c (old HP extension) to tests --- progs/demos/occlude.c | 234 -------------------------------------------------- progs/tests/occlude.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 234 insertions(+), 234 deletions(-) delete mode 100644 progs/demos/occlude.c create mode 100644 progs/tests/occlude.c (limited to 'progs') diff --git a/progs/demos/occlude.c b/progs/demos/occlude.c deleted file mode 100644 index 8f7b90984e..0000000000 --- a/progs/demos/occlude.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * GL_HP_occlustion_test demo - * - * Brian Paul - * 31 March 2000 - * - * Copyright (C) 2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -#include -#include -#include -#include -#include -#include - - -static GLfloat Xpos = 0; -static GLboolean Anim = GL_TRUE; - - -static void -PrintString(const char *s) -{ - while (*s) { - glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); - s++; - } -} - - - -static void Idle(void) -{ - static int lastTime = 0; - static int sign = +1; - int time = glutGet(GLUT_ELAPSED_TIME); - float step; - - if (lastTime == 0) - lastTime = time; - else if (time - lastTime < 20) /* 50Hz update */ - return; - - step = (time - lastTime) / 1000.0 * sign; - lastTime = time; - - Xpos += step; - - if (Xpos > 2.5) { - Xpos = 2.5; - sign = -1; - } - else if (Xpos < -2.5) { - Xpos = -2.5; - sign = +1; - } - glutPostRedisplay(); -} - - -static void Display( void ) -{ - GLboolean result; - - glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); - - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - glTranslatef( 0.0, 0.0, -15.0 ); - - /* draw the occluding polygons */ - glColor3f(0, 0.6, 0.8); - glBegin(GL_QUADS); - glVertex2f(-1.6, -1.5); - glVertex2f(-0.4, -1.5); - glVertex2f(-0.4, 1.5); - glVertex2f(-1.6, 1.5); - - glVertex2f( 0.4, -1.5); - glVertex2f( 1.6, -1.5); - glVertex2f( 1.6, 1.5); - glVertex2f( 0.4, 1.5); - glEnd(); - - /* draw the test polygon with occlusion testing */ - glPushMatrix(); - glTranslatef(Xpos, 0, -0.5); - glScalef(0.3, 0.3, 1.0); - glRotatef(-90.0 * Xpos, 0, 0, 1); - - glEnable(GL_OCCLUSION_TEST_HP); /* NOTE: enabling the occlusion test */ - /* doesn't clear the result flag! */ - glColorMask(0, 0, 0, 0); - glDepthMask(GL_FALSE); - /* this call clear's the result flag. Not really needed for this demo. */ - glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP, &result); - - glBegin(GL_POLYGON); - glVertex3f(-1, -1, 0); - glVertex3f( 1, -1, 0); - glVertex3f( 1, 1, 0); - glVertex3f(-1, 1, 0); - glEnd(); - - glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP, &result); - /* turn off occlusion testing */ - glDisable(GL_OCCLUSION_TEST_HP); - glColorMask(1, 1, 1, 1); - glDepthMask(GL_TRUE); - - /* draw the green rect, so we can see what's going on */ - glColor3f(0.8, 0.5, 0); - glBegin(GL_POLYGON); - glVertex3f(-1, -1, 0); - glVertex3f( 1, -1, 0); - glVertex3f( 1, 1, 0); - glVertex3f(-1, 1, 0); - glEnd(); - - glPopMatrix(); - - - /* Print result message */ - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - - glColor3f(1, 1, 1); - glRasterPos3f(-0.25, -0.7, 0); - - if (result) - PrintString(" Visible"); - else - PrintString("Fully Occluded"); - - glutSwapBuffers(); -} - - -static void Reshape( int width, int height ) -{ - glViewport( 0, 0, width, height ); -} - - -static void Key( unsigned char key, int x, int y ) -{ - (void) x; - (void) y; - switch (key) { - case 'a': - Anim = !Anim; - if (Anim) - glutIdleFunc( Idle ); - else - glutIdleFunc( NULL ); - break; - case 27: - exit(0); - break; - } - glutPostRedisplay(); -} - - -static void SpecialKey( int key, int x, int y ) -{ - const GLfloat step = 0.1; - (void) x; - (void) y; - switch (key) { - case GLUT_KEY_LEFT: - Xpos -= step; - break; - case GLUT_KEY_RIGHT: - Xpos += step; - break; - } - glutPostRedisplay(); -} - - -static void Init( void ) -{ - const char *ext = (const char *) glGetString(GL_EXTENSIONS); - if (!strstr(ext, "GL_HP_occlusion_test")) { - printf("Sorry, this demo requires the GL_HP_occlusion_test extension\n"); - exit(-1); - } - - glEnable(GL_DEPTH_TEST); -} - - -int main( int argc, char *argv[] ) -{ - glutInit( &argc, argv ); - glutInitWindowPosition( 0, 0 ); - glutInitWindowSize( 400, 400 ); - glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); - glutCreateWindow(argv[0]); - glutReshapeFunc( Reshape ); - glutKeyboardFunc( Key ); - glutSpecialFunc( SpecialKey ); - glutIdleFunc( Idle ); - glutDisplayFunc( Display ); - Init(); - glutMainLoop(); - return 0; -} diff --git a/progs/tests/occlude.c b/progs/tests/occlude.c new file mode 100644 index 0000000000..8f7b90984e --- /dev/null +++ b/progs/tests/occlude.c @@ -0,0 +1,234 @@ +/* + * GL_HP_occlustion_test demo + * + * Brian Paul + * 31 March 2000 + * + * Copyright (C) 2000 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + + +#include +#include +#include +#include +#include +#include + + +static GLfloat Xpos = 0; +static GLboolean Anim = GL_TRUE; + + +static void +PrintString(const char *s) +{ + while (*s) { + glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s); + s++; + } +} + + + +static void Idle(void) +{ + static int lastTime = 0; + static int sign = +1; + int time = glutGet(GLUT_ELAPSED_TIME); + float step; + + if (lastTime == 0) + lastTime = time; + else if (time - lastTime < 20) /* 50Hz update */ + return; + + step = (time - lastTime) / 1000.0 * sign; + lastTime = time; + + Xpos += step; + + if (Xpos > 2.5) { + Xpos = 2.5; + sign = -1; + } + else if (Xpos < -2.5) { + Xpos = -2.5; + sign = +1; + } + glutPostRedisplay(); +} + + +static void Display( void ) +{ + GLboolean result; + + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); + + /* draw the occluding polygons */ + glColor3f(0, 0.6, 0.8); + glBegin(GL_QUADS); + glVertex2f(-1.6, -1.5); + glVertex2f(-0.4, -1.5); + glVertex2f(-0.4, 1.5); + glVertex2f(-1.6, 1.5); + + glVertex2f( 0.4, -1.5); + glVertex2f( 1.6, -1.5); + glVertex2f( 1.6, 1.5); + glVertex2f( 0.4, 1.5); + glEnd(); + + /* draw the test polygon with occlusion testing */ + glPushMatrix(); + glTranslatef(Xpos, 0, -0.5); + glScalef(0.3, 0.3, 1.0); + glRotatef(-90.0 * Xpos, 0, 0, 1); + + glEnable(GL_OCCLUSION_TEST_HP); /* NOTE: enabling the occlusion test */ + /* doesn't clear the result flag! */ + glColorMask(0, 0, 0, 0); + glDepthMask(GL_FALSE); + /* this call clear's the result flag. Not really needed for this demo. */ + glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP, &result); + + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glGetBooleanv(GL_OCCLUSION_TEST_RESULT_HP, &result); + /* turn off occlusion testing */ + glDisable(GL_OCCLUSION_TEST_HP); + glColorMask(1, 1, 1, 1); + glDepthMask(GL_TRUE); + + /* draw the green rect, so we can see what's going on */ + glColor3f(0.8, 0.5, 0); + glBegin(GL_POLYGON); + glVertex3f(-1, -1, 0); + glVertex3f( 1, -1, 0); + glVertex3f( 1, 1, 0); + glVertex3f(-1, 1, 0); + glEnd(); + + glPopMatrix(); + + + /* Print result message */ + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( -1.0, 1.0, -1.0, 1.0, -1.0, 1.0 ); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + + glColor3f(1, 1, 1); + glRasterPos3f(-0.25, -0.7, 0); + + if (result) + PrintString(" Visible"); + else + PrintString("Fully Occluded"); + + glutSwapBuffers(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 'a': + Anim = !Anim; + if (Anim) + glutIdleFunc( Idle ); + else + glutIdleFunc( NULL ); + break; + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void SpecialKey( int key, int x, int y ) +{ + const GLfloat step = 0.1; + (void) x; + (void) y; + switch (key) { + case GLUT_KEY_LEFT: + Xpos -= step; + break; + case GLUT_KEY_RIGHT: + Xpos += step; + break; + } + glutPostRedisplay(); +} + + +static void Init( void ) +{ + const char *ext = (const char *) glGetString(GL_EXTENSIONS); + if (!strstr(ext, "GL_HP_occlusion_test")) { + printf("Sorry, this demo requires the GL_HP_occlusion_test extension\n"); + exit(-1); + } + + glEnable(GL_DEPTH_TEST); +} + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 400, 400 ); + glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutSpecialFunc( SpecialKey ); + glutIdleFunc( Idle ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From d61070b65970c9ec14b3272a6c4c6b4b1a9280a2 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 13:12:50 -0600 Subject: demos: move demos/texobj.c to tests/ --- progs/demos/Makefile | 1 - progs/demos/texobj.c | 284 --------------------------------------------------- progs/tests/Makefile | 1 + progs/tests/texobj.c | 284 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 285 insertions(+), 285 deletions(-) delete mode 100644 progs/demos/texobj.c create mode 100644 progs/tests/texobj.c (limited to 'progs') diff --git a/progs/demos/Makefile b/progs/demos/Makefile index 8febc14d41..c17595ec79 100644 --- a/progs/demos/Makefile +++ b/progs/demos/Makefile @@ -58,7 +58,6 @@ PROGS = \ tessdemo \ texcyl \ texenv \ - texobj \ textures \ trispd \ tunnel \ diff --git a/progs/demos/texobj.c b/progs/demos/texobj.c deleted file mode 100644 index 40bce6e569..0000000000 --- a/progs/demos/texobj.c +++ /dev/null @@ -1,284 +0,0 @@ - -/* - * Example of using the 1.1 texture object functions. - * Also, this demo utilizes Mesa's fast texture map path. - * - * Brian Paul June 1996 This file is in the public domain. - */ - -#include -#include -#include -#include -#include -#include "GL/glut.h" - -static GLuint Window = 0; - -static GLuint TexObj[2]; -static GLfloat Angle = 0.0f; -static GLboolean UseObj = GL_FALSE; - - -#if defined(GL_VERSION_1_1) || defined(GL_VERSION_1_2) -# define TEXTURE_OBJECT 1 -#elif defined(GL_EXT_texture_object) -# define TEXTURE_OBJECT 1 -# define glBindTexture(A,B) glBindTextureEXT(A,B) -# define glGenTextures(A,B) glGenTexturesEXT(A,B) -# define glDeleteTextures(A,B) glDeleteTexturesEXT(A,B) -#endif - - - - -static void draw( void ) -{ - glClear( GL_COLOR_BUFFER_BIT ); - - glColor3f( 1.0, 1.0, 1.0 ); - - /* draw first polygon */ - glPushMatrix(); - glTranslatef( -1.0, 0.0, 0.0 ); - glRotatef( Angle, 0.0, 0.0, 1.0 ); - if (UseObj) { -#ifdef TEXTURE_OBJECT - glBindTexture( GL_TEXTURE_2D, TexObj[0] ); -#endif - } - else { - glCallList( TexObj[0] ); - } - glBegin( GL_POLYGON ); - glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 ); - glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 ); - glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 ); - glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 ); - glEnd(); - glPopMatrix(); - - /* draw second polygon */ - glPushMatrix(); - glTranslatef( 1.0, 0.0, 0.0 ); - glRotatef( Angle-90.0, 0.0, 1.0, 0.0 ); - if (UseObj) { -#ifdef TEXTURE_OBJECT - glBindTexture( GL_TEXTURE_2D, TexObj[1] ); -#endif - } - else { - glCallList( TexObj[1] ); - } - glBegin( GL_POLYGON ); - glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 ); - glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 ); - glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 ); - glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 ); - glEnd(); - glPopMatrix(); - - glutSwapBuffers(); -} - - - -static void idle( void ) -{ - static double t0 = -1.; - double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; - if (t0 < 0.0) - t0 = t; - dt = t - t0; - t0 = t; - Angle += 120.0*dt; - glutPostRedisplay(); -} - - - -/* change view Angle, exit upon ESC */ -static void key(unsigned char k, int x, int y) -{ - (void) x; - (void) y; - switch (k) { - case 27: -#ifdef TEXTURE_OBJECT - glDeleteTextures( 2, TexObj ); -#endif - glutDestroyWindow(Window); - exit(0); - } -} - - - -/* new window size or exposure */ -static void reshape( int width, int height ) -{ - glViewport(0, 0, (GLint)width, (GLint)height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - /* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/ - glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 ); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslatef( 0.0, 0.0, -8.0 ); -} - - -static void init( void ) -{ - static int width=8, height=8; - static GLubyte tex1[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 1, 1, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 }; - - static GLubyte tex2[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 2, 2, 0, 0, 0, - 0, 0, 2, 0, 0, 2, 0, 0, - 0, 0, 0, 0, 0, 2, 0, 0, - 0, 0, 0, 0, 2, 0, 0, 0, - 0, 0, 0, 2, 0, 0, 0, 0, - 0, 0, 2, 2, 2, 2, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0 }; - - GLubyte tex[64][3]; - GLint i, j; - - - glDisable( GL_DITHER ); - - /* Setup texturing */ - glEnable( GL_TEXTURE_2D ); - glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); - glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST ); - - - /* generate texture object IDs */ - if (UseObj) { -#ifdef TEXTURE_OBJECT - glGenTextures( 2, TexObj ); -#endif - } - else { - TexObj[0] = glGenLists(2); - TexObj[1] = TexObj[0]+1; - } - - /* setup first texture object */ - if (UseObj) { -#ifdef TEXTURE_OBJECT - glBindTexture( GL_TEXTURE_2D, TexObj[0] ); - assert(glIsTexture(TexObj[0])); -#endif - } - else { - glNewList( TexObj[0], GL_COMPILE ); - } - /* red on white */ - for (i=0;i +#include +#include +#include +#include +#include "GL/glut.h" + +static GLuint Window = 0; + +static GLuint TexObj[2]; +static GLfloat Angle = 0.0f; +static GLboolean UseObj = GL_FALSE; + + +#if defined(GL_VERSION_1_1) || defined(GL_VERSION_1_2) +# define TEXTURE_OBJECT 1 +#elif defined(GL_EXT_texture_object) +# define TEXTURE_OBJECT 1 +# define glBindTexture(A,B) glBindTextureEXT(A,B) +# define glGenTextures(A,B) glGenTexturesEXT(A,B) +# define glDeleteTextures(A,B) glDeleteTexturesEXT(A,B) +#endif + + + + +static void draw( void ) +{ + glClear( GL_COLOR_BUFFER_BIT ); + + glColor3f( 1.0, 1.0, 1.0 ); + + /* draw first polygon */ + glPushMatrix(); + glTranslatef( -1.0, 0.0, 0.0 ); + glRotatef( Angle, 0.0, 0.0, 1.0 ); + if (UseObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[0] ); +#endif + } + else { + glCallList( TexObj[0] ); + } + glBegin( GL_POLYGON ); + glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 ); + glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 ); + glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 ); + glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 ); + glEnd(); + glPopMatrix(); + + /* draw second polygon */ + glPushMatrix(); + glTranslatef( 1.0, 0.0, 0.0 ); + glRotatef( Angle-90.0, 0.0, 1.0, 0.0 ); + if (UseObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[1] ); +#endif + } + else { + glCallList( TexObj[1] ); + } + glBegin( GL_POLYGON ); + glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 ); + glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 ); + glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 ); + glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 ); + glEnd(); + glPopMatrix(); + + glutSwapBuffers(); +} + + + +static void idle( void ) +{ + static double t0 = -1.; + double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0; + if (t0 < 0.0) + t0 = t; + dt = t - t0; + t0 = t; + Angle += 120.0*dt; + glutPostRedisplay(); +} + + + +/* change view Angle, exit upon ESC */ +static void key(unsigned char k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case 27: +#ifdef TEXTURE_OBJECT + glDeleteTextures( 2, TexObj ); +#endif + glutDestroyWindow(Window); + exit(0); + } +} + + + +/* new window size or exposure */ +static void reshape( int width, int height ) +{ + glViewport(0, 0, (GLint)width, (GLint)height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + /* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/ + glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 ); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -8.0 ); +} + + +static void init( void ) +{ + static int width=8, height=8; + static GLubyte tex1[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; + + static GLubyte tex2[] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 2, 2, 0, 0, 0, + 0, 0, 2, 0, 0, 2, 0, 0, + 0, 0, 0, 0, 0, 2, 0, 0, + 0, 0, 0, 0, 2, 0, 0, 0, + 0, 0, 0, 2, 0, 0, 0, 0, + 0, 0, 2, 2, 2, 2, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 }; + + GLubyte tex[64][3]; + GLint i, j; + + + glDisable( GL_DITHER ); + + /* Setup texturing */ + glEnable( GL_TEXTURE_2D ); + glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL ); + glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST ); + + + /* generate texture object IDs */ + if (UseObj) { +#ifdef TEXTURE_OBJECT + glGenTextures( 2, TexObj ); +#endif + } + else { + TexObj[0] = glGenLists(2); + TexObj[1] = TexObj[0]+1; + } + + /* setup first texture object */ + if (UseObj) { +#ifdef TEXTURE_OBJECT + glBindTexture( GL_TEXTURE_2D, TexObj[0] ); + assert(glIsTexture(TexObj[0])); +#endif + } + else { + glNewList( TexObj[0], GL_COMPILE ); + } + /* red on white */ + for (i=0;i Date: Sat, 18 Apr 2009 13:18:44 -0600 Subject: demos: updated .gitignore list --- progs/demos/.gitignore | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'progs') diff --git a/progs/demos/.gitignore b/progs/demos/.gitignore index d59d175212..c6ff227391 100644 --- a/progs/demos/.gitignore +++ b/progs/demos/.gitignore @@ -5,10 +5,12 @@ bounce clearspd copypix cubemap +dinoshade drawpix engine extfuncs.h fbo_firecube +fbotexture fire fogcoord fplight @@ -19,7 +21,6 @@ gears geartrain glinfo gloss -glslnoise gltestperf glutfx ipers @@ -27,11 +28,9 @@ isosurf lodbias morph3d multiarb -occlude -osdemo paltex -pixeltex pointblast +projtex rain ray readpix @@ -46,14 +45,12 @@ singlebuffer spectex spriteblast stex3d -streaming_rect teapot terrain tessdemo texcyl texdown texenv -texobj textures trackball.c trackball.h -- cgit v1.2.3 From c0565e86b4d4375ed52b20d9464daace616b50a8 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 18 Apr 2009 14:18:59 -0600 Subject: demos: added glsl/texaaline.c program and overhaul the Makefile --- progs/glsl/Makefile | 278 +++++++++++++++++-------------------- progs/glsl/texaaline.c | 369 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 499 insertions(+), 148 deletions(-) create mode 100644 progs/glsl/texaaline.c (limited to 'progs') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 8e61ab690b..71db895d1d 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -5,48 +5,69 @@ include $(TOP)/configs/current INCDIR = $(TOP)/include -LIB_DEP = $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) +LIB_DEP = \ + $(TOP)/$(LIB_DIR)/$(GL_LIB_NAME) \ + $(TOP)/$(LIB_DIR)/$(GLU_LIB_NAME) \ + $(TOP)/$(LIB_DIR)/$(GLUT_LIB_NAME) LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) -PROGS = \ - array \ - bitmap \ - brick \ - bump \ - convolutions \ - deriv \ - identity \ - fragcoord \ - linktest \ - mandelbrot \ - multinoise \ - multitex \ - noise \ - noise2 \ - points \ - pointcoord \ - samplers \ - samplers_array \ - shadow_sampler \ - skinning \ - texdemo1 \ - toyball \ - twoside \ - trirast \ - vert-or-frag-only \ - vert-tex +INCLUDE_DIRS = -I$(TOP)/progs/util + +DEMO_SOURCES = \ + array.c \ + bitmap.c \ + brick.c \ + bump.c \ + convolutions.c \ + deriv.c \ + fragcoord.c \ + identity.c \ + linktest.c \ + mandelbrot.c \ + multinoise.c \ + multitex.c \ + noise.c \ + noise2.c \ + pointcoord.c \ + points.c \ + samplers.c \ + shadow_sampler.c \ + skinning.c \ + texaaline.c \ + texdemo1.c \ + toyball.c \ + trirast.c \ + twoside.c \ + vert-or-frag-only.c \ + vert-tex.c + +UTIL_HEADERS = \ + extfuncs.h \ + shaderutil.h \ + readtex.h + +UTIL_SOURCES = \ + shaderutil.c \ + readtex.c + +UTIL_OBJS = $(UTIL_SOURCES:.c=.o) + + +PROGS = $(DEMO_SOURCES:%.c=%) + ##### RULES ##### -.SUFFIXES: -.SUFFIXES: .c +# make .o file from .c file: +.c.o: + $(APP_CC) -c -I$(INCDIR) $(CFLAGS) $< -o $@ -# make executable from .c file: -.c: $(LIB_DEP) - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) $< $(LIBS) -o $@ +# make executable from .o files +.o: + $(APP_CC) $(INCLUDES) $(CFLAGS) $(LDFLAGS) $< $(UTIL_OBJS) $(LIBS) -o $@ ##### TARGETS ##### @@ -54,202 +75,163 @@ PROGS = \ default: $(PROGS) +clean: + -rm -f $(PROGS) + -rm -f *.o *~ + -rm -f extfuncs.h + -rm -f shaderutil.* + + ##### Extra dependencies -extfuncs.h: $(TOP)/progs/util/extfuncs.h - cp $< . +extfuncs.h: + cp $(TOP)/progs/util/extfuncs.h . +readtex.c: + cp $(TOP)/progs/util/readtex.c . -readtex.c: $(TOP)/progs/util/readtex.c - cp $< . +readtex.h: + cp $(TOP)/progs/util/readtex.h . -readtex.h: $(TOP)/progs/util/readtex.h - cp $< . +shaderutil.c: + cp $(TOP)/progs/util/shaderutil.c . -readtex.o: readtex.c readtex.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) readtex.c +shaderutil.h: + cp $(TOP)/progs/util/shaderutil.h . -shaderutil.c: $(TOP)/progs/util/shaderutil.c - cp $< . -shaderutil.h: $(TOP)/progs/util/shaderutil.h - cp $< . +array.o: $(UTIL_HEADERS) -shaderutil.o: shaderutil.c shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) shaderutil.c +array: array.o $(UTIL_OBJS) +bitmap.o: $(UTIL_HEADERS) -array.o: array.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) array.c +bitmap: bitmap.o $(UTIL_OBJS) -array: array.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) array.o shaderutil.o $(LIBS) -o $@ +brick.o: $(UTIL_HEADERS) -bitmap.o: bitmap.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bitmap.c +brick: brick.o $(UTIL_OBJS) -bitmap: bitmap.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bitmap.o shaderutil.o $(LIBS) -o $@ +bump.o: $(UTIL_HEADERS) -brick.o: brick.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) brick.c +bump: bump.o $(UTIL_OBJS) -brick: brick.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) brick.o shaderutil.o $(LIBS) -o $@ +convolutions.o: $(UTIL_HEADERS) -bump.o: bump.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) bump.c +convolutions: convolutions.o $(UTIL_OBJS) -bump: bump.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) bump.o shaderutil.o $(LIBS) -o $@ +deriv.o: deriv.c $(UTIL_HEADERS) -convolutions.o: convolutions.c readtex.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) convolutions.c +deriv: deriv.o $(UTIL_OBJS) -convolutions: convolutions.o readtex.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) convolutions.o readtex.o $(LIBS) -o $@ +identity.o: $(UTIL_HEADERS) -deriv.o: deriv.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) deriv.c +identity: identity.o $(UTIL_OBJS) -deriv: deriv.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) deriv.o shaderutil.o $(LIBS) -o $@ +fragcoord.o: $(UTIL_HEADERS) -identity.o: identity.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) identity.c +fragcoord: fragcoord.o $(UTIL_OBJS) -identity: identity.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) identity.o shaderutil.o $(LIBS) -o $@ +linktest.o: $(UTIL_HEADERS) -fragcoord.o: fragcoord.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) fragcoord.c +linktest: linktest.o $(UTIL_OBJS) -fragcoord: fragcoord.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) fragcoord.o shaderutil.o $(LIBS) -o $@ +mandelbrot.o: $(UTIL_HEADERS) -linktest.o: linktest.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) linktest.c +mandelbrot: mandelbrot.o $(UTIL_OBJS) -linktest: linktest.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) linktest.o shaderutil.o $(LIBS) -o $@ -mandelbrot.o: mandelbrot.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) mandelbrot.c +multinoise.o: $(UTIL_HEADERS) -mandelbrot: mandelbrot.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) mandelbrot.o shaderutil.o $(LIBS) -o $@ +multinoise: multinoise.o $(UTIL_OBJS) -multitex.o: multitex.c extfuncs.h readtex.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) multitex.c -multitex: multitex.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) multitex.o readtex.o shaderutil.o $(LIBS) -o $@ +multitex.o: $(UTIL_HEADERS) +multitex: multitex.o $(UTIL_OBJS) -noise.o: noise.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) noise.c -noise: noise.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise.o shaderutil.o $(LIBS) -o $@ +noise.o: $(UTIL_HEADERS) +noise: noise.o $(UTIL_OBJS) -noise2.o: noise2.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) noise2.c -noise2: noise2.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) noise2.o shaderutil.o $(LIBS) -o $@ +noise2.o: $(UTIL_HEADERS) +noise2: noise2.o $(UTIL_OBJS) -points.o: points.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) points.c -points: points.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) points.o shaderutil.o $(LIBS) -o $@ +points.o: $(UTIL_HEADERS) +points: points.o $(UTIL_OBJS) -pointcoord.o: pointcoord.c readtex.h extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) pointcoord.c -pointcoord: pointcoord.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) pointcoord.o readtex.o shaderutil.o $(LIBS) -o $@ +pointcoord.o: $(UTIL_HEADERS) +pointcoord: pointcoord.o $(UTIL_OBJS) -samplers.o: samplers.c readtex.h extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) samplers.c -samplers: samplers.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers.o readtex.o shaderutil.o $(LIBS) -o $@ +samplers.o: $(UTIL_HEADERS) -samplers_array.o: samplers.c readtex.h extfuncs.h shaderutil.h - $(APP_CC) -c -DSAMPLERS_ARRAY -I$(INCDIR) $(CFLAGS) samplers.c -o samplers_array.o +samplers: samplers.o $(UTIL_OBJS) -samplers_array: samplers_array.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) samplers_array.o readtex.o shaderutil.o $(LIBS) -o $@ -skinning.o: skinning.c readtex.h extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) skinning.c +samplers_array.o: $(UTIL_HEADERS) -skinning: skinning.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) skinning.o readtex.o shaderutil.o $(LIBS) -o $@ +samplers_array: samplers_array.o $(UTIL_OBJS) -texdemo1.o: texdemo1.c readtex.h extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) texdemo1.c +shadow_sampler.o: $(UTIL_HEADERS) -texdemo1: texdemo1.o readtex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) texdemo1.o readtex.o shaderutil.o $(LIBS) -o $@ +shadow_sampler: shadow_sampler.o $(UTIL_OBJS) -toyball.o: toyball.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) toyball.c +skinning.o: $(UTIL_HEADERS) -toyball: toyball.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) toyball.o shaderutil.o $(LIBS) -o $@ +skinning: skinning.o $(UTIL_OBJS) -twoside.o: twoside.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) twoside.c +texaaline.o: $(UTIL_HEADERS) -twoside: twoside.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) twoside.o shaderutil.o $(LIBS) -o $@ +texaaline: texaaline.o $(UTIL_OBJS) -trirast.o: trirast.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) trirast.c +texdemo1.o: $(UTIL_HEADERS) -trirast: trirast.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) trirast.o shaderutil.o $(LIBS) -o $@ +texdemo1: texdemo1.o $(UTIL_OBJS) -vert-or-frag-only.o: vert-or-frag-only.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-or-frag-only.c +toyball.o: $(UTIL_HEADERS) -vert-or-frag-only: vert-or-frag-only.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-or-frag-only.o shaderutil.o $(LIBS) -o $@ +toyball: toyball.o $(UTIL_OBJS) -vert-tex.o: vert-tex.c extfuncs.h shaderutil.h - $(APP_CC) -c -I$(INCDIR) $(CFLAGS) vert-tex.c +twoside.o: $(UTIL_HEADERS) -vert-tex: vert-tex.o shaderutil.o - $(APP_CC) -I$(INCDIR) $(CFLAGS) $(LDFLAGS) vert-tex.o shaderutil.o $(LIBS) -o $@ +twoside: twoside.o $(UTIL_OBJS) +trirast.o: $(UTIL_HEADERS) +trirast: trirast.o $(UTIL_OBJS) -clean: - -rm -f $(PROGS) - -rm -f *.o *~ - -rm -f extfuncs.h - -rm -f shaderutil.* + +vert-or-frag-only.o: $(UTIL_HEADERS) + +vert-or-frag-only: vert-or-frag-only.o $(UTIL_OBJS) + + +vert-tex.o: $(UTIL_HEADERS) + +vert-tex: vert-tex.o $(UTIL_OBJS) diff --git a/progs/glsl/texaaline.c b/progs/glsl/texaaline.c new file mode 100644 index 0000000000..0b3cc84958 --- /dev/null +++ b/progs/glsl/texaaline.c @@ -0,0 +1,369 @@ +/** + * AA lines with texture mapped quads + * + * Brian Paul + * 9 Feb 2008 + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include "extfuncs.h" + + +static GLint WinWidth = 300, WinHeight = 300; +static GLint win = 0; +static GLfloat Width = 8.; + +/* + * Quad strip for line from v0 to v1: + * + 1 3 5 7 + +---+---------------------+---+ + | | + | *v0 v1* | + | | + +---+---------------------+---+ + 0 2 4 6 + */ +static void +QuadLine(const GLfloat *v0, const GLfloat *v1, GLfloat width) +{ + GLfloat dx = v1[0] - v0[0]; + GLfloat dy = v1[1] - v0[1]; + GLfloat len = sqrt(dx*dx + dy*dy); + float dx0, dx1, dx2, dx3, dx4, dx5, dx6, dx7; + float dy0, dy1, dy2, dy3, dy4, dy5, dy6, dy7; + + dx /= len; + dy /= len; + + width *= 0.5; /* half width */ + dx = dx * (width + 0.0); + dy = dy * (width + 0.0); + + dx0 = -dx+dy; dy0 = -dy-dx; + dx1 = -dx-dy; dy1 = -dy+dx; + + dx2 = 0+dy; dy2 = -dx+0; + dx3 = 0-dy; dy3 = +dx+0; + + dx4 = 0+dy; dy4 = -dx+0; + dx5 = 0-dy; dy5 = +dx+0; + + dx6 = dx+dy; dy6 = dy-dx; + dx7 = dx-dy; dy7 = dy+dx; + + /* + printf("dx, dy = %g, %g\n", dx, dy); + printf(" dx0, dy0: %g, %g\n", dx0, dy0); + printf(" dx1, dy1: %g, %g\n", dx1, dy1); + printf(" dx2, dy2: %g, %g\n", dx2, dy2); + printf(" dx3, dy3: %g, %g\n", dx3, dy3); + */ + + glBegin(GL_QUAD_STRIP); + glTexCoord2f(0, 0); + glVertex2f(v0[0] + dx0, v0[1] + dy0); + glTexCoord2f(0, 1); + glVertex2f(v0[0] + dx1, v0[1] + dy1); + + glTexCoord2f(0.5, 0); + glVertex2f(v0[0] + dx2, v0[1] + dy2); + glTexCoord2f(0.5, 1); + glVertex2f(v0[0] + dx3, v0[1] + dy3); + + glTexCoord2f(0.5, 0); + glVertex2f(v1[0] + dx2, v1[1] + dy2); + glTexCoord2f(0.5, 1); + glVertex2f(v1[0] + dx3, v1[1] + dy3); + + glTexCoord2f(1, 0); + glVertex2f(v1[0] + dx6, v1[1] + dy6); + glTexCoord2f(1, 1); + glVertex2f(v1[0] + dx7, v1[1] + dy7); + glEnd(); +} + + +static float Cos(float a) +{ + return cos(a * M_PI / 180.); +} + +static float Sin(float a) +{ + return sin(a * M_PI / 180.); +} + +static void +Redisplay(void) +{ + int i; + + glClear(GL_COLOR_BUFFER_BIT); + + glColor3f(1, 1, 1); + + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + + for (i = 0; i < 360; i+=5) { + float v0[2], v1[2]; + v0[0] = 150 + 40 * Cos(i); + v0[1] = 150 + 40 * Sin(i); + v1[0] = 150 + 130 * Cos(i); + v1[1] = 150 + 130 * Sin(i); + QuadLine(v0, v1, Width); + } + + { + float v0[2], v1[2], x; + for (x = 0; x < 1.0; x += 0.2) { + v0[0] = 150 + x; + v0[1] = 150 + x * 40 - 20; + v1[0] = 150 + x + 5.0; + v1[1] = 150 + x * 40 - 20; + QuadLine(v0, v1, Width); + } + } + + glDisable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, width, 0, height, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +CleanUp(void) +{ + glutDestroyWindow(win); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + + switch(key) { + case 'w': + Width -= 0.5; + break; + case 'W': + Width += 0.5; + break; + case 27: + CleanUp(); + exit(0); + break; + } +#if 0 + if (Width < 3) + Width = 3; +#endif + printf("Width = %g\n", Width); + glutPostRedisplay(); +} + + +static float +ramp4(GLint i, GLint size) +{ + float d; + if (i < 4 ) { + d = i / 4.0; + } + else if (i >= size - 5) { + d = 1.0 - (i - (size - 5)) / 4.0; + } + else { + d = 1.0; + } + return d; +} + +static float +ramp2(GLint i, GLint size) +{ + float d; + if (i < 2 ) { + d = i / 2.0; + } + else if (i >= size - 3) { + d = 1.0 - (i - (size - 3)) / 2.0; + } + else { + d = 1.0; + } + return d; +} + +static float +ramp1(GLint i, GLint size) +{ + float d; + if (i == 0 || i == size-1) { + d = 0.0; + } + else { + d = 1.0; + } + return d; +} + + +/** + * Make an alpha texture for antialiasing lines. + * Just a linear fall-off ramp for now. + * Should have a number of different textures for different line widths. + * Could try a bell-like-curve.... + */ +static void +MakeTexture(void) +{ +#define SZ 8 + GLfloat tex[SZ][SZ]; /* alpha tex */ + int i, j; + for (i = 0; i < SZ; i++) { + for (j = 0; j < SZ; j++) { +#if 0 + float k = (SZ-1) / 2.0; + float dx = fabs(i - k) / k; + float dy = fabs(j - k) / k; + float d; + + dx = 1.0 - dx; + dy = 1.0 - dy; + d = dx * dy; + +#else + float d = ramp1(i, SZ) * ramp1(j, SZ); + printf("%d, %d: %g\n", i, j, d); +#endif + tex[i][j] = d; + } + } + + glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, SZ, SZ, 0, GL_ALPHA, GL_FLOAT, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#undef SZ +} + + +static void +MakeMipmap(void) +{ +#define SZ 64 + GLfloat tex[SZ][SZ]; /* alpha tex */ + int level; + + glPixelStorei(GL_UNPACK_ROW_LENGTH, SZ); + for (level = 0; level < 7; level++) { + int sz = 1 << (6 - level); + int i, j; + for (i = 0; i < sz; i++) { + for (j = 0; j < sz; j++) { + if (level == 6) + tex[i][j] = 1.0; + else if (level == 5) + tex[i][j] = 0.5; + else + tex[i][j] = ramp1(i, sz) * ramp1(j, sz); + } + } + + glTexImage2D(GL_TEXTURE_2D, level, GL_ALPHA, + sz, sz, 0, GL_ALPHA, GL_FLOAT, tex); + } + + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 4); + ////glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 5); + + glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); +#undef SZ +} + + +static void +Init(void) +{ + const char *version; + + (void) MakeTexture; + (void) ramp4; + (void) ramp2; + + version = (const char *) glGetString(GL_VERSION); + if (version[0] != '2' || version[1] != '.') { + printf("This program requires OpenGL 2.x, found %s\n", version); + exit(1); + } + + GetExtensionFuncs(); + + glClearColor(0.3f, 0.3f, 0.3f, 0.0f); + + printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#if 0 + glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); +#elif 0 + MakeTexture(); +#else + MakeMipmap(); +#endif +} + + +static void +ParseOptions(int argc, char *argv[]) +{ +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition( 0, 0); + glutInitWindowSize(WinWidth, WinHeight); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); + win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Redisplay); + ParseOptions(argc, argv); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 59c8e738c4803545107dae85c412f258120903eb Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 18 Apr 2009 23:16:54 +0100 Subject: progs/glsl: Update ignore --- progs/glsl/.gitignore | 3 +++ 1 file changed, 3 insertions(+) (limited to 'progs') diff --git a/progs/glsl/.gitignore b/progs/glsl/.gitignore index d3e31163d8..39d90c23ac 100644 --- a/progs/glsl/.gitignore +++ b/progs/glsl/.gitignore @@ -1,3 +1,4 @@ +array bitmap brick bump @@ -11,6 +12,7 @@ mandelbrot multinoise multitex noise +noise2 pointcoord points readtex.c @@ -21,6 +23,7 @@ shaderutil.c shaderutil.h shadow_sampler skinning +texaaline texdemo1 toyball trirast -- cgit v1.2.3 From 90a23e340fbfedd76f255fbcab88a07ece2b65db Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sun, 19 Apr 2009 16:22:43 +0100 Subject: progs/demos: Update ignore --- progs/demos/.gitignore | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'progs') diff --git a/progs/demos/.gitignore b/progs/demos/.gitignore index c6ff227391..f3c7091bcc 100644 --- a/progs/demos/.gitignore +++ b/progs/demos/.gitignore @@ -21,6 +21,7 @@ gears geartrain glinfo gloss +glslnoise gltestperf glutfx ipers @@ -45,12 +46,14 @@ singlebuffer spectex spriteblast stex3d +streaming_rect teapot terrain tessdemo texcyl texdown texenv +texobj textures trackball.c trackball.h @@ -58,4 +61,5 @@ trispd tunnel tunnel2 vao_demo +Windows winpos -- cgit v1.2.3 From 70588fc83c5aa75754f7b090a63727f4791618ed Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 17 Apr 2009 15:54:57 +0100 Subject: tests/mipmap_view: add linear/nearest key --- progs/tests/mipmap_view.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'progs') diff --git a/progs/tests/mipmap_view.c b/progs/tests/mipmap_view.c index 16f3584f70..85fc67ac79 100644 --- a/progs/tests/mipmap_view.c +++ b/progs/tests/mipmap_view.c @@ -22,6 +22,7 @@ static int TexWidth = 256, TexHeight = 256; static int WinWidth = 1044, WinHeight = 900; static GLfloat Bias = 0.0; static GLboolean ScaleQuads = GL_FALSE; +static GLboolean Linear = GL_FALSE; static GLint Win = 0; @@ -53,6 +54,15 @@ Display(void) glColor3f(1,1,1); + if (Linear) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + } + else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + } + y = WinHeight - 300; x = 4; @@ -132,6 +142,9 @@ Key(unsigned char key, int x, int y) case 'B': Bias += 10; break; + case 'l': + Linear = !Linear; + break; case '0': case '1': case '2': @@ -222,8 +235,6 @@ Init(void) /* mipmapping required for this extension */ - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS_EXT, &maxBias); -- cgit v1.2.3 From c691f96e9848d05947afc40ea5c14bc2989f00cf Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 20 Apr 2009 15:50:44 +0100 Subject: trivial/tri-viewport.c - add guide lines, more triangles, make interactive This is becoming more like a test than a trivial/ example. --- progs/trivial/tri-viewport.c | 132 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 118 insertions(+), 14 deletions(-) (limited to 'progs') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 8e5f155c7d..4cd64e0781 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -29,6 +29,10 @@ GLenum doubleBuffer = 1; int win; +static float tx = 0; +static float ty = 0; +static float tw = 250; +static float th = 250; static void Init(void) { @@ -42,15 +46,11 @@ static void Init(void) static void Reshape(int width, int height) { - glViewport(width / -2.0, height / -2.0, width, height); - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + tw = width; + th = height; } + static void Key(unsigned char key, int x, int y) { switch (key) { @@ -62,19 +62,91 @@ static void Key(unsigned char key, int x, int y) } } + static void Draw(void) { + int i; + + fprintf(stderr, "%f %f\n", tx, ty); + fflush(stderr); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); + glClear(GL_COLOR_BUFFER_BIT); + glViewport(0, 0, tw, th); + + glBegin(GL_LINES); + glColor3f(1,1,0); + glVertex3f(-1, 0, -30.0); + glVertex3f(1, 0, -30.0); + + glVertex3f(0, -1, -30.0); + glVertex3f(0, 1, -30.0); + glEnd(); + + + /* + */ + glViewport(tx, ty, tw, th); + + glBegin(GL_TRIANGLES); - glColor3f(.8,0,0); - glVertex3f(-0.9, 0.9, -30.0); - glColor3f(0,.9,0); - glVertex3f( 0.9, 0.9, -30.0); - glColor3f(0,0,.7); - glVertex3f( 0.0, -0.9, -30.0); + glColor3f(1,0,0); + glVertex3f(-1, -1, -30.0); + glVertex3f(0, -1, -30.0); + glVertex3f(-.5, -.5, -30.0); + + glColor3f(1,1,1); + glVertex3f(0, -1, -30.0); + glVertex3f(1, -1, -30.0); + glVertex3f(.5, -.5, -30.0); + + glVertex3f(-.5, -.5, -30.0); + glVertex3f(.5, -.5, -30.0); + glVertex3f(0, 0, -30.0); + + + glColor3f(0,1,0); + glVertex3f(1, 1, -30.0); + glVertex3f(0, 1, -30.0); + glVertex3f(.5, .5, -30.0); + + glColor3f(1,1,1); + glVertex3f(0, 1, -30.0); + glVertex3f(-1, 1, -30.0); + glVertex3f(-.5, .5, -30.0); + + glVertex3f(.5, .5, -30.0); + glVertex3f(-.5, .5, -30.0); + glVertex3f( 0, 0, -30.0); + + glEnd(); + + + glViewport(0, 0, tw, th); + + glBegin(GL_LINES); + glColor3f(.5,.5,0); + for (i = -10; i < 10; i++) { + float f = i / 10.0; + + if (i == 0) + continue; + + glVertex3f(-1, f, -30.0); + glVertex3f(1, f, -30.0); + + glVertex3f(f, -1, -30.0); + glVertex3f(f, 1, -30.0); + } glEnd(); + + glFlush(); if (doubleBuffer) { @@ -86,6 +158,13 @@ static GLenum Args(int argc, char **argv) { GLint i; + if (getenv("VPX")) + tx = atof(getenv("VPX")); + + if (getenv("VPY")) + ty = atof(getenv("VPY")); + + for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-sb") == 0) { doubleBuffer = GL_FALSE; @@ -99,6 +178,30 @@ static GLenum Args(int argc, char **argv) return GL_TRUE; } + +static void +special(int k, int x, int y) +{ + switch (k) { + case GLUT_KEY_UP: + ty += 1.0; + break; + case GLUT_KEY_DOWN: + ty -= 1.0; + break; + case GLUT_KEY_LEFT: + tx -= 1.0; + break; + case GLUT_KEY_RIGHT: + tx += 1.0; + break; + default: + return; + } + glutPostRedisplay(); +} + + int main(int argc, char **argv) { GLenum type; @@ -123,7 +226,8 @@ int main(int argc, char **argv) Init(); glutReshapeFunc(Reshape); - glutKeyboardFunc(Key); + glutKeyboardFunc(Key); + glutSpecialFunc(special); glutDisplayFunc(Draw); glutMainLoop(); return 0; -- cgit v1.2.3 From d017749b3ea07f2cc43bb5e8316b83471d1e13ec Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 20 Apr 2009 16:17:50 +0100 Subject: mesa/progs: fix scons build after recent demo moves --- progs/demos/SConscript | 10 ++++------ progs/tests/SConscript | 9 +++++---- 2 files changed, 9 insertions(+), 10 deletions(-) (limited to 'progs') diff --git a/progs/demos/SConscript b/progs/demos/SConscript index bc166dd789..f851870bcf 100644 --- a/progs/demos/SConscript +++ b/progs/demos/SConscript @@ -39,11 +39,9 @@ progs = [ 'geartrain', 'glinfo', 'gloss', - 'glslnoise', 'gltestperf', - 'glutfx', - 'isosurf', 'ipers', + 'isosurf', 'lodbias', 'morph3d', 'multiarb', @@ -55,7 +53,6 @@ progs = [ 'renormal', 'shadowtex', 'singlebuffer', - 'streaming_rect', 'spectex', 'spriteblast', 'stex3d', @@ -63,15 +60,16 @@ progs = [ 'terrain', 'tessdemo', 'texcyl', - 'texdown', 'texenv', - 'texobj', 'textures', 'trispd', 'tunnel', 'tunnel2', 'vao_demo', 'winpos', + 'dinoshade', + 'fbotexture', + 'projtex', ] for prog in progs: diff --git a/progs/tests/SConscript b/progs/tests/SConscript index bf1e7f8a7d..4f22ca735c 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -42,8 +42,8 @@ progs = [ 'arbfptest1', 'arbfptexture', 'arbfptrig', - 'arbnpot-mipmap', 'arbnpot', + 'arbnpot-mipmap', 'arbvptest1', 'arbvptest3', 'arbvptorus', @@ -61,19 +61,18 @@ progs = [ 'copypixrate', 'crossbar', 'cva', - 'dinoshade', 'drawbuffers', 'exactrast', 'ext422square', 'fbotest1', 'fbotest2', - 'fbotexture', 'fillrate', 'floattex', 'fog', 'fogcoord', 'fptest1', 'fptexture', + 'glutfx', 'interleave', 'invert', 'lineclip', @@ -91,7 +90,6 @@ progs = [ 'packedpixels', 'pbo', 'prog_parameter', - 'projtex', 'quads', 'random', 'readrate', @@ -101,14 +99,17 @@ progs = [ 'stencil_twoside', 'stencil_wrap', 'stencilwrap', + 'streaming_rect', 'subtex', 'subtexrate', 'tex1d', 'texcmp', 'texcompress2', + 'texdown', 'texfilt', 'texgenmix', 'texline', + 'texobj', 'texrect', 'texwrap', 'unfilledclip', -- cgit v1.2.3 From 6bfcffa79e8b7999e8193e721e07dbb3de4a1658 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 20 Apr 2009 17:30:53 +0100 Subject: trivial/tri_viewport: add width/height keys --- progs/trivial/tri-viewport.c | 67 ++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 18 deletions(-) (limited to 'progs') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 4cd64e0781..c08089b9dd 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -31,8 +31,11 @@ GLenum doubleBuffer = 1; int win; static float tx = 0; static float ty = 0; -static float tw = 250; -static float th = 250; +static float tw = 0; +static float th = 0; + +static float win_width = 250; +static float win_height = 250; static void Init(void) { @@ -41,33 +44,49 @@ static void Init(void) fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); fflush(stderr); - glClearColor(0.3, 0.1, 0.3, 0.0); + glClearColor(0, 0, 0, 0.0); } static void Reshape(int width, int height) { - tw = width; - th = height; + win_width = width; + win_height = height; + glutPostRedisplay(); } static void Key(unsigned char key, int x, int y) { switch (key) { - case 27: - exit(0); - default: - glutPostRedisplay(); - return; + case 27: + exit(0); + case 'w': + tw += 1.0; + break; + case 'W': + tw -= 1.0; + break; + case 'h': + th += 1.0; + break; + case 'H': + th -= 1.0; + break; + + default: + break; } + glutPostRedisplay(); } static void Draw(void) { int i; + float w = tw + win_width; + float h = th + win_height; - fprintf(stderr, "%f %f\n", tx, ty); + fprintf(stderr, "glViewport(%f %f %f %f)\n", tx, ty, w, h); fflush(stderr); glMatrixMode(GL_PROJECTION); @@ -77,8 +96,22 @@ static void Draw(void) glClear(GL_COLOR_BUFFER_BIT); - glViewport(0, 0, tw, th); + /*********************************************************************** + * Should be clipped to be no larger than the triangles: + */ + glViewport(tx, ty, w, h); + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-2, -2, -30.0); + glVertex3f(-2, 2, -30.0); + glVertex3f(2, 2, -30.0); + glVertex3f(2, -2, -30.0); + glEnd(); + + /*********************************************************************** + */ + glViewport(0, 0, win_width, win_height); glBegin(GL_LINES); glColor3f(1,1,0); glVertex3f(-1, 0, -30.0); @@ -89,11 +122,9 @@ static void Draw(void) glEnd(); - /* + /*********************************************************************** */ - glViewport(tx, ty, tw, th); - - + glViewport(tx, ty, w, h); glBegin(GL_TRIANGLES); glColor3f(1,0,0); glVertex3f(-1, -1, -30.0); @@ -127,7 +158,7 @@ static void Draw(void) glEnd(); - glViewport(0, 0, tw, th); + glViewport(0, 0, win_width, win_height); glBegin(GL_LINES); glColor3f(.5,.5,0); @@ -196,7 +227,7 @@ special(int k, int x, int y) tx += 1.0; break; default: - return; + break; } glutPostRedisplay(); } -- cgit v1.2.3 From a38f7d9e689f0e12cb8eed6b96a140805b452ba1 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Mon, 20 Apr 2009 17:32:15 +0100 Subject: trivial/tri_viewport: add space==reset key --- progs/trivial/tri-viewport.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index c08089b9dd..37e424467b 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -72,7 +72,9 @@ static void Key(unsigned char key, int x, int y) case 'H': th -= 1.0; break; - + case ' ': + tw = th = tx = ty = 0; + break; default: break; } -- cgit v1.2.3 From 6e05224bc4d00ba05fee8651d2a9ecbf2a4b3ca8 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 21 Apr 2009 10:59:54 +0100 Subject: trivial/tri-viewport: add more out-of-bounds background quads --- progs/trivial/tri-viewport.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 37e424467b..133744235f 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -103,14 +103,40 @@ static void Draw(void) * Should be clipped to be no larger than the triangles: */ glViewport(tx, ty, w, h); + glBegin(GL_POLYGON); - glColor3f(.5,.5,1); + glColor3f(1,1,0); + glVertex3f(-100, -100, -30.0); + glVertex3f(-100, 100, -30.0); + glVertex3f(100, 100, -30.0); + glVertex3f(100, -100, -30.0); + glEnd(); + + glBegin(GL_POLYGON); + glColor3f(0,1,1); + glVertex3f(-10, -10, -30.0); + glVertex3f(-10, 10, -30.0); + glVertex3f(10, 10, -30.0); + glVertex3f(10, -10, -30.0); + glEnd(); + + glBegin(GL_POLYGON); + glColor3f(1,0,0); glVertex3f(-2, -2, -30.0); glVertex3f(-2, 2, -30.0); glVertex3f(2, 2, -30.0); glVertex3f(2, -2, -30.0); glEnd(); + + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-1, -1, -30.0); + glVertex3f(-1, 1, -30.0); + glVertex3f(1, 1, -30.0); + glVertex3f(1, -1, -30.0); + glEnd(); + /*********************************************************************** */ glViewport(0, 0, win_width, win_height); -- cgit v1.2.3 From e20f837f672e43671890d5f62f9814487e15531f Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 21 Apr 2009 11:40:59 +0100 Subject: trivial/tri-viewport: add keys for frustrum/ortho and z coordinate --- progs/trivial/tri-viewport.c | 120 +++++++++++++++++++++++++++---------------- 1 file changed, 77 insertions(+), 43 deletions(-) (limited to 'progs') diff --git a/progs/trivial/tri-viewport.c b/progs/trivial/tri-viewport.c index 133744235f..3e52449b47 100644 --- a/progs/trivial/tri-viewport.c +++ b/progs/trivial/tri-viewport.c @@ -33,9 +33,16 @@ static float tx = 0; static float ty = 0; static float tw = 0; static float th = 0; +static float z = -5; + static float win_width = 250; static float win_height = 250; +static enum { + ORTHO, + FRUSTUM, + MODE_MAX +} mode = ORTHO; static void Init(void) { @@ -72,8 +79,21 @@ static void Key(unsigned char key, int x, int y) case 'H': th -= 1.0; break; + + case 'z': + z += 1.0; + break; + case 'Z': + z -= 1.0; + break; + case 'm': + mode++; + mode %= MODE_MAX; + break; case ' ': tw = th = tx = ty = 0; + z = -5; + mode = ORTHO; break; default: break; @@ -89,12 +109,26 @@ static void Draw(void) float h = th + win_height; fprintf(stderr, "glViewport(%f %f %f %f)\n", tx, ty, w, h); + fprintf(stderr, "mode: %s\n", mode == FRUSTUM ? "FRUSTUM" : "ORTHO"); + fprintf(stderr, "z: %f\n", z); fflush(stderr); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + + switch (mode) { + case FRUSTUM: + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + break; + case ORTHO: + default: + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + break; + } + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glClear(GL_COLOR_BUFFER_BIT); @@ -106,35 +140,35 @@ static void Draw(void) glBegin(GL_POLYGON); glColor3f(1,1,0); - glVertex3f(-100, -100, -30.0); - glVertex3f(-100, 100, -30.0); - glVertex3f(100, 100, -30.0); - glVertex3f(100, -100, -30.0); + glVertex3f(-100, -100, z); + glVertex3f(-100, 100, z); + glVertex3f(100, 100, z); + glVertex3f(100, -100, z); glEnd(); glBegin(GL_POLYGON); glColor3f(0,1,1); - glVertex3f(-10, -10, -30.0); - glVertex3f(-10, 10, -30.0); - glVertex3f(10, 10, -30.0); - glVertex3f(10, -10, -30.0); + glVertex3f(-10, -10, z); + glVertex3f(-10, 10, z); + glVertex3f(10, 10, z); + glVertex3f(10, -10, z); glEnd(); glBegin(GL_POLYGON); glColor3f(1,0,0); - glVertex3f(-2, -2, -30.0); - glVertex3f(-2, 2, -30.0); - glVertex3f(2, 2, -30.0); - glVertex3f(2, -2, -30.0); + glVertex3f(-2, -2, z); + glVertex3f(-2, 2, z); + glVertex3f(2, 2, z); + glVertex3f(2, -2, z); glEnd(); glBegin(GL_POLYGON); glColor3f(.5,.5,1); - glVertex3f(-1, -1, -30.0); - glVertex3f(-1, 1, -30.0); - glVertex3f(1, 1, -30.0); - glVertex3f(1, -1, -30.0); + glVertex3f(-1, -1, z); + glVertex3f(-1, 1, z); + glVertex3f(1, 1, z); + glVertex3f(1, -1, z); glEnd(); /*********************************************************************** @@ -142,11 +176,11 @@ static void Draw(void) glViewport(0, 0, win_width, win_height); glBegin(GL_LINES); glColor3f(1,1,0); - glVertex3f(-1, 0, -30.0); - glVertex3f(1, 0, -30.0); + glVertex3f(-1, 0, z); + glVertex3f(1, 0, z); - glVertex3f(0, -1, -30.0); - glVertex3f(0, 1, -30.0); + glVertex3f(0, -1, z); + glVertex3f(0, 1, z); glEnd(); @@ -155,33 +189,33 @@ static void Draw(void) glViewport(tx, ty, w, h); glBegin(GL_TRIANGLES); glColor3f(1,0,0); - glVertex3f(-1, -1, -30.0); - glVertex3f(0, -1, -30.0); - glVertex3f(-.5, -.5, -30.0); + glVertex3f(-1, -1, z); + glVertex3f(0, -1, z); + glVertex3f(-.5, -.5, z); glColor3f(1,1,1); - glVertex3f(0, -1, -30.0); - glVertex3f(1, -1, -30.0); - glVertex3f(.5, -.5, -30.0); + glVertex3f(0, -1, z); + glVertex3f(1, -1, z); + glVertex3f(.5, -.5, z); - glVertex3f(-.5, -.5, -30.0); - glVertex3f(.5, -.5, -30.0); - glVertex3f(0, 0, -30.0); + glVertex3f(-.5, -.5, z); + glVertex3f(.5, -.5, z); + glVertex3f(0, 0, z); glColor3f(0,1,0); - glVertex3f(1, 1, -30.0); - glVertex3f(0, 1, -30.0); - glVertex3f(.5, .5, -30.0); + glVertex3f(1, 1, z); + glVertex3f(0, 1, z); + glVertex3f(.5, .5, z); glColor3f(1,1,1); - glVertex3f(0, 1, -30.0); - glVertex3f(-1, 1, -30.0); - glVertex3f(-.5, .5, -30.0); + glVertex3f(0, 1, z); + glVertex3f(-1, 1, z); + glVertex3f(-.5, .5, z); - glVertex3f(.5, .5, -30.0); - glVertex3f(-.5, .5, -30.0); - glVertex3f( 0, 0, -30.0); + glVertex3f(.5, .5, z); + glVertex3f(-.5, .5, z); + glVertex3f( 0, 0, z); glEnd(); @@ -196,11 +230,11 @@ static void Draw(void) if (i == 0) continue; - glVertex3f(-1, f, -30.0); - glVertex3f(1, f, -30.0); + glVertex3f(-1, f, z); + glVertex3f(1, f, z); - glVertex3f(f, -1, -30.0); - glVertex3f(f, 1, -30.0); + glVertex3f(f, -1, z); + glVertex3f(f, 1, z); } glEnd(); -- cgit v1.2.3 From dad1c1be18dc4e8e7f51cdb91652124e9427e644 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 21 Apr 2009 07:27:12 -0600 Subject: demos: check that GL version is 2.0 or higher --- progs/tests/shader_api.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'progs') diff --git a/progs/tests/shader_api.c b/progs/tests/shader_api.c index a513ca6ba1..6453856345 100644 --- a/progs/tests/shader_api.c +++ b/progs/tests/shader_api.c @@ -321,10 +321,18 @@ static void run_test(const char *name, void (*callback)(void)) int main(int argc, char **argv) { + const char *version; + glutInit(&argc, argv); glutCreateWindow("Mesa bug demo"); glewInit(); + version = (const char *) glGetString(GL_VERSION); + if (version[0] == '1') { + printf("Sorry, this test requires OpenGL 2.x GLSL support\n"); + exit(0); + } + RUN_TEST(test_uniform_size_type); RUN_TEST(test_attrib_size_type); RUN_TEST(test_uniform_array_overflow); -- cgit v1.2.3 From 510a44eea799f2370b79e5da532b3004e94bb005 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 21 Apr 2009 19:49:29 +0100 Subject: tests/mipmap_view: add a bunch of keystrokes for testing render-to-texture Move between mipmaps, render a triangle, reload textures with either the original arch (and GenMipmaps) or via straightforward glTexImage. --- progs/tests/mipmap_view.c | 267 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 219 insertions(+), 48 deletions(-) (limited to 'progs') diff --git a/progs/tests/mipmap_view.c b/progs/tests/mipmap_view.c index 85fc67ac79..808d348699 100644 --- a/progs/tests/mipmap_view.c +++ b/progs/tests/mipmap_view.c @@ -18,12 +18,27 @@ #define TEXTURE_FILE "../images/arch.rgb" -static int TexWidth = 256, TexHeight = 256; +#define LEVELS 8 +#define SIZE (1< Date: Wed, 22 Apr 2009 15:19:44 +0100 Subject: demos/readpix: add option to draw triangle instead of drawpix --- progs/demos/readpix.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 5 deletions(-) (limited to 'progs') diff --git a/progs/demos/readpix.c b/progs/demos/readpix.c index c0aac2272f..bbb3a68eff 100644 --- a/progs/demos/readpix.c +++ b/progs/demos/readpix.c @@ -17,6 +17,7 @@ #define IMAGE_FILE "../images/girl.rgb" static int ImgWidth, ImgHeight; +static int WinWidth, WinHeight; static GLenum ImgFormat; static GLubyte *Image = NULL; @@ -27,6 +28,7 @@ static int CPosX, CPosY; /* copypixels */ static GLboolean DrawFront = GL_FALSE; static GLboolean ScaleAndBias = GL_FALSE; static GLboolean Benchmark = GL_FALSE; +static GLboolean Triangle = GL_FALSE; static GLubyte *TempImage = NULL; #define COMBO 1 @@ -150,11 +152,60 @@ Display( void ) /* draw original image */ glRasterPos2i(APosX, 5); PrintString("Original"); - glRasterPos2i(APosX, APosY); - glEnable(GL_DITHER); - SetupPixelTransfer(GL_FALSE); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + if (!Triangle) { + glRasterPos2i(APosX, APosY); + glEnable(GL_DITHER); + SetupPixelTransfer(GL_FALSE); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glDrawPixels(ImgWidth, ImgHeight, ImgFormat, GL_UNSIGNED_BYTE, Image); + } + else { + float z = 0; + + glViewport(APosX, APosY, ImgWidth, ImgHeight); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); + glDisable(GL_CULL_FACE); + + /* Red should never be seen + */ + glBegin(GL_POLYGON); + glColor3f(1,0,0); + glVertex3f(-2, -2, z); + glVertex3f(-2, 2, z); + glVertex3f(2, 2, z); + glVertex3f(2, -2, z); + glEnd(); + + /* Blue background + */ + glBegin(GL_POLYGON); + glColor3f(.5,.5,1); + glVertex3f(-1, -1, z); + glVertex3f(-1, 1, z); + glVertex3f(1, 1, z); + glVertex3f(1, -1, z); + glEnd(); + + /* Triangle + */ + glBegin(GL_TRIANGLES); + glColor3f(.8,0,0); + glVertex3f(-0.9, -0.9, z); + glColor3f(0,.9,0); + glVertex3f( 0.9, -0.9, z); + glColor3f(0,0,.7); + glVertex3f( 0.0, 0.9, z); + glEnd(); + + glColor3f(1,1,1); + + glViewport( 0, 0, WinWidth, WinHeight ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho( 0.0, WinWidth, 0.0, WinHeight, -1.0, 1.0 ); + } /* might try alignment=4 here for testing */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -218,6 +269,9 @@ Display( void ) static void Reshape( int width, int height ) { + WinWidth = width; + WinHeight = height; + glViewport( 0, 0, width, height ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); @@ -236,6 +290,9 @@ Key( unsigned char key, int x, int y ) case 'b': Benchmark = GL_TRUE; break; + case 't': + Triangle = !Triangle; + break; case 's': ScaleAndBias = !ScaleAndBias; break; -- cgit v1.2.3 From a86ef37655c25e0e5a7cb0e41ba7b1c2dcdc1a90 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Fri, 24 Apr 2009 12:16:29 +0100 Subject: shadowtex: fflush stdout for cygwin --- progs/demos/shadowtex.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'progs') diff --git a/progs/demos/shadowtex.c b/progs/demos/shadowtex.c index f10a01ec26..dc5a4bbc48 100644 --- a/progs/demos/shadowtex.c +++ b/progs/demos/shadowtex.c @@ -788,6 +788,7 @@ Key(unsigned char key, int x, int y) exit(0); break; } + fflush(stdout); glutPostRedisplay(); } @@ -1014,6 +1015,7 @@ PrintHelp(void) printf(" + cursor keys = rotate light source\n"); if (HaveEXTshadowFuncs) printf(" o = cycle through comparison modes\n"); + fflush(stdout); } -- cgit v1.2.3 From b2a69ae879a3ddb1f0ca1ea184ba24587cf25786 Mon Sep 17 00:00:00 2001 From: Alan Hourihane Date: Fri, 24 Apr 2009 16:44:58 +0100 Subject: demos: ensure display lists are destroyed for next generation --- progs/xdemos/glxcontexts.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'progs') diff --git a/progs/xdemos/glxcontexts.c b/progs/xdemos/glxcontexts.c index a9ff326ed5..a97b62a908 100644 --- a/progs/xdemos/glxcontexts.c +++ b/progs/xdemos/glxcontexts.c @@ -385,6 +385,10 @@ draw( Display *dpy, Window win ) } else do_draw(); + glDeleteLists(gear1, 1); + glDeleteLists(gear2, 1); + glDeleteLists(gear3, 1); + glXSwapBuffers(dpy, win); glXDestroyContext(dpy, ctx); } -- cgit v1.2.3 From e32660060954c0d1a1f7636c6365970348f3be24 Mon Sep 17 00:00:00 2001 From: Shuang He Date: Mon, 27 Apr 2009 07:13:33 -0600 Subject: demos: Clean up allocated Textures and Display Lists when demo quit --- progs/demos/ipers.c | 18 ++++++++++++++++++ progs/demos/teapot.c | 11 +++++++++++ progs/demos/tunnel.c | 9 +++++++++ progs/demos/tunnel2.c | 9 +++++++++ 4 files changed, 47 insertions(+) (limited to 'progs') diff --git a/progs/demos/ipers.c b/progs/demos/ipers.c index 6e153c04e1..5d82b0dc92 100644 --- a/progs/demos/ipers.c +++ b/progs/demos/ipers.c @@ -236,11 +236,28 @@ special(int k, int x, int y) } } +static void +cleanup(void) +{ + int i; + + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); + + glDeleteLists(skydlist, 1); + for (i = 0; i < MAX_LOD; i++) { + glDeleteLists(LODdlist[i], 1); + glDeleteLists(LODnumpoly[i], 1); + } +} + + static void key(unsigned char k, int x, int y) { switch (k) { case 27: + cleanup(); exit(0); break; @@ -707,6 +724,7 @@ main(int ac, char **av) glutIdleFunc(draw); glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/teapot.c b/progs/demos/teapot.c index 38ede7ac3e..6bf6e06409 100644 --- a/progs/demos/teapot.c +++ b/progs/demos/teapot.c @@ -173,10 +173,20 @@ static void special(int k, int x, int y) } } +static void cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); + glDeleteLists(teapotdlist, 1); + glDeleteLists(basedlist, 1); + glDeleteLists(lightdlist, 1); +} + static void key(unsigned char k, int x, int y) { switch(k) { case 27: + cleanup(); exit(0); break; @@ -670,6 +680,7 @@ int main(int ac, char **av) glutIdleFunc(draw); glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/tunnel.c b/progs/demos/tunnel.c index 6a240580e8..6981da3298 100644 --- a/progs/demos/tunnel.c +++ b/progs/demos/tunnel.c @@ -202,11 +202,19 @@ special(int k, int x, int y) } } +static void +cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); +} + static void key(unsigned char k, int x, int y) { switch (k) { case 27: + cleanup(); exit(0); break; @@ -531,5 +539,6 @@ main(int ac, char **av) glutMainLoop(); + cleanup(); return 0; } diff --git a/progs/demos/tunnel2.c b/progs/demos/tunnel2.c index f4171a8346..0288ea0f8c 100644 --- a/progs/demos/tunnel2.c +++ b/progs/demos/tunnel2.c @@ -200,6 +200,13 @@ special(int k, int x, int y) } } +static void +cleanup(void) +{ + glDeleteTextures(1, &t1id); + glDeleteTextures(1, &t2id); +} + static void key(unsigned char k, int x, int y) { @@ -207,6 +214,7 @@ key(unsigned char k, int x, int y) case 27: glutDestroyWindow(channel[0]); glutDestroyWindow(channel[1]); + cleanup(); exit(0); break; @@ -602,6 +610,7 @@ main(int ac, char **av) calcposobs(); glutMainLoop(); + cleanup(); return 0; } -- cgit v1.2.3 From e0d5ff1a8a2237808d88f087f029224beee015af Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 27 Apr 2009 17:01:59 -0600 Subject: demos: asst. updates, clean-ups --- progs/tests/floattex.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'progs') diff --git a/progs/tests/floattex.c b/progs/tests/floattex.c index dd99d836c6..ad14cacdcb 100644 --- a/progs/tests/floattex.c +++ b/progs/tests/floattex.c @@ -1,6 +1,5 @@ /* * Test floating point textures. - * No actual rendering, yet. */ @@ -103,7 +102,6 @@ Key(unsigned char key, int x, int y) } - static void InitTexture(void) { @@ -141,6 +139,8 @@ InitTexture(void) GL_RGB, GL_FLOAT, ftex); + CheckError(__LINE__); + /* sanity checks */ glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_TYPE_ARB, &t); assert(t == GL_FLOAT); @@ -152,32 +152,26 @@ InitTexture(void) assert(t == GL_FLOAT); free(image); - free(ftex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); -#if 0 - /* read back the texture and make sure values are correct */ - glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, tex2); - CheckError(__LINE__); - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) { - if (tex[i][j][0] != tex2[i][j][0] || - tex[i][j][1] != tex2[i][j][1] || - tex[i][j][2] != tex2[i][j][2] || - tex[i][j][3] != tex2[i][j][3]) { - printf("tex[%d][%d] %g %g %g %g != tex2[%d][%d] %g %g %g %g\n", - i, j, - tex[i][j][0], tex[i][j][1], tex[i][j][2], tex[i][j][3], - i, j, - tex2[i][j][0], tex2[i][j][1], tex2[i][j][2], tex2[i][j][3]); + if (1) { + /* read back the texture and make sure values are correct */ + GLfloat *tex2 = (GLfloat *) + malloc(imgWidth * imgHeight * 4 * sizeof(GLfloat)); + glGetTexImage(GL_TEXTURE_2D, 0, imgFormat, GL_FLOAT, tex2); + CheckError(__LINE__); + for (i = 0; i < imgWidth * imgHeight * 4; i++) { + if (ftex[i] != tex2[i]) { + printf("tex[%d] %g != tex2[%d] %g\n", + i, ftex[i], i, tex2[i]); } } } -#endif + + free(ftex); } @@ -193,7 +187,9 @@ CreateProgram(void) assert(program); - // InitUniforms(program, Uniforms); + glUseProgram_func(program); + + InitUniforms(program, Uniforms); return program; } @@ -211,8 +207,9 @@ Init(void) exit(1); } - if (!glutExtensionSupported("GL_MESAX_texture_float")) { - printf("Sorry, this test requires GL_MESAX_texture_float\n"); + if (!glutExtensionSupported("GL_MESAX_texture_float") && + !glutExtensionSupported("GL_ARB_texture_float")) { + printf("Sorry, this test requires GL_MESAX/ARB_texture_float\n"); exit(1); } -- cgit v1.2.3 From fd402791f909371d8f1c1381f0e16a0f08bd78e6 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 28 Apr 2009 11:49:55 +0100 Subject: progs: add fflushes for cygwin --- progs/demos/dinoshade.c | 2 ++ progs/redbook/polyoff.c | 3 +++ 2 files changed, 5 insertions(+) (limited to 'progs') diff --git a/progs/demos/dinoshade.c b/progs/demos/dinoshade.c index 451da2ec89..41b19d5a92 100644 --- a/progs/demos/dinoshade.c +++ b/progs/demos/dinoshade.c @@ -624,6 +624,7 @@ redraw(void) glFinish(); end = glutGet(GLUT_ELAPSED_TIME); printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start); + fflush(stdout); } glutSwapBuffers(); @@ -878,6 +879,7 @@ main(int argc, char **argv) polygonOffsetVersion = MISSING; printf("\ndinoshine: Missing polygon offset.\n"); printf(" Expect shadow depth aliasing artifacts.\n\n"); + fflush(stdout); } } diff --git a/progs/redbook/polyoff.c b/progs/redbook/polyoff.c index 2017b4d8ee..de34b2e767 100644 --- a/progs/redbook/polyoff.c +++ b/progs/redbook/polyoff.c @@ -153,6 +153,7 @@ static void Benchmark( float xdiff, float ydiff ) double seconds, fps; printf("Benchmarking...\n"); + fflush(stdout); draws = 0; startTime = glutGet(GLUT_ELAPSED_TIME); @@ -169,6 +170,7 @@ static void Benchmark( float xdiff, float ydiff ) seconds = (double) (endTime - startTime) / 1000.0; fps = draws / seconds; printf("Result: fps: %g\n", fps); + fflush(stdout); } @@ -263,6 +265,7 @@ void keyboard (unsigned char key, int x, int y) default: break; } + fflush(stdout); } static void -- cgit v1.2.3 From 1793d5adac121a2142b662d87e24990ebf209ca3 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 29 Apr 2009 20:17:21 +0100 Subject: progs/tests: Add mipmap_comp for mipmap testing with compressed textures --- progs/tests/.gitignore | 1 + progs/tests/Makefile | 1 + progs/tests/SConscript | 1 + progs/tests/mipmap_comp.c | 295 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 298 insertions(+) create mode 100644 progs/tests/mipmap_comp.c (limited to 'progs') diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index e6369de3ab..8d05668c07 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -49,6 +49,7 @@ mapbufrange mapvbo minmag mipgen +mipmap_comp mipmap_limits mipmap_view multipal diff --git a/progs/tests/Makefile b/progs/tests/Makefile index f5fbf374f7..628ca41535 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -58,6 +58,7 @@ SOURCES = \ mapvbo.c \ minmag.c \ mipgen.c \ + mipmap_comp.c \ mipmap_limits.c \ mipmap_view.c \ multipal.c \ diff --git a/progs/tests/SConscript b/progs/tests/SConscript index 4f22ca735c..453fcecd9c 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -81,6 +81,7 @@ progs = [ 'mapvbo', 'minmag', 'mipgen', + 'mipmap_comp', 'mipmap_limits', 'mipmap_view', 'multipal', diff --git a/progs/tests/mipmap_comp.c b/progs/tests/mipmap_comp.c new file mode 100644 index 0000000000..5842e2b880 --- /dev/null +++ b/progs/tests/mipmap_comp.c @@ -0,0 +1,295 @@ +/* Copyright (c) Mark J. Kilgard, 1994. */ +/* + * (c) Copyright 1993, Silicon Graphics, Inc. + * ALL RIGHTS RESERVED + * Permission to use, copy, modify, and distribute this software for + * any purpose and without fee is hereby granted, provided that the above + * copyright notice appear in all copies and that both the copyright notice + * and this permission notice appear in supporting documentation, and that + * the name of Silicon Graphics, Inc. not be used in advertising + * or publicity pertaining to distribution of the software without specific, + * written prior permission. + * + * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" + * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, + * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR + * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON + * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, + * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY + * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, + * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF + * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN + * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE + * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. + * + * US Government Users Restricted Rights + * Use, duplication, or disclosure by the Government is subject to + * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph + * (c)(1)(ii) of the Rights in Technical Data and Computer Software + * clause at DFARS 252.227-7013 and/or in similar or successor + * clauses in the FAR or the DOD or NASA FAR Supplement. + * Unpublished-- rights reserved under the copyright laws of the + * United States. Contractor/manufacturer is Silicon Graphics, + * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. + * + * OpenGL(TM) is a trademark of Silicon Graphics, Inc. + */ + +/* mipmap_comp + * Test compressed texture mipmaps + * + * Based on mipmap_limits + */ + +#include +#include +#include +#include +#include + +#include "readtex.h" + +#define SIZE 16 /* not larger then 16 */ + +static GLint BaseLevel = 0, MaxLevel = 9; +static GLfloat MinLod = -1, MaxLod = 9; +static GLfloat LodBias = 0.0; +static GLboolean NearestFilter = GL_TRUE; +static GLuint texImage; + + +static void +initValues(void) +{ + BaseLevel = 0; + MaxLevel = 9; + MinLod = -1; + MaxLod = 2; + LodBias = 5.0; + NearestFilter = GL_TRUE; +} + + +static void +makeImage(int level, int width, int height) +{ +#if 0 + GLubyte img[SIZE*SIZE*3]; + int i, j; + + (void)size; + for (i = 0; i < height; i++) { + for (j = 0; j < width; j++) { + int k = (i * width + j) * 3; + img[k + 0] = 255 * ((level + 1) % 2); + img[k + 1] = 255 * ((level + 1) % 2); + img[k + 2] = 255 * ((level + 1) % 2); + } + } + + glTexImage2D(GL_TEXTURE_2D, level, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, width, height, 0, + GL_RGB, GL_UNSIGNED_BYTE, img); +#else + GLubyte img[128]; + GLint size[] = { + 128, /* 16x16 */ + 32, /* 8x8 */ + 8, /* 4x4 */ + 8, /* 2x2 */ + 8, /* 1x1 */ + }; + int i; + int value = ((level + 1) % 2) * 0xffffffff; + memset(img, 0, 128); + + /* generate black and white mipmap levels */ + if (value) + for (i = 0; i < size[level] / 4; i += 2) + ((int*)img)[i] = value; + + glCompressedTexImage2D(GL_TEXTURE_2D, level, + GL_COMPRESSED_RGB_S3TC_DXT1_EXT, + width, height, 0, + size[level], img); +#endif +} + + +static void +makeImages(void) +{ + int i, sz; + + for (i = 0, sz = SIZE; sz >= 1; i++, sz /= 2) { + makeImage(i, sz, sz); + printf("Level %d size: %d x %d\n", i, sz, sz); + } +} + + +static void +myInit(void) +{ + + initValues(); + + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glShadeModel(GL_FLAT); + + glTranslatef(0.0, 0.0, -3.6); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + glGenTextures(1, &texImage); + glBindTexture(GL_TEXTURE_2D, texImage); + makeImages(); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); + glEnable(GL_TEXTURE_2D); +} + + +static void +display(void) +{ + GLfloat tcm = 1.0; + glBindTexture(GL_TEXTURE_2D, texImage); + + printf("BASE_LEVEL=%d MAX_LEVEL=%d MIN_LOD=%.2g MAX_LOD=%.2g Bias=%.2g Filter=%s\n", + BaseLevel, MaxLevel, MinLod, MaxLod, LodBias, + NearestFilter ? "NEAREST" : "LINEAR"); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, BaseLevel); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, MaxLevel); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, MinLod); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, MaxLod); + + if (NearestFilter) { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_NEAREST_MIPMAP_NEAREST); + } + else { + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, + GL_LINEAR_MIPMAP_LINEAR); + } + + glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBegin(GL_QUADS); + glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); + glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0); + glTexCoord2f(tcm * 3000.0, tcm); glVertex3f(3000.0, 1.0, -6000.0); + glTexCoord2f(tcm * 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0); + glEnd(); + glFlush(); +} + + +static void +myReshape(int w, int h) +{ + glViewport(0, 0, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + + +static void +key(unsigned char k, int x, int y) +{ + (void) x; + (void) y; + switch (k) { + case 'b': + BaseLevel--; + if (BaseLevel < 0) + BaseLevel = 0; + break; + case 'B': + BaseLevel++; + if (BaseLevel > 10) + BaseLevel = 10; + break; + case 'm': + MaxLevel--; + if (MaxLevel < 0) + MaxLevel = 0; + break; + case 'M': + MaxLevel++; + if (MaxLevel > 10) + MaxLevel = 10; + break; + case 'l': + LodBias -= 0.25; + break; + case 'L': + LodBias += 0.25; + break; + case 'n': + MinLod -= 0.25; + break; + case 'N': + MinLod += 0.25; + break; + case 'x': + MaxLod -= 0.25; + break; + case 'X': + MaxLod += 0.25; + break; + case 'f': + NearestFilter = !NearestFilter; + break; + case ' ': + initValues(); + break; + case 27: /* Escape */ + exit(0); + break; + default: + return; + } + glutPostRedisplay(); +} + + +static void +usage(void) +{ + printf("usage:\n"); + printf(" b/B decrease/increase GL_TEXTURE_BASE_LEVEL\n"); + printf(" m/M decrease/increase GL_TEXTURE_MAX_LEVEL\n"); + printf(" n/N decrease/increase GL_TEXTURE_MIN_LOD\n"); + printf(" x/X decrease/increase GL_TEXTURE_MAX_LOD\n"); + printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n"); + printf(" f toggle nearest/linear filtering\n"); + printf(" SPACE reset values\n"); +} + + +int +main(int argc, char** argv) +{ + glutInit(&argc, argv); + glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); + glutInitWindowSize (600, 600); + glutCreateWindow (argv[0]); + glewInit(); + myInit(); + glutReshapeFunc (myReshape); + glutDisplayFunc(display); + glutKeyboardFunc(key); + usage(); + glutMainLoop(); + return 0; /* ANSI C requires main to return int. */ +} -- cgit v1.2.3 From 289dc69418d834e44bd2f63f69382c1f1d3d7c00 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 29 Apr 2009 20:44:03 +0100 Subject: progs/tests: Update ignores --- progs/tests/.gitignore | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'progs') diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index 8d05668c07..959ddcc51f 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -16,22 +16,20 @@ blendminmax blendsquare blendxor bufferobj -bumpmap bug_3050 bug_3101 bug_3195 bug_texstore_i8 +bumpmap calibrate_rast copypixrate crossbar cva -dinoshade drawbuffers extfuncs.h exactrast fbotest1 fbotest2 -fbotexture fillrate floattex fog @@ -40,6 +38,7 @@ fptest1 fptexture getprocaddress getproclist.h +glutfx interleave invert jkrahntest @@ -57,7 +56,6 @@ no_s3tc packedpixels pbo prog_parameter -projtex quads random readrate @@ -65,22 +63,22 @@ readtex.c readtex.h rubberband seccolor -sharedtex shader_api shaderutil.c shaderutil.h +sharedtex stencil_twoside -stencil_wrap stencilwrap stencil_wrap +streaming_rect subtex subtexrate tex1d -texcmp texcompress2 +texdown texfilt -texgenmix texline +texobj texobjshare texrect texwrap -- cgit v1.2.3 From 3dfe672c851756e5ee09443dfafb1295c912da31 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 30 Apr 2009 17:03:54 -0600 Subject: demos: silence warning --- progs/demos/dinoshade.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/demos/dinoshade.c b/progs/demos/dinoshade.c index 41b19d5a92..cbf8751e25 100644 --- a/progs/demos/dinoshade.c +++ b/progs/demos/dinoshade.c @@ -382,7 +382,7 @@ static GLfloat floorShadow[4][4]; static void redraw(void) { - int start, end; + int start = 0, end = 0; if (reportSpeed) { start = glutGet(GLUT_ELAPSED_TIME); -- cgit v1.2.3 From 4d548bd069220677b12630cbab6f8c228e3d3a6b Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 29 Apr 2009 14:21:41 +0100 Subject: trivial: add line-flat.c --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/line-flat.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 progs/trivial/line-flat.c (limited to 'progs') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 69c71cbaf6..e255cdadc5 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -30,6 +30,7 @@ SOURCES = \ fs-tri.c \ line-clip.c \ line-cull.c \ + line-flat.c \ line-smooth.c \ line-stipple-wide.c \ line-userclip-clip.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 480630e210..0333418ad8 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -26,6 +26,7 @@ progs = [ 'fs-tri', 'line-clip', 'line-cull', + 'line-flat', 'line-smooth', 'line-stipple-wide', 'line-userclip-clip', diff --git a/progs/trivial/line-flat.c b/progs/trivial/line-flat.c new file mode 100644 index 0000000000..14f0ac0782 --- /dev/null +++ b/progs/trivial/line-flat.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + 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); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glShadeModel(GL_FLAT); + + glBegin(GL_LINES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + + + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 5f2569a1b997cf7577dc2d44e3670d0c55de905c Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 30 Apr 2009 12:35:59 +0100 Subject: progs/trivial: add vbo-noninterleaved test --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/vbo-noninterleaved.c | 139 +++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 progs/trivial/vbo-noninterleaved.c (limited to 'progs') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index e255cdadc5..69b0408bbd 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -139,6 +139,7 @@ SOURCES = \ tristrip-flat.c \ tristrip.c \ vbo-drawarrays.c \ + vbo-noninterleaved.c \ vbo-drawelements.c \ vbo-drawrange.c \ vp-array.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 0333418ad8..03ccb1436d 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -135,6 +135,7 @@ progs = [ 'tristrip-flat', 'tristrip', 'vbo-drawarrays', + 'vbo-noninterleaved', 'vbo-drawelements', 'vbo-drawrange', 'vp-array', diff --git a/progs/trivial/vbo-noninterleaved.c b/progs/trivial/vbo-noninterleaved.c new file mode 100644 index 0000000000..0672ca50ff --- /dev/null +++ b/progs/trivial/vbo-noninterleaved.c @@ -0,0 +1,139 @@ +/* Basic VBO */ + +#include +#include +#include +#include +#include +#include +#include + + +struct { + GLfloat pos[4][4]; + GLfloat col[4][4]; +} verts = +{ + /* Position: a quad + */ + { + { 0.9, -0.9, 0.0, 1.0 }, + { 0.9, 0.9, 0.0, 1.0 }, + { -0.9, 0.9, 0.0, 1.0 }, + { -0.9, -0.9, 0.0, 1.0 }, + }, + + /* Color: all red + */ + { + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + }, + + +}; + +GLuint arrayObj, elementObj; + +static void Init( void ) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "MOV result.color, vertex.color;\n" + "MOV result.position, vertex.position;\n" + "END\n"; + + glGenProgramsARB(1, &prognum); + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + assert(glIsProgramARB(prognum)); + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + glGenBuffersARB(1, &arrayObj); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), &verts, GL_STATIC_DRAW_ARB); + + glVertexPointer( 4, GL_FLOAT, sizeof(verts.pos[0]), 0 ); + glColorPointer( 4, GL_FLOAT, sizeof(verts.col[0]), (void *)(4*4*sizeof(float)) ); + +} + + + +static void Display( void ) +{ + glClearColor(0.3, 0.3, 0.3, 1); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glEnable(GL_VERTEX_PROGRAM_ARB); + +// glDrawArrays( GL_TRIANGLES, 0, 3 ); +// glDrawArrays( GL_TRIANGLES, 1, 3 ); + glDrawArrays( GL_QUADS, 0, 4 ); + + glFlush(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + /*glTranslatef( 0.0, 0.0, -15.0 );*/ +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 250, 250 ); + glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 077c904b76542dbe01b20386733d3e9e8a49da0b Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 5 May 2009 13:00:44 +0100 Subject: progs/trivial: add test for vertex program invarient transform --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/vp-tri-invariant.c | 147 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 progs/trivial/vp-tri-invariant.c (limited to 'progs') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 69b0408bbd..22de83fa79 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -147,6 +147,7 @@ SOURCES = \ vp-clip.c \ vp-line-clip.c \ vp-tri.c \ + vp-tri-invariant.c \ vp-tri-swap.c \ vp-tri-tex.c \ vp-tri-imm.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 03ccb1436d..9a1f3575bd 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -143,6 +143,7 @@ progs = [ 'vp-clip', 'vp-line-clip', 'vp-tri', + 'vp-tri-invariant', 'vp-tri-swap', 'vp-tri-tex', 'vp-tri-imm', diff --git a/progs/trivial/vp-tri-invariant.c b/progs/trivial/vp-tri-invariant.c new file mode 100644 index 0000000000..ff24139365 --- /dev/null +++ b/progs/trivial/vp-tri-invariant.c @@ -0,0 +1,147 @@ +/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */ + +#include +#include +#include +#include +#include +#include + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "OPTION ARB_position_invariant ;" + "MOV result.color, vertex.color;\n" + "END\n"; + + + glGenProgramsARB(1, &prognum); + + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + 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); */ + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glEnable(GL_VERTEX_PROGRAM_ARB); + + glBegin(GL_TRIANGLES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -0.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -0.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -0.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB | GLUT_ALPHA; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + glewInit(); + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 56cfa4de9150514af46d040c3cdb24def301b3a1 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Thu, 7 May 2009 14:15:24 -0600 Subject: demos: delete vertex array objects upon exit --- progs/demos/vao_demo.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'progs') diff --git a/progs/demos/vao_demo.c b/progs/demos/vao_demo.c index ce416712fe..206e06fc6c 100644 --- a/progs/demos/vao_demo.c +++ b/progs/demos/vao_demo.c @@ -260,6 +260,8 @@ static void Key( unsigned char key, int x, int y ) (void) y; switch (key) { case 27: + (*delete_vertex_arrays)( 1, & cube_array_obj ); + (*delete_vertex_arrays)( 1, & oct_array_obj ); glutDestroyWindow(Win); exit(0); break; -- cgit v1.2.3 From 482be01db02d3ea224e01c24c4d1638229d6a4dc Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 29 Apr 2009 14:21:41 +0100 Subject: trivial: add line-flat.c --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/line-flat.c | 147 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 progs/trivial/line-flat.c (limited to 'progs') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 69c71cbaf6..e255cdadc5 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -30,6 +30,7 @@ SOURCES = \ fs-tri.c \ line-clip.c \ line-cull.c \ + line-flat.c \ line-smooth.c \ line-stipple-wide.c \ line-userclip-clip.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 480630e210..0333418ad8 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -26,6 +26,7 @@ progs = [ 'fs-tri', 'line-clip', 'line-cull', + 'line-flat', 'line-smooth', 'line-stipple-wide', 'line-userclip-clip', diff --git a/progs/trivial/line-flat.c b/progs/trivial/line-flat.c new file mode 100644 index 0000000000..14f0ac0782 --- /dev/null +++ b/progs/trivial/line-flat.c @@ -0,0 +1,147 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + 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); + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + glShadeModel(GL_FLAT); + + glBegin(GL_LINES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -30.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + + + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -30.0); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -30.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From e99729d63d50dd7e1dffc8b739b6f9decc834925 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 30 Apr 2009 12:35:59 +0100 Subject: progs/trivial: add vbo-noninterleaved test --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/vbo-noninterleaved.c | 139 +++++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 progs/trivial/vbo-noninterleaved.c (limited to 'progs') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index e255cdadc5..69b0408bbd 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -139,6 +139,7 @@ SOURCES = \ tristrip-flat.c \ tristrip.c \ vbo-drawarrays.c \ + vbo-noninterleaved.c \ vbo-drawelements.c \ vbo-drawrange.c \ vp-array.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 0333418ad8..03ccb1436d 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -135,6 +135,7 @@ progs = [ 'tristrip-flat', 'tristrip', 'vbo-drawarrays', + 'vbo-noninterleaved', 'vbo-drawelements', 'vbo-drawrange', 'vp-array', diff --git a/progs/trivial/vbo-noninterleaved.c b/progs/trivial/vbo-noninterleaved.c new file mode 100644 index 0000000000..0672ca50ff --- /dev/null +++ b/progs/trivial/vbo-noninterleaved.c @@ -0,0 +1,139 @@ +/* Basic VBO */ + +#include +#include +#include +#include +#include +#include +#include + + +struct { + GLfloat pos[4][4]; + GLfloat col[4][4]; +} verts = +{ + /* Position: a quad + */ + { + { 0.9, -0.9, 0.0, 1.0 }, + { 0.9, 0.9, 0.0, 1.0 }, + { -0.9, 0.9, 0.0, 1.0 }, + { -0.9, -0.9, 0.0, 1.0 }, + }, + + /* Color: all red + */ + { + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + { 1.0, 0.0, 0.0, 1.0 }, + }, + + +}; + +GLuint arrayObj, elementObj; + +static void Init( void ) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "MOV result.color, vertex.color;\n" + "MOV result.position, vertex.position;\n" + "END\n"; + + glGenProgramsARB(1, &prognum); + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + assert(glIsProgramARB(prognum)); + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + + glEnableClientState( GL_VERTEX_ARRAY ); + glEnableClientState( GL_COLOR_ARRAY ); + + glGenBuffersARB(1, &arrayObj); + glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), &verts, GL_STATIC_DRAW_ARB); + + glVertexPointer( 4, GL_FLOAT, sizeof(verts.pos[0]), 0 ); + glColorPointer( 4, GL_FLOAT, sizeof(verts.col[0]), (void *)(4*4*sizeof(float)) ); + +} + + + +static void Display( void ) +{ + glClearColor(0.3, 0.3, 0.3, 1); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glEnable(GL_VERTEX_PROGRAM_ARB); + +// glDrawArrays( GL_TRIANGLES, 0, 3 ); +// glDrawArrays( GL_TRIANGLES, 1, 3 ); + glDrawArrays( GL_QUADS, 0, 4 ); + + glFlush(); +} + + +static void Reshape( int width, int height ) +{ + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + /*glTranslatef( 0.0, 0.0, -15.0 );*/ +} + + +static void Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 27: + exit(0); + break; + } + glutPostRedisplay(); +} + + + + +int main( int argc, char *argv[] ) +{ + glutInit( &argc, argv ); + glutInitWindowPosition( 0, 0 ); + glutInitWindowSize( 250, 250 ); + glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); + glutCreateWindow(argv[0]); + glewInit(); + glutReshapeFunc( Reshape ); + glutKeyboardFunc( Key ); + glutDisplayFunc( Display ); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From d56b0e6847255410ccb958068f0828fd2543aaba Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 5 May 2009 13:00:44 +0100 Subject: progs/trivial: add test for vertex program invarient transform --- progs/trivial/Makefile | 1 + progs/trivial/SConscript | 1 + progs/trivial/vp-tri-invariant.c | 147 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 progs/trivial/vp-tri-invariant.c (limited to 'progs') diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile index 69b0408bbd..22de83fa79 100644 --- a/progs/trivial/Makefile +++ b/progs/trivial/Makefile @@ -147,6 +147,7 @@ SOURCES = \ vp-clip.c \ vp-line-clip.c \ vp-tri.c \ + vp-tri-invariant.c \ vp-tri-swap.c \ vp-tri-tex.c \ vp-tri-imm.c \ diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript index 03ccb1436d..9a1f3575bd 100644 --- a/progs/trivial/SConscript +++ b/progs/trivial/SConscript @@ -143,6 +143,7 @@ progs = [ 'vp-clip', 'vp-line-clip', 'vp-tri', + 'vp-tri-invariant', 'vp-tri-swap', 'vp-tri-tex', 'vp-tri-imm', diff --git a/progs/trivial/vp-tri-invariant.c b/progs/trivial/vp-tri-invariant.c new file mode 100644 index 0000000000..ff24139365 --- /dev/null +++ b/progs/trivial/vp-tri-invariant.c @@ -0,0 +1,147 @@ +/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */ + +#include +#include +#include +#include +#include +#include + + +#define CI_OFFSET_1 16 +#define CI_OFFSET_2 32 + + +GLenum doubleBuffer; + +static void Init(void) +{ + GLint errno; + GLuint prognum; + + static const char *prog1 = + "!!ARBvp1.0\n" + "OPTION ARB_position_invariant ;" + "MOV result.color, vertex.color;\n" + "END\n"; + + + glGenProgramsARB(1, &prognum); + + glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); + glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, + strlen(prog1), (const GLubyte *) prog1); + + errno = glGetError(); + printf("glGetError = %d\n", errno); + if (errno != GL_NO_ERROR) + { + GLint errorpos; + + glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); + printf("errorpos: %d\n", errorpos); + printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); + } + + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + 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); */ + glMatrixMode(GL_MODELVIEW); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + return; + } + + glutPostRedisplay(); +} + +static void Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glEnable(GL_VERTEX_PROGRAM_ARB); + + glBegin(GL_TRIANGLES); + glColor3f(0,0,.7); + glVertex3f( 0.9, -0.9, -0.0); + glColor3f(.8,0,0); + glVertex3f( 0.9, 0.9, -0.0); + glColor3f(0,.9,0); + glVertex3f(-0.9, 0.0, -0.0); + glEnd(); + + glFlush(); + + if (doubleBuffer) { + glutSwapBuffers(); + } +} + +static GLenum Args(int argc, char **argv) +{ + GLint i; + + doubleBuffer = GL_FALSE; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-sb") == 0) { + doubleBuffer = GL_FALSE; + } else if (strcmp(argv[i], "-db") == 0) { + doubleBuffer = GL_TRUE; + } else { + fprintf(stderr, "%s (Bad option).\n", argv[i]); + return GL_FALSE; + } + } + return GL_TRUE; +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + if (Args(argc, argv) == GL_FALSE) { + exit(1); + } + + glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); + + type = GLUT_RGB | GLUT_ALPHA; + type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + glewInit(); + Init(); + + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From f5cf181c65293fd9097f63192c09f44b9c82c633 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 11 May 2009 16:08:01 -0600 Subject: trivial: destroy window upon exit --- progs/trivial/tri.c | 1 + 1 file changed, 1 insertion(+) (limited to 'progs') diff --git a/progs/trivial/tri.c b/progs/trivial/tri.c index d44cb6a9fe..cac3fcb7d9 100644 --- a/progs/trivial/tri.c +++ b/progs/trivial/tri.c @@ -60,6 +60,7 @@ static void Key(unsigned char key, int x, int y) { switch (key) { case 27: + glutDestroyWindow(win); exit(0); default: glutPostRedisplay(); -- cgit v1.2.3 From 723bc9452fee2602fa702699141e91b87872e621 Mon Sep 17 00:00:00 2001 From: Joakim Sindholt Date: Tue, 12 May 2009 19:38:17 +0200 Subject: progs/trivial: update .gitignore with new binaries --- progs/trivial/.gitignore | 3 +++ 1 file changed, 3 insertions(+) (limited to 'progs') diff --git a/progs/trivial/.gitignore b/progs/trivial/.gitignore index 8dcb20a68f..dce733a70a 100644 --- a/progs/trivial/.gitignore +++ b/progs/trivial/.gitignore @@ -19,6 +19,7 @@ fs-tri line line-clip line-cull +line-flat line-smooth line-stipple-wide line-userclip @@ -130,6 +131,7 @@ tristrip-flat vbo-drawarrays vbo-drawelements vbo-drawrange +vbo-noninterleaved vp-array vp-array-int vp-clip @@ -139,6 +141,7 @@ vp-tri-cb vp-tri-cb-pos vp-tri-cb-tex vp-tri-imm +vp-tri-invariant vp-tri-swap vp-tri-tex vp-unfilled -- cgit v1.2.3 From 58fadc624281b3f0bbe084e3e8af28a61036ca94 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 22 May 2009 13:00:49 -0600 Subject: demos: fix multitex.c VertCoord attribute mapping If the multitex.vert shader uses the VertCoord generic vertex attribute instead of the pre-defined gl_Vertex attribute, we need to make sure that VertCoord gets bound to generic vertex attribute zero. That's because we need to call glVertexAttrib2fv(0, xy) after all the other vertex attributes have been set since setting generic attribute 0 triggers vertex submission. Before, we wound up issuing the vertex attributes in the order 0, 1, 2 which caused the first vertex to be submitted before all the attributes were set. Now, the attributes are set in 1, 2, 0 order. --- progs/glsl/multitex.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/glsl/multitex.c b/progs/glsl/multitex.c index b4be463787..bbf58af055 100644 --- a/progs/glsl/multitex.c +++ b/progs/glsl/multitex.c @@ -271,9 +271,24 @@ CreateProgram(const char *vertProgFile, const char *fragProgFile, InitUniforms(program, uniforms); + VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + if (VertCoord_attr > 0) { + /* We want the VertCoord attrib to have position zero so that + * the call to glVertexAttrib(0, xyz) triggers vertex processing. + * Otherwise, if TexCoord0 or TexCoord1 gets position 0 we'd have + * to set that attribute last (which is a PITA to manage). + */ + glBindAttribLocation_func(program, 0, "VertCoord"); + /* re-link */ + glLinkProgram_func(program); + /* VertCoord_attr should be zero now */ + VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + assert(VertCoord_attr == 0); + } + TexCoord0_attr = glGetAttribLocation_func(program, "TexCoord0"); TexCoord1_attr = glGetAttribLocation_func(program, "TexCoord1"); - VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + printf("TexCoord0_attr = %d\n", TexCoord0_attr); printf("TexCoord1_attr = %d\n", TexCoord1_attr); printf("VertCoord_attr = %d\n", VertCoord_attr); -- cgit v1.2.3 From 96370113f1a3580ed2a8ef2fb427f37afd7432f8 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 22 May 2009 13:12:01 -0600 Subject: demos/util: add funcs for GL_ARB_buffer_object --- progs/util/extfuncs.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'progs') diff --git a/progs/util/extfuncs.h b/progs/util/extfuncs.h index 070414e294..238794d55a 100644 --- a/progs/util/extfuncs.h +++ b/progs/util/extfuncs.h @@ -86,6 +86,15 @@ static PFNGLISVERTEXARRAYAPPLEPROC glIsVertexArrayAPPLE_func = NULL; /* GL_EXT_stencil_two_side */ static PFNGLACTIVESTENCILFACEEXTPROC glActiveStencilFaceEXT_func = NULL; +/* GL_ARB_buffer_object */ +static PFNGLGENBUFFERSARBPROC glGenBuffersARB_func = NULL; +static PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB_func = NULL; +static PFNGLBINDBUFFERARBPROC glBindBufferARB_func = NULL; +static PFNGLBUFFERDATAARBPROC glBufferDataARB_func = NULL; +static PFNGLBUFFERSUBDATAARBPROC glBufferSubDataARB_func = NULL; +static PFNGLMAPBUFFERARBPROC glMapBufferARB_func = NULL; +static PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB_func = NULL; + static void GetExtensionFuncs(void) @@ -173,5 +182,15 @@ GetExtensionFuncs(void) /* GL_EXT_stencil_two_side */ glActiveStencilFaceEXT_func = (PFNGLACTIVESTENCILFACEEXTPROC) glutGetProcAddress("glActiveStencilFaceEXT"); + + /* GL_ARB_vertex_buffer_object */ + glGenBuffersARB_func = (PFNGLGENBUFFERSARBPROC) glutGetProcAddress("glGenBuffersARB"); + glDeleteBuffersARB_func = (PFNGLDELETEBUFFERSARBPROC) glutGetProcAddress("glDeleteBuffersARB"); + glBindBufferARB_func = (PFNGLBINDBUFFERARBPROC) glutGetProcAddress("glBindBufferARB"); + glBufferDataARB_func = (PFNGLBUFFERDATAARBPROC) glutGetProcAddress("glBufferDataARB"); + glBufferSubDataARB_func = (PFNGLBUFFERSUBDATAARBPROC) glutGetProcAddress("glBufferSubDataARB"); + glMapBufferARB_func = (PFNGLMAPBUFFERARBPROC) glutGetProcAddress("glMapBufferARB"); + glUnmapBufferARB_func = (PFNGLUNMAPBUFFERARBPROC) glutGetProcAddress("glUnmapBufferARB"); + } -- cgit v1.2.3 From 891a2bdd7d11086712500cf916efbc1b733f094b Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 22 May 2009 13:12:28 -0600 Subject: demos: extend glsl/multitex.c to use a vertex buffer object --- progs/glsl/multitex.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 6 deletions(-) (limited to 'progs') diff --git a/progs/glsl/multitex.c b/progs/glsl/multitex.c index b4be463787..1a1c63aaf4 100644 --- a/progs/glsl/multitex.c +++ b/progs/glsl/multitex.c @@ -51,6 +51,8 @@ static GLfloat Xrot = 0.0, Yrot = .0, Zrot = 0.0; static GLfloat EyeDist = 10; static GLboolean Anim = GL_TRUE; static GLboolean UseArrays = GL_TRUE; +static GLboolean UseVBO = GL_TRUE; +static GLuint VBO = 0; static GLint VertCoord_attr = -1, TexCoord0_attr = -1, TexCoord1_attr = -1; @@ -76,28 +78,81 @@ static const GLfloat VertCoords[4][2] = { }; + +static void +SetupVertexBuffer(void) +{ + glGenBuffersARB_func(1, &VBO); + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, VBO); + + glBufferDataARB_func(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords) + + sizeof(Tex0Coords) + + sizeof(Tex1Coords), + NULL, + GL_STATIC_DRAW_ARB); + + /* non-interleaved vertex arrays */ + + glBufferSubDataARB_func(GL_ARRAY_BUFFER_ARB, + 0, /* offset */ + sizeof(VertCoords), /* size */ + VertCoords); /* data */ + + glBufferSubDataARB_func(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords), /* offset */ + sizeof(Tex0Coords), /* size */ + Tex0Coords); /* data */ + + glBufferSubDataARB_func(GL_ARRAY_BUFFER_ARB, + sizeof(VertCoords) + + sizeof(Tex0Coords), /* offset */ + sizeof(Tex1Coords), /* size */ + Tex1Coords); /* data */ + + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, 0); +} + + static void DrawPolygonArray(void) { + void *vertPtr, *tex0Ptr, *tex1Ptr; + + if (UseVBO) { + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, VBO); + vertPtr = (void *) 0; + tex0Ptr = (void *) sizeof(VertCoords); + tex1Ptr = (void *) (sizeof(VertCoords) + sizeof(Tex0Coords)); + } + else { + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, 0); + vertPtr = VertCoords; + tex0Ptr = Tex0Coords; + tex1Ptr = Tex1Coords; + } + if (VertCoord_attr >= 0) { glVertexAttribPointer_func(VertCoord_attr, 2, GL_FLOAT, GL_FALSE, - 0, VertCoords); + 0, vertPtr); glEnableVertexAttribArray_func(VertCoord_attr); } else { - glVertexPointer(2, GL_FLOAT, 0, VertCoords); + glVertexPointer(2, GL_FLOAT, 0, vertPtr); glEnable(GL_VERTEX_ARRAY); } glVertexAttribPointer_func(TexCoord0_attr, 2, GL_FLOAT, GL_FALSE, - 0, Tex0Coords); + 0, tex0Ptr); glEnableVertexAttribArray_func(TexCoord0_attr); glVertexAttribPointer_func(TexCoord1_attr, 2, GL_FLOAT, GL_FALSE, - 0, Tex1Coords); + 0, tex1Ptr); glEnableVertexAttribArray_func(TexCoord1_attr); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + + glBindBufferARB_func(GL_ARRAY_BUFFER_ARB, 0); } @@ -163,6 +218,10 @@ key(unsigned char k, int x, int y) UseArrays = !UseArrays; printf("Arrays: %d\n", UseArrays); break; + case 'v': + UseVBO = !UseVBO; + printf("Use VBO: %d\n", UseVBO); + break; case ' ': Anim = !Anim; if (Anim) @@ -271,9 +330,24 @@ CreateProgram(const char *vertProgFile, const char *fragProgFile, InitUniforms(program, uniforms); + VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + if (VertCoord_attr > 0) { + /* We want the VertCoord attrib to have position zero so that + * the call to glVertexAttrib(0, xyz) triggers vertex processing. + * Otherwise, if TexCoord0 or TexCoord1 gets position 0 we'd have + * to set that attribute last (which is a PITA to manage). + */ + glBindAttribLocation_func(program, 0, "VertCoord"); + /* re-link */ + glLinkProgram_func(program); + /* VertCoord_attr should be zero now */ + VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + assert(VertCoord_attr == 0); + } + TexCoord0_attr = glGetAttribLocation_func(program, "TexCoord0"); TexCoord1_attr = glGetAttribLocation_func(program, "TexCoord1"); - VertCoord_attr = glGetAttribLocation_func(program, "VertCoord"); + printf("TexCoord0_attr = %d\n", TexCoord0_attr); printf("TexCoord1_attr = %d\n", TexCoord1_attr); printf("VertCoord_attr = %d\n", VertCoord_attr); @@ -299,12 +373,19 @@ InitGL(void) /*exit(1);*/ } printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER)); - + printf("Usage:\n"); + printf(" a - toggle arrays vs. immediate mode rendering\n"); + printf(" v - toggle VBO usage for array rendering\n"); + printf(" z/Z - change viewing distance\n"); + printf(" SPACE - toggle animation\n"); + printf(" Esc - exit\n"); GetExtensionFuncs(); InitTextures(); InitPrograms(); + SetupVertexBuffer(); + glEnable(GL_DEPTH_TEST); glClearColor(.6, .6, .9, 0); -- cgit v1.2.3 From 5be48307d55120311b13433eaa9af09d07e233e0 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 27 May 2009 19:37:32 -0600 Subject: demos: remove some old debug/test code --- progs/samples/prim.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'progs') diff --git a/progs/samples/prim.c b/progs/samples/prim.c index f47c60faef..c04750725f 100644 --- a/progs/samples/prim.c +++ b/progs/samples/prim.c @@ -466,25 +466,22 @@ static void Draw(void) } else { glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); } -#if 01 + Viewport(0, 0); Point(); Viewport(0, 1); Lines(); Viewport(0, 2); LineStrip(); Viewport(0, 3); LineLoop(); Viewport(1, 0); Bitmap(); - Viewport(1, 1); TriangleFan(); Viewport(1, 2); Triangles(); Viewport(1, 3); TriangleStrip(); Viewport(2, 0); Rect(); -#endif Viewport(2, 1); PolygonFunc(); -#if 01 Viewport(2, 2); Quads(); Viewport(2, 3); QuadStrip(); -#endif + glFlush(); if (doubleBuffer) { -- cgit v1.2.3 From 85e0572756b85b7025740fbbefb673cf75a46cea Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Mon, 1 Jun 2009 11:20:05 +0100 Subject: progs/rbug: Add small remote debugging cli applications --- progs/rbug/.gitignore | 9 ++++ progs/rbug/Makefile | 46 ++++++++++++++++ progs/rbug/README | 39 ++++++++++++++ progs/rbug/ctx_info.c | 80 ++++++++++++++++++++++++++++ progs/rbug/shdr_disable.c | 82 +++++++++++++++++++++++++++++ progs/rbug/shdr_dump.c | 115 ++++++++++++++++++++++++++++++++++++++++ progs/rbug/shdr_info.c | 98 ++++++++++++++++++++++++++++++++++ progs/rbug/simple_client.c | 64 +++++++++++++++++++++++ progs/rbug/simple_server.c | 62 ++++++++++++++++++++++ progs/rbug/tex_dump.c | 127 +++++++++++++++++++++++++++++++++++++++++++++ progs/rbug/tex_info.c | 78 ++++++++++++++++++++++++++++ 11 files changed, 800 insertions(+) create mode 100644 progs/rbug/.gitignore create mode 100644 progs/rbug/Makefile create mode 100644 progs/rbug/README create mode 100644 progs/rbug/ctx_info.c create mode 100644 progs/rbug/shdr_disable.c create mode 100644 progs/rbug/shdr_dump.c create mode 100644 progs/rbug/shdr_info.c create mode 100644 progs/rbug/simple_client.c create mode 100644 progs/rbug/simple_server.c create mode 100644 progs/rbug/tex_dump.c create mode 100644 progs/rbug/tex_info.c (limited to 'progs') diff --git a/progs/rbug/.gitignore b/progs/rbug/.gitignore new file mode 100644 index 0000000000..317290bbb3 --- /dev/null +++ b/progs/rbug/.gitignore @@ -0,0 +1,9 @@ +simple_client +simple_server +shdr_info +shdr_dump +shdr_disable +ctx_info +tex_dump +tex_info +*.bmp diff --git a/progs/rbug/Makefile b/progs/rbug/Makefile new file mode 100644 index 0000000000..8df03dd4e1 --- /dev/null +++ b/progs/rbug/Makefile @@ -0,0 +1,46 @@ +# progs/rbug/Makefile + +TOP = ../.. +include $(TOP)/configs/current + +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + $(PROG_INCLUDES) + +LINKS = \ + $(GALLIUM_AUXILIARIES) \ + $(PROG_LINKS) + +SOURCES = \ + simple_client.c \ + simple_server.c \ + shdr_info.c \ + shdr_dump.c \ + shdr_disable.c \ + ctx_info.c \ + tex_info.c \ + tex_dump.c + + +OBJECTS = $(SOURCES:.c=.o) + +PROGS = $(OBJECTS:.o=) + +##### TARGETS ##### + +default: $(OBJECTS) $(PROGS) + +clean: + -rm -f $(PROGS) + -rm -f *.o + +##### RULES ##### + +$(OBJECTS): %.o: %.c + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $(PROG_DEFINES) $< -o $@ + +$(PROGS): %: %.o + $(CC) $(LDFLAGS) $< $(LINKS) -o $@ diff --git a/progs/rbug/README b/progs/rbug/README new file mode 100644 index 0000000000..0eb0a5de9a --- /dev/null +++ b/progs/rbug/README @@ -0,0 +1,39 @@ + REMOTE DEBUGGING CLI APPLICATIONS + + += About = + +This directory contains a Gallium3D remote debugging cli applications. + + += Build Instructions = + +To build, build a normal gallium build and from this directory do the following. + + make + += Usage = + +Make sure that you driver has trace integration, see +src/gallium/driver/trace/README for more information about that. Then from on +the computer that you want to debug do: + + export GALLIUM_RBUG=true + + + +From the debugging computer launch apps form this directory. Currently ip +addresses are hardcoded and you need to edit the application, but that will +change in the future. + += Testing = + +The two apps simple_client and simple_server. Are unit testing of the +connection and (de)marsheler. Just run the server first and then the client: + + ./simple_server & + ./simple_client + + +-- +Jakob Bornecrantz diff --git a/progs/rbug/ctx_info.c b/progs/rbug/ctx_info.c new file mode 100644 index 0000000000..d72c326719 --- /dev/null +++ b/progs/rbug/ctx_info.c @@ -0,0 +1,80 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + struct rbug_proto_context_info_reply *info; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { +#if 0 + rbug_send_contexts_info(con, list->contexts[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_INFO_REPLY); + info = (struct rbug_proto_context_info_reply *)header; +#else + (void)info; + header = NULL; +#endif + + debug_printf("%llu\n", + (unsigned long long)list->contexts[i]); + rbug_free_header(header); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/shdr_disable.c b/progs/rbug/shdr_disable.c new file mode 100644 index 0000000000..e6b12073d8 --- /dev/null +++ b/progs/rbug/shdr_disable.c @@ -0,0 +1,82 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk(rbug_context_t ctx, rbug_shader_t shdr) +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + rbug_send_shader_disable(con, ctx, shdr, true, NULL); + + rbug_send_ping(con, NULL); + + debug_printf("Sent waiting for reply\n"); + header = rbug_get_message(con, NULL); + + if (header->opcode != RBUG_OP_PING_REPLY) + debug_printf("Error\n"); + else + debug_printf("Ok!\n"); + + rbug_free_header(header); + rbug_disconnect(con); +} + +static void print_usage() +{ + printf("Usage shdr_disable \n"); + exit(-1); +} + +int main(int argc, char** argv) +{ + long ctx; + long shdr; + + if (argc < 3) + print_usage(); + + ctx = atol(argv[1]); + shdr = atol(argv[2]); + + if (ctx <= 0 && ctx <= 0) + print_usage(); + + talk((uint64_t)ctx, (uint64_t)shdr); + + return 0; +} diff --git a/progs/rbug/shdr_dump.c b/progs/rbug/shdr_dump.c new file mode 100644 index 0000000000..8f9d758d51 --- /dev/null +++ b/progs/rbug/shdr_dump.c @@ -0,0 +1,115 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +#include "tgsi/tgsi_dump.h" + +static void shader_info(struct rbug_connection *con, rbug_context_t ctx) +{ + struct rbug_header *header; + struct rbug_proto_shader_list_reply *list; + struct rbug_proto_shader_info_reply *info; + int i; + + debug_printf("Sending get shaders to %llu\n", (unsigned long long)ctx); + rbug_send_shader_list(con, ctx, NULL); + + debug_printf("Waiting for shaders from %llu\n", (unsigned long long)ctx); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_LIST_REPLY); + list = (struct rbug_proto_shader_list_reply *)header; + + debug_printf("Got shaders:\n"); + for (i = 0; i < list->shaders_len; i++) { + rbug_send_shader_info(con, ctx, list->shaders[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_INFO_REPLY); + info = (struct rbug_proto_shader_info_reply *)header; + + debug_printf("#####################################################\n"); + debug_printf("ctx: %llu shdr: %llu disabled %u\n", + (unsigned long long)ctx, + (unsigned long long)list->shaders[i], + info->disabled); + + /* just to be sure */ + assert(sizeof(struct tgsi_token) == 4); + + debug_printf("-----------------------------------------------------\n"); + tgsi_dump((struct tgsi_token *)info->original, 0); + + if (info->replaced_len > 0) { + debug_printf("-----------------------------------------------------\n"); + tgsi_dump((struct tgsi_token *)info->replaced, 0); + } + + rbug_free_header(header); + } + + debug_printf("#####################################################\n"); + rbug_free_header(&list->header); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { + shader_info(con, list->contexts[i]); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/shdr_info.c b/progs/rbug/shdr_info.c new file mode 100644 index 0000000000..b6864e988e --- /dev/null +++ b/progs/rbug/shdr_info.c @@ -0,0 +1,98 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void shader_info(struct rbug_connection *con, rbug_context_t ctx) +{ + struct rbug_header *header; + struct rbug_proto_shader_list_reply *list; + struct rbug_proto_shader_info_reply *info; + int i; + + rbug_send_shader_list(con, ctx, NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_LIST_REPLY); + list = (struct rbug_proto_shader_list_reply *)header; + + debug_printf(" context | shader | disabled |\n"); + for (i = 0; i < list->shaders_len; i++) { + rbug_send_shader_info(con, ctx, list->shaders[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_SHADER_INFO_REPLY); + info = (struct rbug_proto_shader_info_reply *)header; + + debug_printf("% 15llu |% 15llu |% 15u |\n", + (unsigned long long)ctx, + (unsigned long long)list->shaders[i], + (unsigned)info->disabled); + + rbug_free_header(header); + } + + rbug_free_header(&list->header); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_context_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get contexts\n"); + rbug_send_context_list(con, NULL); + + debug_printf("Waiting for contexts\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_CONTEXT_LIST_REPLY); + list = (struct rbug_proto_context_list_reply *)header; + + debug_printf("Got contexts:\n"); + for (i = 0; i < list->contexts_len; i++) { + shader_info(con, list->contexts[i]); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/simple_client.c b/progs/rbug/simple_client.c new file mode 100644 index 0000000000..38929fa796 --- /dev/null +++ b/progs/rbug/simple_client.c @@ -0,0 +1,64 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_texture_list_reply *list; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) + debug_printf("\ttex %llu\n", (unsigned long long)list->textures[i]); + + rbug_free_header(header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/simple_server.c b/progs/rbug/simple_server.c new file mode 100644 index 0000000000..04380c3310 --- /dev/null +++ b/progs/rbug/simple_server.c @@ -0,0 +1,62 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void wait() +{ + int s = u_socket_listen_on_port(13370); + int c = u_socket_accept(s); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + rbug_texture_t texs[2]; + uint32_t serial; + texs[0] = 1337; + texs[1] = 7331; + + assert(s >= 0); + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Waiting for get textures\n"); + header = rbug_get_message(con, &serial); + assert(header); + assert(header->opcode == RBUG_OP_TEXTURE_LIST); + rbug_free_header(header); + + rbug_send_texture_list_reply(con, serial, texs, 2, NULL); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + wait(); + return 0; +} diff --git a/progs/rbug/tex_dump.c b/progs/rbug/tex_dump.c new file mode 100644 index 0000000000..f9e06ee994 --- /dev/null +++ b/progs/rbug/tex_dump.c @@ -0,0 +1,127 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" +#include "util/u_tile.h" +#include "rbug/rbug.h" + +static void dump(rbug_texture_t tex, + struct rbug_proto_texture_info_reply *info, + struct rbug_proto_texture_read_reply *read, + int mip) +{ + enum pipe_format format = info->format; + uint8_t *data = read->data; + unsigned width = info->width[mip]; + unsigned height = info->height[mip]; + unsigned dst_stride = width * 4 * 4; + unsigned src_stride = read->stride; + float *rgba = MALLOC(dst_stride * height); + int i; + char filename[512]; + + util_snprintf(filename, 512, "%llu_%s_%u.bmp", + (unsigned long long)tex, pf_name(info->format), mip); + + if (pf_is_compressed(info->format)) { + debug_printf("skipping: %s\n", filename); + return; + } + + debug_printf("saving: %s\n", filename); + + for (i = 0; i < height; i++) { + pipe_tile_raw_to_rgba(format, data + src_stride * i, + width, 1, + &rgba[width*4*i], dst_stride); + } + + debug_dump_float_rgba_bmp(filename, width, height, rgba, width); + + FREE(rgba); +} + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_header *header2; + struct rbug_proto_texture_list_reply *list; + struct rbug_proto_texture_info_reply *info; + struct rbug_proto_texture_read_reply *read; + int i, j; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) { + rbug_send_texture_info(con, list->textures[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY); + info = (struct rbug_proto_texture_info_reply *)header; + + for (j = 0; j <= info->last_level; j++) { + rbug_send_texture_read(con, list->textures[i], + 0, j, 0, + 0, 0, info->width[j], info->height[j], + NULL); + + header2 = rbug_get_message(con, NULL); + assert(header2->opcode == RBUG_OP_TEXTURE_READ_REPLY); + read = (struct rbug_proto_texture_read_reply *)header2; + + dump(list->textures[i], info, read, j); + + rbug_free_header(header2); + } + + rbug_free_header(header); + + } + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} diff --git a/progs/rbug/tex_info.c b/progs/rbug/tex_info.c new file mode 100644 index 0000000000..4a21bae359 --- /dev/null +++ b/progs/rbug/tex_info.c @@ -0,0 +1,78 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" + +#include "rbug/rbug.h" + +static void talk() +{ + int c = u_socket_connect("localhost", 13370); + struct rbug_connection *con = rbug_from_socket(c); + struct rbug_header *header; + struct rbug_proto_texture_list_reply *list; + struct rbug_proto_texture_info_reply *info; + int i; + + assert(c >= 0); + assert(con); + debug_printf("Connection get!\n"); + + debug_printf("Sending get textures\n"); + rbug_send_texture_list(con, NULL); + + debug_printf("Waiting for textures\n"); + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_LIST_REPLY); + list = (struct rbug_proto_texture_list_reply *)header; + + debug_printf("Got textures:\n"); + for (i = 0; i < list->textures_len; i++) { + rbug_send_texture_info(con, list->textures[i], NULL); + + header = rbug_get_message(con, NULL); + assert(header->opcode == RBUG_OP_TEXTURE_INFO_REPLY); + info = (struct rbug_proto_texture_info_reply *)header; + + debug_printf("%llu %s %u x %u x %u, block(%ux%u %u), last_level: %u, nr_samples: %u, usage: %u\n", + (unsigned long long)list->textures[i], pf_name(info->format), + info->width[0], info->height[0], info->depth[0], + info->blockw, info->blockh, info->blocksize, + info->last_level, info->nr_samples, info->tex_usage); + rbug_free_header(header); + } + + rbug_free_header(&list->header); + rbug_disconnect(con); +} + +int main(int argc, char** argv) +{ + talk(); + return 0; +} -- cgit v1.2.3 From a5d033e89bab6c5e913cd2ca17df02e56b5fe31d Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Mon, 1 Jun 2009 11:23:39 -0600 Subject: demos: add missing dependencies for util files --- progs/glsl/Makefile | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'progs') diff --git a/progs/glsl/Makefile b/progs/glsl/Makefile index 71db895d1d..f97cdb6942 100644 --- a/progs/glsl/Makefile +++ b/progs/glsl/Makefile @@ -80,25 +80,26 @@ clean: -rm -f *.o *~ -rm -f extfuncs.h -rm -f shaderutil.* + -rm -f readtex.* ##### Extra dependencies -extfuncs.h: - cp $(TOP)/progs/util/extfuncs.h . +extfuncs.h: $(TOP)/progs/util/extfuncs.h + cp $< . -readtex.c: - cp $(TOP)/progs/util/readtex.c . +readtex.c: $(TOP)/progs/util/readtex.c + cp $< . -readtex.h: - cp $(TOP)/progs/util/readtex.h . +readtex.h: $(TOP)/progs/util/readtex.h + cp $< . -shaderutil.c: - cp $(TOP)/progs/util/shaderutil.c . +shaderutil.c: $(TOP)/progs/util/shaderutil.c + cp $< . -shaderutil.h: - cp $(TOP)/progs/util/shaderutil.h . +shaderutil.h: $(TOP)/progs/util/shaderutil.h + cp $< . -- cgit v1.2.3 From 76ad2b4a5a38389ed733d1bf31a6cbba1881dc10 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 14 May 2009 13:28:09 +0100 Subject: progs/wgl: Use an invisible window in wglinfo. --- progs/wgl/wglinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/wgl/wglinfo.c b/progs/wgl/wglinfo.c index 881d35b297..43a216da18 100644 --- a/progs/wgl/wglinfo.c +++ b/progs/wgl/wglinfo.c @@ -364,7 +364,7 @@ print_screen_info(HDC _hdc, GLboolean limits) win = CreateWindowEx(0, wc.lpszClassName, "wglinfo", - WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, width, -- cgit v1.2.3 From 3c756ed39f93bd26bc81f6e3be0440429ad58c40 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 14 May 2009 15:32:10 +0100 Subject: progs/wgl: Small cleanup to wglinfo. --- progs/wgl/wglinfo.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'progs') diff --git a/progs/wgl/wglinfo.c b/progs/wgl/wglinfo.c index 43a216da18..864372c2f9 100644 --- a/progs/wgl/wglinfo.c +++ b/progs/wgl/wglinfo.c @@ -348,7 +348,6 @@ print_screen_info(HDC _hdc, GLboolean limits) HWND win; HGLRC ctx; int visinfo; - int width = 100, height = 100; HDC hdc; PIXELFORMATDESCRIPTOR pfd; @@ -367,15 +366,15 @@ print_screen_info(HDC _hdc, GLboolean limits) WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, - width, - height, + CW_USEDEFAULT, + CW_USEDEFAULT, NULL, NULL, wc.hInstance, NULL); if (!win) { fprintf(stderr, "Couldn't create window"); - exit(1); + return; } hdc = GetDC(win); @@ -476,7 +475,7 @@ print_visual_attribs_verbose(int iPixelFormat, LPPIXELFORMATDESCRIPTOR ppfd) ppfd->dwFlags & PFD_DRAW_TO_WINDOW ? 1 : 0); printf(" bufferSize=%d level=%d renderType=%s doubleBuffer=%d stereo=%d\n", 0 /* ppfd->bufferSize */, 0 /* ppfd->level */, - visual_render_type_name(ppfd->dwFlags), + visual_render_type_name(ppfd->iPixelType), ppfd->dwFlags & PFD_DOUBLEBUFFER ? 1 : 0, ppfd->dwFlags & PFD_STEREO ? 1 : 0); printf(" rgba: cRedBits=%d cGreenBits=%d cBlueBits=%d cAlphaBits=%d\n", -- cgit v1.2.3 From 00e7a600776ceb589bd5939ccd8aad937527db81 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Wed, 13 May 2009 13:47:38 +0100 Subject: trivial/tri-z: add controls for depthrange min/max Also add key to set up quake-1 style ztrick rendering with clear depth 1.0, deptrange(1.0, 0.0) and depthfunc GL_GREATER. --- progs/trivial/tri-z.c | 50 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 10 deletions(-) (limited to 'progs') diff --git a/progs/trivial/tri-z.c b/progs/trivial/tri-z.c index 335d2b90e2..014aaa071a 100644 --- a/progs/trivial/tri-z.c +++ b/progs/trivial/tri-z.c @@ -57,13 +57,19 @@ static struct { GLenum func; const char *str; } funcs[] = static int curFunc = 0; static double clearVal = 1.0; - +static float minZ = 0.0; +static float maxZ = 1.0; static void usage(void) { - printf("t - toggle rendering order of triangles\n"); - printf("c - toggle Z clear value between 0, 1\n"); - printf("f - cycle through depth test functions\n"); + printf("t - toggle rendering order of triangles\n"); + printf("c - toggle Z clear value between 0, 1\n"); + printf("f - cycle through depth test functions\n"); + printf("n/N - decrease/increase depthrange minZ\n"); + printf("x/X - decrease/increase depthrange maxZ\n"); + printf("spc - reset\n"); + printf("z - set to reverse-direction (ztrick) mode\n"); + fflush(stdout); } @@ -97,9 +103,11 @@ static void drawRightTriangle(void) void display(void) { - printf("GL_CLEAR_DEPTH = %f GL_DEPTH_FUNC = %s\n", - clearVal, funcs[curFunc].str); + printf("GL_CLEAR_DEPTH = %.2f, GL_DEPTH_FUNC = %s, DepthRange(%.1f, %.1f)\n", + clearVal, funcs[curFunc].str, minZ, maxZ); + fflush(stdout); glClearDepth(clearVal); + glDepthRange(minZ, maxZ); glDepthFunc(funcs[curFunc].func); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -131,27 +139,49 @@ void reshape(int w, int h) void keyboard(unsigned char key, int x, int y) { switch (key) { + case 'n': + minZ -= .1; + break; + case 'N': + minZ += .1; + break; + case 'x': + maxZ -= .1; + break; + case 'X': + maxZ += .1; + break; case 'c': case 'C': clearVal = 1.0 - clearVal; - glutPostRedisplay(); break; case 'f': case 'F': curFunc = (curFunc + 1) % NUM_FUNCS; - glutPostRedisplay(); break; case 't': case 'T': leftFirst = !leftFirst; - glutPostRedisplay(); + break; + case ' ': + curFunc = 0; + clearVal = 1.0; + minZ = 0.0; + maxZ = 1.0; + break; + case 'z': + curFunc = 2; + clearVal = 0.0; + minZ = 1.0; + maxZ = 0.0; break; case 27: /* Escape key */ exit(0); break; default: - break; + return; } + glutPostRedisplay(); } /* Main Loop -- cgit v1.2.3 From 97f5953ced6938ca8e92cde62e8717ff505cc4e2 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Thu, 14 May 2009 15:57:27 +0100 Subject: progs/vpglsl: add similar support for point rendering as progs/vp --- progs/vpglsl/psiz-imm.glsl | 6 +++++ progs/vpglsl/psiz-mul.glsl | 6 +++++ progs/vpglsl/vp-tris.c | 58 +++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 progs/vpglsl/psiz-imm.glsl create mode 100644 progs/vpglsl/psiz-mul.glsl (limited to 'progs') diff --git a/progs/vpglsl/psiz-imm.glsl b/progs/vpglsl/psiz-imm.glsl new file mode 100644 index 0000000000..101d314d58 --- /dev/null +++ b/progs/vpglsl/psiz-imm.glsl @@ -0,0 +1,6 @@ + +void main() { + gl_FrontColor = gl_Color; + gl_PointSize = 2.0; + gl_Position = gl_Vertex; +} diff --git a/progs/vpglsl/psiz-mul.glsl b/progs/vpglsl/psiz-mul.glsl new file mode 100644 index 0000000000..77f4a46b52 --- /dev/null +++ b/progs/vpglsl/psiz-mul.glsl @@ -0,0 +1,6 @@ + +void main() { + gl_FrontColor = gl_Color; + gl_PointSize = 10 * gl_Color.x; + gl_Position = gl_Vertex; +} diff --git a/progs/vpglsl/vp-tris.c b/progs/vpglsl/vp-tris.c index 9ae410bf98..b2b0508091 100644 --- a/progs/vpglsl/vp-tris.c +++ b/progs/vpglsl/vp-tris.c @@ -10,6 +10,10 @@ static const char *filename = NULL; static GLuint nr_steps = 4; +static GLuint prim = GL_TRIANGLES; +static GLfloat psz = 1.0; +static GLboolean pointsmooth = 0; +static GLboolean program_point_size = 0; static GLuint fragShader; static GLuint vertShader; @@ -229,6 +233,14 @@ static void subdiv( union vert *v0, } } +static void enable( GLenum value, GLboolean flag ) +{ + if (flag) + glEnable(value); + else + glDisable(value); +} + /** Assignment */ #define ASSIGN_3V( V, V0, V1, V2 ) \ do { \ @@ -241,10 +253,13 @@ static void Display( void ) { glClearColor(0.3, 0.3, 0.3, 1); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + glPointSize(psz); glUseProgram(program); + enable( GL_POINT_SMOOTH, pointsmooth ); + enable( GL_VERTEX_PROGRAM_POINT_SIZE_ARB, program_point_size ); - glBegin(GL_TRIANGLES); + glBegin(prim); { @@ -291,10 +306,41 @@ static void Key( unsigned char key, int x, int y ) (void) x; (void) y; switch (key) { - case 27: - CleanUp(); - exit(0); - break; + case 'p': + prim = GL_POINTS; + break; + case 't': + prim = GL_TRIANGLES; + break; + case 's': + psz += .5; + break; + case 'S': + if (psz > .5) + psz -= .5; + break; + case 'm': + pointsmooth = !pointsmooth; + break; + case 'z': + program_point_size = !program_point_size; + break; + case '+': + nr_steps++; + break; + case '-': + if (nr_steps) + nr_steps--; + break; + case ' ': + psz = 1.0; + prim = GL_TRIANGLES; + nr_steps = 4; + break; + case 27: + CleanUp(); + exit(0); + break; } glutPostRedisplay(); } @@ -305,7 +351,7 @@ int main( int argc, char *argv[] ) glutInitWindowPosition( 0, 0 ); glutInitWindowSize( 250, 250 ); glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); - glutCreateWindow(argv[0]); + glutCreateWindow(argv[argc-1]); glewInit(); glutReshapeFunc( Reshape ); glutKeyboardFunc( Key ); -- cgit v1.2.3 From 283e84bfb3066a3e3d778d4065b448ddd288fbb4 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 3 Jun 2009 16:33:56 +0200 Subject: progs/tests: Add some scissor tests --- progs/tests/.gitignore | 2 + progs/tests/Makefile | 2 + progs/tests/SConscript | 2 + progs/tests/scissor-viewport.c | 138 +++++++++++++++++++++++++++++++++ progs/tests/scissor.c | 168 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 312 insertions(+) create mode 100644 progs/tests/scissor-viewport.c create mode 100644 progs/tests/scissor.c (limited to 'progs') diff --git a/progs/tests/.gitignore b/progs/tests/.gitignore index 959ddcc51f..d6a8538767 100644 --- a/progs/tests/.gitignore +++ b/progs/tests/.gitignore @@ -62,6 +62,8 @@ readrate readtex.c readtex.h rubberband +scissor +scissor-viewport seccolor shader_api shaderutil.c diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 628ca41535..7604b22788 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -70,6 +70,8 @@ SOURCES = \ random.c \ readrate.c \ rubberband.c \ + scissor.c \ + scissor-viewport.c \ seccolor.c \ shader_api.c \ sharedtex.c \ diff --git a/progs/tests/SConscript b/progs/tests/SConscript index 453fcecd9c..9d89ff6a0d 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -95,6 +95,8 @@ progs = [ 'random', 'readrate', 'rubberband', + 'scissor', + 'scissor-viewport', 'seccolor', 'shader_api', 'stencil_twoside', diff --git a/progs/tests/scissor-viewport.c b/progs/tests/scissor-viewport.c new file mode 100644 index 0000000000..582e65fb72 --- /dev/null +++ b/progs/tests/scissor-viewport.c @@ -0,0 +1,138 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * Copyright (c) 2009 VMware, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +struct program +{ + unsigned width; + unsigned height; + int i; +}; + +struct program prog; + +static void init(void) +{ + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); + + prog.i = 0; +} + +static void reshape(int width, int height) +{ + glViewport(0, 0, 100, 100); + + prog.width = width; + prog.height = height; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + glutPostRedisplay(); + return; + } +} + +static void drawQuad(void) +{ + glBegin(GL_QUADS); + glVertex2d(-1.0, -1.0); + glVertex2d( 1.0, -1.0); + glVertex2d( 1.0, 1.0); + glVertex2d(-1.0, 1.0); + glEnd(); +} + +static void draw(void) +{ + int i; + + glClearColor(0.0, 0.0, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + i = prog.i++; + if (prog.i >= 3) + prog.i = 0; + + glEnable(GL_SCISSOR_TEST); + + { + glColor4d(1.0, 0.0, 0.0, 1.0); + + glScissor(i, i, 10 - 2*i, 10 - 2*i); + drawQuad(); + } + + glDisable(GL_SCISSOR_TEST); + + //glutSwapBuffers(); + glFlush(); +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + prog.width = 200; + prog.height = 200; + + glutInitWindowPosition(100, 0); + glutInitWindowSize(prog.width, prog.height); + + //type = GLUT_RGB | GLUT_DOUBLE; + type = GLUT_RGB | GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + init(); + + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutDisplayFunc(draw); + glutMainLoop(); + return 0; +} diff --git a/progs/tests/scissor.c b/progs/tests/scissor.c new file mode 100644 index 0000000000..2dfd2174e8 --- /dev/null +++ b/progs/tests/scissor.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc. + * Copyright (c) 2009 VMware, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software and + * its documentation for any purpose is hereby granted without fee, provided + * that (i) the above copyright notices and this permission notice appear in + * all copies of the software and related documentation, and (ii) the name of + * Silicon Graphics may not be used in any advertising or + * publicity relating to the software without the specific, prior written + * permission of Silicon Graphics. + * + * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF + * ANY KIND, + * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY + * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. + * + * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR + * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, + * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, + * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF + * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE + * OF THIS SOFTWARE. + */ + +#include +#include +#include +#include + +struct program +{ + unsigned width; + unsigned height; + unsigned quads; +}; + +struct program prog; + +static void init(void) +{ + fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); + fflush(stderr); +} + +static void reshape(int width, int height) +{ + + glViewport(0, 0, (GLint)width, (GLint)height); + + prog.width = width; + prog.height = height; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); + glMatrixMode(GL_MODELVIEW); +} + +static void key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + exit(1); + default: + prog.quads = !prog.quads; + glutPostRedisplay(); + return; + } +} + +static void drawQuad(void) +{ + + if (prog.quads) { + glBegin(GL_QUADS); + glVertex2d(-1.0, -1.0); + glVertex2d( 1.0, -1.0); + glVertex2d( 1.0, 1.0); + glVertex2d(-1.0, 1.0); + glEnd(); + } else { + glClear(GL_COLOR_BUFFER_BIT); + } +} + +static void draw(void) +{ + glClearColor(0.0, 0.0, 1.0, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + printf("drawing with %s\n", prog.quads ? "quads" : "clears"); + + glEnable(GL_SCISSOR_TEST); + + { + glClearColor(1.0, 0.0, 0.0, 1.0); + glColor4d(1.0, 0.0, 0.0, 1.0); + + glScissor(1, 1, 10, 10); + drawQuad(); + glScissor(1, prog.height - 11, 10, 10); + drawQuad(); + glScissor(prog.width - 11, prog.height - 11, 10, 10); + drawQuad(); + } + + { + glClearColor(0.0, 1.0, 0.0, 1.0); + glColor4d(0.0, 1.0, 0.0, 1.0); + + glScissor(12, 1, 10, 10); + drawQuad(); + glScissor(12, prog.height - 11, 10, 10); + drawQuad(); + glScissor(prog.width - 22, prog.height - 11, 10, 10); + drawQuad(); + } + + { + glClearColor(1.0, 1.0, 0.0, 1.0); + glColor4d(1.0, 1.0, 0.0, 1.0); + + glScissor(1, 12, 10, 10); + drawQuad(); + glScissor(1, prog.height - 22, 10, 10); + drawQuad(); + glScissor(prog.width - 11, prog.height - 22, 10, 10); + drawQuad(); + } + + glDisable(GL_SCISSOR_TEST); + + //glutSwapBuffers(); + glFlush(); +} + +int main(int argc, char **argv) +{ + GLenum type; + + glutInit(&argc, argv); + + prog.width = 200; + prog.height = 200; + + glutInitWindowPosition(100, 0); + glutInitWindowSize(prog.width, prog.height); + + //type = GLUT_RGB | GLUT_DOUBLE; + type = GLUT_RGB | GLUT_SINGLE; + glutInitDisplayMode(type); + + if (glutCreateWindow(*argv) == GL_FALSE) { + exit(1); + } + + init(); + + glutReshapeFunc(reshape); + glutKeyboardFunc(key); + glutDisplayFunc(draw); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 139f2ddde4fcfdaa7d8bbb86e946274be3733e71 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 9 Jun 2009 14:03:25 -0600 Subject: tests: quick and dirty glGetTexImage() test program --- progs/tests/Makefile | 3 +- progs/tests/getteximage.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 progs/tests/getteximage.c (limited to 'progs') diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 628ca41535..1a3ba4f181 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -48,7 +48,8 @@ SOURCES = \ fptest1.c \ fptexture.c \ getprocaddress.c \ - glutfx \ + getteximage.c \ + glutfx.c \ interleave.c \ invert.c \ jkrahntest.c \ diff --git a/progs/tests/getteximage.c b/progs/tests/getteximage.c new file mode 100644 index 0000000000..c8705d5052 --- /dev/null +++ b/progs/tests/getteximage.c @@ -0,0 +1,123 @@ +/** + * Test glGetTexImage() + * Brian Paul + * 9 June 2009 + */ + + +#include +#include +#include +#include + +static int Win; + + +static void +TestGetTexImage(void) +{ + GLuint iter; + + for (iter = 0; iter < 20; iter++) { + GLint p = (iter % 6) + 4; + GLint w = (1 << p); + GLint h = (1 << p); + GLubyte data[512*512*4]; + GLubyte data2[512*512*4]; + GLuint i; + GLint level = 0; + + printf("Testing %d x %d tex image\n", w, h); + /* fill data */ + for (i = 0; i < w * h * 4; i++) { + data[i] = i & 0xff; + data2[i] = 0; + } + + glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w, h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, data); + + glBegin(GL_POINTS); + glVertex2f(0, 0); + glEnd(); + + /* get */ + glGetTexImage(GL_TEXTURE_2D, level, GL_RGBA, GL_UNSIGNED_BYTE, data2); + + /* compare */ + for (i = 0; i < w * h * 4; i++) { + if (data2[i] != data[i]) { + printf("Failure!\n"); + abort(); + } + } + } + printf("Passed\n"); + glutDestroyWindow(Win); + exit(0); +} + + +static void +Draw(void) +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + TestGetTexImage(); + + glutSwapBuffers(); +} + + +static void +Reshape(int width, int height) +{ + glViewport(0, 0, width, height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glTranslatef(0.0, 0.0, -15.0); +} + + +static void +Key(unsigned char key, int x, int y) +{ + (void) x; + (void) y; + switch (key) { + case 27: + glutDestroyWindow(Win); + exit(0); + break; + } + glutPostRedisplay(); +} + + +static void +Init(void) +{ + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glEnable(GL_TEXTURE_2D); +} + + +int +main(int argc, char *argv[]) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(400, 400); + glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); + Win = glutCreateWindow(argv[0]); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Draw); + Init(); + glutMainLoop(); + return 0; +} -- cgit v1.2.3 From 073c20befa28177cf1276bfb8c75f6638d588580 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 9 Jun 2009 15:05:36 -0600 Subject: tests: also test glGetTexImage with render to texture Also, adjust texture dims for the original test. And use GLEW. --- progs/tests/getteximage.c | 114 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 11 deletions(-) (limited to 'progs') diff --git a/progs/tests/getteximage.c b/progs/tests/getteximage.c index c8705d5052..f0160f5863 100644 --- a/progs/tests/getteximage.c +++ b/progs/tests/getteximage.c @@ -8,6 +8,7 @@ #include #include #include +#include #include static int Win; @@ -17,17 +18,22 @@ static void TestGetTexImage(void) { GLuint iter; + GLubyte *data = (GLubyte *) malloc(1024 * 1024 * 4); + GLubyte *data2 = (GLubyte *) malloc(1024 * 1024 * 4); - for (iter = 0; iter < 20; iter++) { - GLint p = (iter % 6) + 4; + glEnable(GL_TEXTURE_2D); + + printf("glTexImage2D + glGetTexImage:\n"); + + for (iter = 0; iter < 8; iter++) { + GLint p = (iter % 8) + 3; GLint w = (1 << p); GLint h = (1 << p); - GLubyte data[512*512*4]; - GLubyte data2[512*512*4]; GLuint i; GLint level = 0; - printf("Testing %d x %d tex image\n", w, h); + printf(" Testing %d x %d tex image\n", w, h); + /* fill data */ for (i = 0; i < w * h * 4; i++) { data[i] = i & 0xff; @@ -47,17 +53,100 @@ TestGetTexImage(void) /* compare */ for (i = 0; i < w * h * 4; i++) { if (data2[i] != data[i]) { - printf("Failure!\n"); + printf("glTexImage + glGetTexImage failure!\n"); + printf("Expected value %d, found %d\n", data[i], data2[i]); abort(); } } } + printf("Passed\n"); - glutDestroyWindow(Win); - exit(0); + glDisable(GL_TEXTURE_2D); + free(data); + free(data2); +} + + +static GLboolean +ColorsEqual(const GLubyte ref[4], const GLubyte act[4]) +{ + if (abs((int) ref[0] - (int) act[0]) > 1 || + abs((int) ref[1] - (int) act[1]) > 1 || + abs((int) ref[2] - (int) act[2]) > 1 || + abs((int) ref[3] - (int) act[3]) > 1) { + printf("expected %d %d %d %d\n", ref[0], ref[1], ref[2], ref[3]); + printf("found %d %d %d %d\n", act[0], act[1], act[2], act[3]); + return GL_FALSE; + } + return GL_TRUE; } +static void +TestGetTexImageRTT(void) +{ + GLuint iter; + GLuint fb, tex; + GLint w = 512; + GLint h = 256; + GLint level = 0; + + glGenTextures(1, &tex); + glGenFramebuffersEXT(1, &fb); + + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + + glBindFramebuffer(GL_FRAMEBUFFER_EXT, fb); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, tex, level); + + printf("Render to texture + glGetTexImage:\n"); + printf(" Testing %d x %d tex image\n", w, h); + for (iter = 0; iter < 8; iter++) { + GLubyte color[4]; + GLubyte *data2 = (GLubyte *) malloc(w * h * 4); + GLuint i; + + /* random clear color */ + for (i = 0; i < 4; i++) { + color[i] = rand() % 256; + } + + glClearColor(color[0] / 255.0, + color[1] / 255.0, + color[2] / 255.0, + color[3] / 255.0); + + glClear(GL_COLOR_BUFFER_BIT); + + /* get */ + glGetTexImage(GL_TEXTURE_2D, level, GL_RGBA, GL_UNSIGNED_BYTE, data2); + + /* compare */ + for (i = 0; i < w * h; i += 4) { + if (!ColorsEqual(color, data2 + i * 4)) { + printf("Render to texture failure!\n"); + abort(); + } + } + + free(data2); + } + + glBindFramebuffer(GL_FRAMEBUFFER_EXT, 0); + glDeleteFramebuffersEXT(1, &fb); + glDeleteTextures(1, &tex); + + printf("Passed\n"); +} + + + + static void Draw(void) { @@ -65,6 +154,11 @@ Draw(void) TestGetTexImage(); + TestGetTexImageRTT(); + + glutDestroyWindow(Win); + exit(0); + glutSwapBuffers(); } @@ -100,9 +194,6 @@ Key(unsigned char key, int x, int y) static void Init(void) { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); - glEnable(GL_TEXTURE_2D); } @@ -114,6 +205,7 @@ main(int argc, char *argv[]) glutInitWindowSize(400, 400); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); Win = glutCreateWindow(argv[0]); + glewInit(); glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Draw); -- cgit v1.2.3 From 29c79a03a42365b4bf828c81ab8676e3e42cfbaf Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Tue, 9 Jun 2009 15:06:41 -0600 Subject: tests: check for GL_EXT/ARB_framebuffer_object --- progs/tests/getteximage.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'progs') diff --git a/progs/tests/getteximage.c b/progs/tests/getteximage.c index f0160f5863..e4818a8fab 100644 --- a/progs/tests/getteximage.c +++ b/progs/tests/getteximage.c @@ -154,7 +154,9 @@ Draw(void) TestGetTexImage(); - TestGetTexImageRTT(); + if (glutExtensionSupported("GL_EXT_framebuffer_object") || + glutExtensionSupported("GL_ARB_framebuffer_object")) + TestGetTexImageRTT(); glutDestroyWindow(Win); exit(0); -- cgit v1.2.3 From e3f14f2f3bdd66400d02f0f9076593db609874a8 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Thu, 11 Jun 2009 13:19:34 +0100 Subject: progs: Port fp programs to GLEW. --- progs/fp/SConscript | 19 ++++++++++++++++--- progs/fp/fp-tri.c | 2 +- progs/fp/point-position.c | 7 ++++--- progs/fp/tri-depth.c | 9 ++++----- progs/fp/tri-depth2.c | 7 ++++--- progs/fp/tri-depthwrite.c | 6 ++++-- progs/fp/tri-depthwrite2.c | 6 ++++-- progs/fp/tri-inv.c | 6 ++++-- progs/fp/tri-param.c | 8 +++++--- progs/fp/tri-tex.c | 6 ++++-- 10 files changed, 50 insertions(+), 26 deletions(-) (limited to 'progs') diff --git a/progs/fp/SConscript b/progs/fp/SConscript index 553799758b..a78318542c 100644 --- a/progs/fp/SConscript +++ b/progs/fp/SConscript @@ -11,7 +11,20 @@ env.Prepend(CPPPATH = [ env.Prepend(LIBS = ['$GLUT_LIB']) -env.Program( - target = 'fp-tri', - source = ['fp-tri.c'], +progs = [ + 'fp-tri', + 'tri-depth', + 'tri-depth2', + 'tri-depthwrite', + 'tri-depthwrite2', + 'tri-inv', + 'tri-param', + 'tri-tex', + 'point-position', +] + +for prog in progs: + env.Program( + target = prog, + source = [prog + '.c'], ) diff --git a/progs/fp/fp-tri.c b/progs/fp/fp-tri.c index 6c15540d38..52a8fcfc22 100644 --- a/progs/fp/fp-tri.c +++ b/progs/fp/fp-tri.c @@ -89,7 +89,7 @@ static void Init( void ) } fprintf(stderr, "%.*s\n", sz, buf); - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } diff --git a/progs/fp/point-position.c b/progs/fp/point-position.c index c352a939cb..c0963d7a0b 100644 --- a/progs/fp/point-position.c +++ b/progs/fp/point-position.c @@ -2,9 +2,8 @@ #include #include #include -#define GL_GLEXT_PROTOTYPES +#include #include -#include "GL/gl.h" @@ -17,7 +16,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -109,6 +108,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-depth.c b/progs/fp/tri-depth.c index a1f0579c8e..5488469e80 100644 --- a/progs/fp/tri-depth.c +++ b/progs/fp/tri-depth.c @@ -2,9 +2,8 @@ #include #include #include -#define GL_GLEXT_PROTOTYPES +#include #include -#include "GL/gl.h" @@ -19,7 +18,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -89,8 +88,6 @@ int main(int argc, char **argv) glutInit(&argc, argv); - - glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250); type = GLUT_RGB; @@ -101,6 +98,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-depth2.c b/progs/fp/tri-depth2.c index f309628283..6ed2307115 100644 --- a/progs/fp/tri-depth2.c +++ b/progs/fp/tri-depth2.c @@ -2,9 +2,8 @@ #include #include #include -#define GL_GLEXT_PROTOTYPES +#include #include -#include "GL/gl.h" @@ -21,7 +20,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -106,6 +105,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-depthwrite.c b/progs/fp/tri-depthwrite.c index fedeec4577..8e4f3e6245 100644 --- a/progs/fp/tri-depthwrite.c +++ b/progs/fp/tri-depthwrite.c @@ -2,7 +2,7 @@ #include #include #include -#define GL_GLEXT_PROTOTYPES +#include #include @@ -16,7 +16,7 @@ static void Init(void) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -97,6 +97,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-depthwrite2.c b/progs/fp/tri-depthwrite2.c index 5547092ec9..3c0b4d30c9 100644 --- a/progs/fp/tri-depthwrite2.c +++ b/progs/fp/tri-depthwrite2.c @@ -2,7 +2,7 @@ #include #include #include -#define GL_GLEXT_PROTOTYPES +#include #include @@ -16,7 +16,7 @@ static void Init(void) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -97,6 +97,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-inv.c b/progs/fp/tri-inv.c index e902332386..7e8d8c5ce2 100644 --- a/progs/fp/tri-inv.c +++ b/progs/fp/tri-inv.c @@ -2,7 +2,7 @@ #include #include #include -#define GL_GLEXT_PROTOTYPES +#include #include @@ -17,7 +17,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -99,6 +99,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-param.c b/progs/fp/tri-param.c index f3e55af3f1..57443d71bd 100644 --- a/progs/fp/tri-param.c +++ b/progs/fp/tri-param.c @@ -2,9 +2,9 @@ #include #include #include -#define GL_GLEXT_PROTOTYPES +#include #include -#include "GL/gl.h" + static void Init( void ) { @@ -15,7 +15,7 @@ static void Init( void ) ; GLuint modulateProg; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -104,6 +104,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); diff --git a/progs/fp/tri-tex.c b/progs/fp/tri-tex.c index 87f63894ce..1dbbb201ce 100644 --- a/progs/fp/tri-tex.c +++ b/progs/fp/tri-tex.c @@ -3,7 +3,7 @@ #include #include #include -#define GL_GLEXT_PROTOTYPES +#include #include #include "readtex.c" @@ -23,7 +23,7 @@ static void Init( void ) GLuint modulateProg; GLuint Texture; - if (!glutExtensionSupported("GL_ARB_fragment_program")) { + if (!GLEW_ARB_fragment_program) { printf("Error: GL_ARB_fragment_program not supported!\n"); exit(1); } @@ -120,6 +120,8 @@ int main(int argc, char **argv) exit(1); } + glewInit(); + Init(); glutReshapeFunc(Reshape); -- cgit v1.2.3 From 1cd0afffc9edbcac690f8ab436aecfced26b0aba Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 12 Jun 2009 14:55:04 +0100 Subject: progs/rbug: Add binary to bmp converter program --- progs/rbug/.gitignore | 2 + progs/rbug/Makefile | 1 + progs/rbug/bin_to_bmp.c | 110 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 progs/rbug/bin_to_bmp.c (limited to 'progs') diff --git a/progs/rbug/.gitignore b/progs/rbug/.gitignore index 317290bbb3..26a561c829 100644 --- a/progs/rbug/.gitignore +++ b/progs/rbug/.gitignore @@ -1,3 +1,4 @@ +bin_to_bmp simple_client simple_server shdr_info @@ -7,3 +8,4 @@ ctx_info tex_dump tex_info *.bmp +*.bin diff --git a/progs/rbug/Makefile b/progs/rbug/Makefile index 8df03dd4e1..718f7a2bb5 100644 --- a/progs/rbug/Makefile +++ b/progs/rbug/Makefile @@ -15,6 +15,7 @@ LINKS = \ $(PROG_LINKS) SOURCES = \ + bin_to_bmp.c \ simple_client.c \ simple_server.c \ shdr_info.c \ diff --git a/progs/rbug/bin_to_bmp.c b/progs/rbug/bin_to_bmp.c new file mode 100644 index 0000000000..cdae3486ce --- /dev/null +++ b/progs/rbug/bin_to_bmp.c @@ -0,0 +1,110 @@ +/* + * Copyright 2009 VMware, Inc. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * on the rights to use, copy, modify, merge, publish, distribute, sub + * license, and/or sell copies of the Software, and to permit persons to whom + * the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "pipe/p_compiler.h" +#include "pipe/p_format.h" +#include "pipe/p_state.h" +#include "util/u_memory.h" +#include "util/u_debug.h" +#include "util/u_network.h" +#include "util/u_tile.h" + +static uint8_t* read(const char *filename, unsigned size); +static void dump(unsigned src_width, unsigned src_height, + unsigned src_stride, enum pipe_format src_format, + uint8_t *data, unsigned src_size); + +int main(int argc, char** argv) +{ + /* change these */ + unsigned width = 64; + unsigned height = 64; + unsigned stride = width * 4; + unsigned size = stride * height; + const char *filename = "mybin.bin"; + enum pipe_format format = PIPE_FORMAT_A8R8G8B8_UNORM; + + dump(width, height, stride, format, read(filename, size), size); + + return 0; +} + +static void dump(unsigned width, unsigned height, + unsigned src_stride, enum pipe_format src_format, + uint8_t *data, unsigned src_size) +{ + struct pipe_format_block src_block; + + enum pipe_format dst_format = PIPE_FORMAT_R32G32B32A32_FLOAT; + struct pipe_format_block dst_block; + unsigned dst_stride; + unsigned dst_size; + float *rgba; + int i; + char filename[512]; + + { + pf_get_block(src_format, &src_block); + assert(src_stride >= pf_get_stride(&src_block, width)); + assert(src_size >= pf_get_2d_size(&src_block, src_stride, width)); + } + { + pf_get_block(dst_format, &dst_block); + dst_stride = pf_get_stride(&dst_block, width); + dst_size = pf_get_2d_size(&dst_block, dst_stride, width); + rgba = MALLOC(dst_size); + } + + util_snprintf(filename, 512, "%s.bmp", pf_name(src_format)); + + if (pf_is_compressed(src_format)) { + debug_printf("skipping: %s\n", filename); + return; + } + + debug_printf("saving: %s\n", filename); + + for (i = 0; i < height; i++) { + pipe_tile_raw_to_rgba(src_format, data + src_stride * i, + width, 1, + &rgba[width*4*i], dst_stride); + } + + debug_dump_float_rgba_bmp(filename, width, height, rgba, width); + + FREE(rgba); +} + +static uint8_t* read(const char *filename, unsigned size) +{ + uint8_t *data; + FILE *file = fopen(filename, "rb"); + + data = MALLOC(size); + + fread(data, 1, size, file); + fclose(file); + + return data; +} -- cgit v1.2.3