diff options
Diffstat (limited to 'progs')
-rw-r--r-- | progs/SConscript | 3 | ||||
-rw-r--r-- | progs/es2/xegl/tri.c | 5 | ||||
-rw-r--r-- | progs/fpglsl/.gitignore | 1 | ||||
-rw-r--r-- | progs/fpglsl/Makefile | 52 | ||||
-rw-r--r-- | progs/fpglsl/SConscript | 13 | ||||
-rw-r--r-- | progs/fpglsl/fp-tri.c | 415 | ||||
-rw-r--r-- | progs/fpglsl/mov-imm.glsl | 3 | ||||
-rw-r--r-- | progs/fpglsl/mov.glsl | 3 | ||||
-rw-r--r-- | progs/fpglsl/tex-multi.glsl | 15 | ||||
-rw-r--r-- | progs/fpglsl/tex.glsl | 6 | ||||
-rw-r--r-- | progs/tests/Makefile | 1 | ||||
-rw-r--r-- | progs/tests/SConscript | 1 | ||||
-rw-r--r-- | progs/tests/fbotest3.c | 231 |
13 files changed, 746 insertions, 3 deletions
diff --git a/progs/SConscript b/progs/SConscript index 66a1745271d..2ec95a282e8 100644 --- a/progs/SConscript +++ b/progs/SConscript @@ -23,7 +23,8 @@ if platform != 'embedded': progs_env.Prepend(LIBS = ['GLU', 'GL']) # Glut - progs_env.Prepend(LIBS = [glut]) + progs_env.Prepend(LIBPATH = [glut.dir]) + progs_env.Prepend(LIBS = [glut.name]) # GLEW progs_env.Prepend(LIBS = [glew]) diff --git a/progs/es2/xegl/tri.c b/progs/es2/xegl/tri.c index 7729a099578..8981d8a7e21 100644 --- a/progs/es2/xegl/tri.c +++ b/progs/es2/xegl/tri.c @@ -334,14 +334,15 @@ make_x_window(Display *x_dpy, EGLDisplay egl_dpy, exit(1); } + /* sanity checks */ { EGLint val; eglQuerySurface(egl_dpy, *surfRet, EGL_WIDTH, &val); assert(val == width); eglQuerySurface(egl_dpy, *surfRet, EGL_HEIGHT, &val); assert(val == height); - eglQuerySurface(egl_dpy, *surfRet, EGL_SURFACE_TYPE, &val); - assert(val == EGL_WINDOW_BIT); + assert(eglGetConfigAttrib(egl_dpy, config, EGL_SURFACE_TYPE, &val)); + assert(val & EGL_WINDOW_BIT); } XFree(visInfo); diff --git a/progs/fpglsl/.gitignore b/progs/fpglsl/.gitignore new file mode 100644 index 00000000000..9fe73ab0678 --- /dev/null +++ b/progs/fpglsl/.gitignore @@ -0,0 +1 @@ +fp-tri diff --git a/progs/fpglsl/Makefile b/progs/fpglsl/Makefile new file mode 100644 index 00000000000..3bf14b4b709 --- /dev/null +++ b/progs/fpglsl/Makefile @@ -0,0 +1,52 @@ +# progs/tests/Makefile + + +# These programs aren't intended to be included with the normal distro. +# They're not too interesting but they're good for testing. + +TOP = ../.. +include $(TOP)/configs/current + +LIBS = -L$(TOP)/$(LIB_DIR) -l$(GLUT_LIB) -l$(GLEW_LIB) -l$(GLU_LIB) -l$(GL_LIB) $(APP_LIB_DEPS) + +SOURCES = \ + fp-tri.c + + + +PROGS = $(SOURCES:%.c=%) + +INCLUDES = -I. -I$(TOP)/include -I../samples + + +##### RULES ##### + +.SUFFIXES: +.SUFFIXES: .c + +.c: + $(CC) $(INCLUDES) $(CFLAGS) $< $(LIBS) -o $@ + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ + +.S.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DEFINES) $< -o $@ + + +##### TARGETS ##### + +default: $(PROGS) + +clean: + rm -f $(PROGS) + rm -f *.o + rm -f getproclist.h + + + + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find ../include` diff --git a/progs/fpglsl/SConscript b/progs/fpglsl/SConscript new file mode 100644 index 00000000000..e31fa320238 --- /dev/null +++ b/progs/fpglsl/SConscript @@ -0,0 +1,13 @@ +Import('env') + +if not env['GLUT']: + Return() + +env = env.Clone() + +env.Prepend(LIBS = ['$GLUT_LIB']) + +env.Program( + target = 'fp-tri', + source = ['fp-tri.c'], + ) diff --git a/progs/fpglsl/fp-tri.c b/progs/fpglsl/fp-tri.c new file mode 100644 index 00000000000..c9b08fbbad7 --- /dev/null +++ b/progs/fpglsl/fp-tri.c @@ -0,0 +1,415 @@ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> + +#ifndef WIN32 +#include <unistd.h> +#include <signal.h> +#endif + +#include <GL/glew.h> +#include <GL/glut.h> + +#include "readtex.c" + + +#define TEXTURE_FILE "../images/bw.rgb" + +unsigned show_fps = 0; +unsigned int frame_cnt = 0; +void alarmhandler(int); +static const char *filename = NULL; + +static GLuint fragShader; +static GLuint vertShader; +static GLuint program; + + +static void usage(char *name) +{ + fprintf(stderr, "usage: %s [ options ] shader_filename\n", name); +#ifndef WIN32 + fprintf(stderr, "\n" ); + fprintf(stderr, "options:\n"); + fprintf(stderr, " -fps show frames per second\n"); +#endif +} + +#ifndef WIN32 +void alarmhandler (int sig) +{ + if (sig == SIGALRM) { + printf("%d frames in 5.0 seconds = %.3f FPS\n", frame_cnt, + frame_cnt / 5.0); + + frame_cnt = 0; + } + signal(SIGALRM, alarmhandler); + alarm(5); +} +#endif + + + + +static void load_and_compile_shader(GLuint shader, const char *text) +{ + GLint stat; + + glShaderSource(shader, 1, (const GLchar **) &text, NULL); + + glCompileShader(shader); + + glGetShaderiv(shader, GL_COMPILE_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetShaderInfoLog(shader, 1000, &len, log); + fprintf(stderr, "fp-tri: problem compiling shader:\n%s\n", log); + exit(1); + } +} + +static void read_shader(GLuint shader, const char *filename) +{ + const int max = 100*1000; + int n; + char *buffer = (char*) malloc(max); + FILE *f = fopen(filename, "r"); + if (!f) { + fprintf(stderr, "fp-tri: Unable to open shader file %s\n", filename); + exit(1); + } + + n = fread(buffer, 1, max, f); + printf("fp-tri: read %d bytes from shader file %s\n", n, filename); + if (n > 0) { + buffer[n] = 0; + load_and_compile_shader(shader, buffer); + } + + fclose(f); + free(buffer); +} + +static void check_link(GLuint prog) +{ + GLint stat; + glGetProgramiv(prog, GL_LINK_STATUS, &stat); + if (!stat) { + GLchar log[1000]; + GLsizei len; + glGetProgramInfoLog(prog, 1000, &len, log); + fprintf(stderr, "Linker error:\n%s\n", log); + } +} + +static void setup_uniforms() +{ + { + GLint loc1f = glGetUniformLocationARB(program, "Offset1f"); + GLint loc2f = glGetUniformLocationARB(program, "Offset2f"); + GLint loc4f = glGetUniformLocationARB(program, "Offset4f"); + GLfloat vecKer[] = + { 1.0, 0.0, 0.0, 1.0, + 0.0, 1.0, 0.0, 1.0, + 1.0, 0.0, 0.0, 1.0, + 0.0, 0.0, 0.0, 1.0 + }; + if (loc1f >= 0) + glUniform1fv(loc1f, 16, vecKer); + + if (loc2f >= 0) + glUniform2fv(loc2f, 8, vecKer); + + if (loc4f >= 0) + glUniform4fv(loc4f, 4, vecKer); + + } + + { + GLint loc1f = glGetUniformLocationARB(program, "KernelValue1f"); + GLint loc2f = glGetUniformLocationARB(program, "KernelValue2f"); + GLint loc4f = glGetUniformLocationARB(program, "KernelValue4f"); + GLfloat vecKer[] = + { 1.0, 0.0, 0.0, 0.25, + 0.0, 1.0, 0.0, 0.25, + 0.0, 0.0, 1.0, 0.25, + 0.0, 0.0, 0.0, 0.25, + 0.5, 0.0, 0.0, 0.35, + 0.0, 0.5, 0.0, 0.35, + 0.0, 0.0, 0.5, 0.35, + 0.0, 0.0, 0.0, 0.35 + }; + if (loc1f >= 0) + glUniform1fv(loc1f, 16, vecKer); + + if (loc2f >= 0) + glUniform2fv(loc2f, 8, vecKer); + + if (loc4f >= 0) + glUniform4fv(loc4f, 4, vecKer); + } +} + +static void prepare_shaders() +{ + static const char *fragShaderText = + "void main() {\n" + " gl_FragColor = gl_Color;\n" + "}\n"; + static const char *vertShaderText = + "void main() {\n" + " gl_FrontColor = gl_Color;\n" + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + "}\n"; + fragShader = glCreateShader(GL_FRAGMENT_SHADER); + if (filename) + read_shader(fragShader, filename); + else + load_and_compile_shader(fragShader, fragShaderText); + + + vertShader = glCreateShader(GL_VERTEX_SHADER); + load_and_compile_shader(vertShader, vertShaderText); + + program = glCreateProgram(); + glAttachShader(program, fragShader); + glAttachShader(program, vertShader); + glLinkProgram(program); + check_link(program); + glUseProgram(program); + + setup_uniforms(); +} + +#define LEVELS 8 +#define SIZE (1<<LEVELS) +static int TexWidth = SIZE, TexHeight = SIZE; + + +static void +ResetTextureLevel( int i ) +{ + GLubyte tex2d[SIZE*SIZE][4]; + + { + GLint Width = TexWidth / (1 << i); + GLint Height = TexHeight / (1 << i); + GLint s, t; + + for (s = 0; s < Width; s++) { + for (t = 0; t < Height; t++) { + tex2d[t*Width+s][0] = ((s / 16) % 2) ? 0 : 255; + tex2d[t*Width+s][1] = ((t / 16) % 2) ? 0 : 255; + tex2d[t*Width+s][2] = 128; + tex2d[t*Width+s][3] = 255; + } + } + + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + glTexImage2D(GL_TEXTURE_2D, i, GL_RGB, Width, Height, 0, + GL_RGBA, GL_UNSIGNED_BYTE, tex2d); + } +} + + +static void +ResetTexture( void ) +{ + int i; + + for (i = 0; i <= LEVELS; i++) + { + ResetTextureLevel(i); + } +} + +static void Init( void ) +{ + GLuint Texture; + + /* Load texture */ + glGenTextures(1, &Texture); + glBindTexture(GL_TEXTURE_2D, Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { + printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE); + exit(1); + } + + + glGenTextures(1, &Texture); + glActiveTextureARB(GL_TEXTURE0_ARB + 1); + glBindTexture(GL_TEXTURE_2D, Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + + { + GLubyte data[32][32]; + int width = 32; + int height = 32; + int i; + int j; + + for (i = 0; i < 32; i++) + for (j = 0; j < 32; j++) + { + /** + ** +-----------+ + ** | W | + ** | +-----+ | + ** | | | | + ** | | B | | + ** | | | | + ** | +-----+ | + ** | | + ** +-----------+ + **/ + int i2 = i - height / 2; + int j2 = j - width / 2; + int h8 = height / 8; + int w8 = width / 8; + if ( -h8 <= i2 && i2 <= h8 && -w8 <= j2 && j2 <= w8 ) { + data[i][j] = 0x00; + } else if ( -2 * h8 <= i2 && i2 <= 2 * h8 && -2 * w8 <= j2 && j2 <= 2 * w8 ) { + data[i][j] = 0x55; + } else if ( -3 * h8 <= i2 && i2 <= 3 * h8 && -3 * w8 <= j2 && j2 <= 3 * w8 ) { + data[i][j] = 0xaa; + } else { + data[i][j] = 0xff; + } + } + + glTexImage2D( GL_TEXTURE_2D, 0, + GL_ALPHA8, + 32, 32, 0, + GL_ALPHA, GL_UNSIGNED_BYTE, data ); + } + + glGenTextures(1, &Texture); + glActiveTextureARB(GL_TEXTURE0_ARB + 2); + glBindTexture(GL_TEXTURE_2D, Texture); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + ResetTexture(); + + glClearColor(.1, .3, .5, 0); +} + + + + +static void args(int argc, char *argv[]) +{ + GLint i; + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-fps") == 0) { + show_fps = 1; + } + else if (i == argc - 1) { + filename = argv[i]; + } + else { + usage(argv[0]); + exit(1); + } + } +} + + + + + +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 CleanUp(void) +{ + glDeleteShader(fragShader); + glDeleteShader(vertShader); + glDeleteProgram(program); +} + +static void Key(unsigned char key, int x, int y) +{ + + switch (key) { + case 27: + CleanUp(); + exit(1); + default: + break; + } + + glutPostRedisplay(); +} + +static void Display(void) +{ + glClear(GL_COLOR_BUFFER_BIT); + + glUseProgram(program); + glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, 1.0, 1.0, 0.0, 0.0); + glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, 0.0, 0.0, 1.0, 1.0); + glBegin(GL_TRIANGLES); + + glColor3f(0,0,1); + glTexCoord3f(1,1,0); + glVertex3f( 0.9, -0.9, -30.0); + + glColor3f(1,0,0); + glTexCoord3f(1,-1,0); + glVertex3f( 0.9, 0.9, -30.0); + + glColor3f(0,1,0); + glTexCoord3f(-1,0,0); + glVertex3f(-0.9, 0.0, -30.0); + glEnd(); + + glFlush(); + if (show_fps) { + ++frame_cnt; + glutPostRedisplay(); + } +} + + +int main(int argc, char **argv) +{ + glutInit(&argc, argv); + glutInitWindowPosition(0, 0); + glutInitWindowSize(250, 250); + glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH); + args(argc, argv); + glutCreateWindow(filename ? filename : "fp-tri"); + glewInit(); + glutReshapeFunc(Reshape); + glutKeyboardFunc(Key); + glutDisplayFunc(Display); + prepare_shaders(); + Init(); +#ifndef WIN32 + if (show_fps) { + signal(SIGALRM, alarmhandler); + alarm(5); + } +#endif + glutMainLoop(); + return 0; +} diff --git a/progs/fpglsl/mov-imm.glsl b/progs/fpglsl/mov-imm.glsl new file mode 100644 index 00000000000..cbb75ce342c --- /dev/null +++ b/progs/fpglsl/mov-imm.glsl @@ -0,0 +1,3 @@ +void main() { + gl_FragColor = vec4(1,0,1,1); +} diff --git a/progs/fpglsl/mov.glsl b/progs/fpglsl/mov.glsl new file mode 100644 index 00000000000..4a1f185ba44 --- /dev/null +++ b/progs/fpglsl/mov.glsl @@ -0,0 +1,3 @@ +void main() { + gl_FragColor = gl_Color; +} diff --git a/progs/fpglsl/tex-multi.glsl b/progs/fpglsl/tex-multi.glsl new file mode 100644 index 00000000000..5220b7efaf2 --- /dev/null +++ b/progs/fpglsl/tex-multi.glsl @@ -0,0 +1,15 @@ +// Multi-texture fragment shader +// Brian Paul + +// Composite second texture over first. +// We're assuming the 2nd texture has a meaningful alpha channel. + +uniform sampler2D tex1; +uniform sampler2D tex2; + +void main() +{ + vec4 t1 = texture2D(tex1, gl_Color.xy); + vec4 t2 = texture2D(tex2, gl_Color.yz); + gl_FragColor = mix(t1, t2, t2.w); +} diff --git a/progs/fpglsl/tex.glsl b/progs/fpglsl/tex.glsl new file mode 100644 index 00000000000..4302fabe2d5 --- /dev/null +++ b/progs/fpglsl/tex.glsl @@ -0,0 +1,6 @@ +uniform sampler2D tex1; + +void main() +{ + gl_FragColor = texture2D(tex1, gl_Color.xy); +} diff --git a/progs/tests/Makefile b/progs/tests/Makefile index 836396b2499..a38f411def8 100644 --- a/progs/tests/Makefile +++ b/progs/tests/Makefile @@ -48,6 +48,7 @@ SOURCES = \ floattex.c \ fbotest1.c \ fbotest2.c \ + fbotest3.c \ fillrate.c \ fog.c \ fogcoord.c \ diff --git a/progs/tests/SConscript b/progs/tests/SConscript index e2c65382887..0a11b965f79 100644 --- a/progs/tests/SConscript +++ b/progs/tests/SConscript @@ -51,6 +51,7 @@ progs = [ 'ext422square', 'fbotest1', 'fbotest2', + 'fbotest3', 'fillrate', 'floattex', 'fog', diff --git a/progs/tests/fbotest3.c b/progs/tests/fbotest3.c new file mode 100644 index 00000000000..8e288b38b83 --- /dev/null +++ b/progs/tests/fbotest3.c @@ -0,0 +1,231 @@ +/* + * Test GL_EXT_framebuffer_object + * Like fbotest2.c but use a texture for the Z buffer / renderbuffer. + * Note: the Z texture is never resized so that limits what can be + * rendered if the window is resized. + * + * This tests a bug reported by Christoph Bumiller on 1 Feb 2010 + * on mesa3d-dev. + * + * XXX this should be made into a piglit test. + * + * Brian Paul + * 1 Feb 2010 + */ + + +#include <assert.h> +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include <GL/glew.h> +#include <GL/glut.h> + + +static int Win = 0; +static int Width = 400, Height = 400; +static GLuint Tex = 0; +static GLuint MyFB, ColorRb, DepthRb; +static GLboolean Animate = GL_FALSE; +static GLfloat Rotation = 0.0; + + +static void +CheckError(int line) +{ + GLenum err = glGetError(); + if (err) { + printf("fbotest3: GL Error 0x%x at line %d\n", (int) err, line); + } +} + + +static void +Display( void ) +{ + GLubyte *buffer = malloc(Width * Height * 4); + GLenum status; + + CheckError(__LINE__); + + /* draw to user framebuffer */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + glDrawBuffer(GL_COLOR_ATTACHMENT1_EXT); + glReadBuffer(GL_COLOR_ATTACHMENT1_EXT); + + status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) { + printf("fbotest3: Error: Framebuffer is incomplete!!!\n"); + } + + CheckError(__LINE__); + + glClearColor(0.5, 0.5, 1.0, 0.0); + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glPushMatrix(); + glRotatef(30.0, 1, 0, 0); + glRotatef(Rotation, 0, 1, 0); + glutSolidTeapot(2.0); + glPopMatrix(); + + /* read from user framebuffer */ + glReadPixels(0, 0, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + /* draw to window */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + glDisable(GL_DEPTH_TEST); /* in case window has depth buffer */ + glWindowPos2iARB(0, 0); + glDrawPixels(Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + + free(buffer); + glutSwapBuffers(); + CheckError(__LINE__); +} + + +static void +Reshape( int width, int height ) +{ + float ar = (float) width / (float) height; + + glViewport( 0, 0, width, height ); + glMatrixMode( GL_PROJECTION ); + glLoadIdentity(); + glFrustum( -ar, ar, -1.0, 1.0, 5.0, 25.0 ); + + glMatrixMode( GL_MODELVIEW ); + glLoadIdentity(); + glTranslatef( 0.0, 0.0, -15.0 ); + + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, width, height); + + Width = width; + Height = height; +} + + +static void +CleanUp(void) +{ + glDeleteFramebuffersEXT(1, &MyFB); + glDeleteRenderbuffersEXT(1, &ColorRb); + glDeleteRenderbuffersEXT(1, &DepthRb); + glDeleteTextures(1, &Tex); + assert(!glIsFramebufferEXT(MyFB)); + assert(!glIsRenderbufferEXT(ColorRb)); + assert(!glIsRenderbufferEXT(DepthRb)); + glutDestroyWindow(Win); + exit(0); +} + + +static void +Idle(void) +{ + Rotation = glutGet(GLUT_ELAPSED_TIME) * 0.1; + glutPostRedisplay(); +} + + +static void +Key( unsigned char key, int x, int y ) +{ + (void) x; + (void) y; + switch (key) { + case 'a': + Animate = !Animate; + if (Animate) + glutIdleFunc(Idle); + else + glutIdleFunc(NULL); + break; + case 27: + CleanUp(); + break; + } + glutPostRedisplay(); +} + + +static void +Init( void ) +{ + if (!glutExtensionSupported("GL_EXT_framebuffer_object")) { + printf("fbotest3: GL_EXT_framebuffer_object not found!\n"); + exit(0); + } + printf("fbotest3: GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + + /* create initial tex obj as an RGBA texture */ + glGenTextures(1, &Tex); + glBindTexture(GL_TEXTURE_2D, Tex); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, + GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + glEnable(GL_TEXTURE_2D); + + /* draw something to make sure the texture is used */ + glBegin(GL_POINTS); + glVertex2f(0, 0); + glEnd(); + + /* done w/ texturing */ + glDisable(GL_TEXTURE_2D); + + /* Create my Framebuffer Object */ + glGenFramebuffersEXT(1, &MyFB); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, MyFB); + assert(glIsFramebufferEXT(MyFB)); + + /* Setup color renderbuffer */ + glGenRenderbuffersEXT(1, &ColorRb); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, ColorRb); + assert(glIsRenderbufferEXT(ColorRb)); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT1_EXT, + GL_RENDERBUFFER_EXT, ColorRb); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGB, Width, Height); + + /* Setup depth renderbuffer (a texture) */ + glGenRenderbuffersEXT(1, &DepthRb); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, DepthRb); + assert(glIsRenderbufferEXT(DepthRb)); + /* replace RGBA texture with Z texture */ + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, Width, Height, 0, + GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, + GL_TEXTURE_2D, Tex, 0); + + CheckError(__LINE__); + + /* restore to default */ + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + CheckError(__LINE__); +} + + +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 (Animate) + glutIdleFunc(Idle); + Init(); + glutMainLoop(); + return 0; +} |