summaryrefslogtreecommitdiff
path: root/progs
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2010-02-05 13:48:35 +0000
committerJosé Fonseca <jfonseca@vmware.com>2010-02-05 13:48:35 +0000
commita1af8eec66c5f7ec421e8011b41c1a7c36319f9f (patch)
treebc76a431699807cf60cf8ba82ff6b3b1ff34f309 /progs
parentc036d13d7d2cc905226fe53ebd86a18da808963f (diff)
parentbee9964b29b2428ee75e2d1efc0e1d2c2518a417 (diff)
Merge remote branch 'origin/lp-binning'
Conflicts: src/gallium/auxiliary/util/u_dl.c src/gallium/auxiliary/util/u_time.h src/gallium/drivers/llvmpipe/lp_state_derived.c src/gallium/drivers/llvmpipe/lp_state_surface.c src/gallium/drivers/llvmpipe/lp_tex_cache.c src/gallium/drivers/llvmpipe/lp_tile_cache.c
Diffstat (limited to 'progs')
-rw-r--r--progs/demos/engine.c5
-rw-r--r--progs/demos/gloss.c7
-rw-r--r--progs/trivial/Makefile2
-rw-r--r--progs/trivial/SConscript2
-rw-r--r--progs/trivial/sub-tex.c137
-rw-r--r--progs/trivial/tex-quads.c143
-rw-r--r--progs/trivial/tri-scissor-tri.c58
-rw-r--r--progs/trivial/tri-z-eq.c14
8 files changed, 352 insertions, 16 deletions
diff --git a/progs/demos/engine.c b/progs/demos/engine.c
index 7e485111da..a4148357d4 100644
--- a/progs/demos/engine.c
+++ b/progs/demos/engine.c
@@ -26,6 +26,8 @@
/* Target engine speed: */
const int RPM = 100.0;
+static int Win = 0;
+
/**
* Engine description.
@@ -1154,6 +1156,7 @@ OptRotate(void)
static void
OptExit(void)
{
+ glutDestroyWindow(Win);
exit(0);
}
@@ -1323,7 +1326,7 @@ main(int argc, char *argv[])
glutInitWindowSize(WinWidth, WinHeight);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
- glutCreateWindow("OpenGL Engine Demo");
+ Win = glutCreateWindow("OpenGL Engine Demo");
glewInit();
glutReshapeFunc(Reshape);
glutMouseFunc(Mouse);
diff --git a/progs/demos/gloss.c b/progs/demos/gloss.c
index 578736b4e2..450861e577 100644
--- a/progs/demos/gloss.c
+++ b/progs/demos/gloss.c
@@ -41,6 +41,7 @@
/* for convolution */
#define FILTER_SIZE 7
+static GLint Win;
static GLint WinWidth = 500, WinHeight = 500;
static GLuint CylinderObj = 0;
static GLuint TeapotObj = 0;
@@ -214,7 +215,11 @@ static void Key( unsigned char key, int x, int y )
case ' ':
ToggleAnimate();
break;
+ case 'n':
+ Idle();
+ break;
case 27:
+ glutDestroyWindow(Win);
exit(0);
break;
}
@@ -439,7 +444,7 @@ int main( int argc, char *argv[] )
glutInitWindowSize(WinWidth, WinHeight);
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
- glutCreateWindow(argv[0] );
+ Win = glutCreateWindow(argv[0] );
glewInit();
glutReshapeFunc( Reshape );
glutKeyboardFunc( Key );
diff --git a/progs/trivial/Makefile b/progs/trivial/Makefile
index 207215dee9..6c78ae90a9 100644
--- a/progs/trivial/Makefile
+++ b/progs/trivial/Makefile
@@ -90,6 +90,8 @@ SOURCES = \
quadstrip-flat.c \
quadstrip.c \
readpixels.c \
+ sub-tex.c \
+ tex-quads.c \
tri-alpha.c \
tri-alpha-tex.c \
tri-array-interleaved.c \
diff --git a/progs/trivial/SConscript b/progs/trivial/SConscript
index e9ed1cb71e..87a4d2164b 100644
--- a/progs/trivial/SConscript
+++ b/progs/trivial/SConscript
@@ -70,6 +70,8 @@ progs = [
'quadstrip-cont',
'quadstrip-flat',
'quadstrip',
+ 'sub-tex',
+ 'tex-quads',
'tri-alpha',
'tri-blend-color',
'tri-blend-max',
diff --git a/progs/trivial/sub-tex.c b/progs/trivial/sub-tex.c
new file mode 100644
index 0000000000..0b8bb28182
--- /dev/null
+++ b/progs/trivial/sub-tex.c
@@ -0,0 +1,137 @@
+/**
+ * Draw a series of textured quads after each quad, use glTexSubImage()
+ * to change one row of the texture image.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+
+
+static GLint Win = 0;
+static GLuint Tex = 0;
+
+
+static void Init(void)
+{
+ fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ fflush(stderr);
+
+ glGenTextures(1, &Tex);
+ glBindTexture(GL_TEXTURE_2D, Tex);
+
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+}
+
+
+static void Reshape(int width, int height)
+{
+ float ar = (float) width / height;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-ar, ar, -1.0, 1.0, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+
+static void Key(unsigned char key, int x, int y)
+{
+ if (key == 27) {
+ glDeleteTextures(1, &Tex);
+ glutDestroyWindow(Win);
+ exit(1);
+ }
+ glutPostRedisplay();
+}
+
+
+static void Draw(void)
+{
+ GLubyte tex[16][16][4];
+ GLubyte row[16][4];
+ int i, j;
+
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
+ if ((i + j) & 1) {
+ tex[i][j][0] = 128;
+ tex[i][j][1] = 128;
+ tex[i][j][2] = 128;
+ tex[i][j][3] = 255;
+ }
+ else {
+ tex[i][j][0] = 255;
+ tex[i][j][1] = 255;
+ tex[i][j][2] = 255;
+ tex[i][j][3] = 255;
+ }
+ }
+ }
+
+ for (i = 0; i < 16; i++) {
+ row[i][0] = 255;
+ row[i][1] = 0;
+ row[i][2] = 0;
+ row[i][3] = 255;
+ }
+
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, tex);
+ glEnable(GL_TEXTURE_2D);
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ for (i = 0; i < 9; i++) {
+
+ glPushMatrix();
+ glTranslatef(-4.0 + i, 0, 0);
+ glScalef(0.5, 0.5, 1.0);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(1,0);
+ glVertex3f( 0.9, -0.9, 0.0);
+ glTexCoord2f(1,1);
+ glVertex3f( 0.9, 0.9, 0.0);
+ glTexCoord2f(0,1);
+ glVertex3f(-0.9, 0.9, 0.0);
+ glTexCoord2f(0,0);
+ glVertex3f(-0.9, -0.9, 0.0);
+ glEnd();
+
+ glPopMatrix();
+
+ /* replace a row of the texture image with red texels */
+ if (i * 2 < 16)
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, i*2, 16, 1,
+ GL_RGBA, GL_UNSIGNED_BYTE, row);
+ }
+
+
+ glutSwapBuffers();
+}
+
+
+int main(int argc, char **argv)
+{
+ glutInit(&argc, argv);
+ glutInitWindowSize(900, 200);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+ Win = glutCreateWindow(*argv);
+ if (!Win) {
+ exit(1);
+ }
+ glewInit();
+ Init();
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/trivial/tex-quads.c b/progs/trivial/tex-quads.c
new file mode 100644
index 0000000000..626e178b87
--- /dev/null
+++ b/progs/trivial/tex-quads.c
@@ -0,0 +1,143 @@
+/**
+ * Draw a series of quads, each with a different texture.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <GL/glew.h>
+#include <GL/glut.h>
+
+#define NUM_TEX 10
+
+static GLint Win = 0;
+static GLuint Tex[NUM_TEX];
+
+
+static void Init(void)
+{
+ int i;
+
+ fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
+ fflush(stderr);
+
+ glGenTextures(NUM_TEX, Tex);
+
+ for (i = 0; i < NUM_TEX; i++) {
+ glBindTexture(GL_TEXTURE_2D, Tex[i]);
+
+ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ }
+}
+
+
+static void Reshape(int width, int height)
+{
+ float ar = (float) width / height;
+ glViewport(0, 0, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glOrtho(-ar, ar, -1.0, 1.0, -1.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+}
+
+
+static void Key(unsigned char key, int x, int y)
+{
+ if (key == 27) {
+ glDeleteTextures(NUM_TEX, Tex);
+ glutDestroyWindow(Win);
+ exit(1);
+ }
+ glutPostRedisplay();
+}
+
+
+static void Draw(void)
+{
+ GLubyte tex[16][16][4];
+ int t, i, j;
+
+ for (t = 0; t < NUM_TEX; t++) {
+
+ for (i = 0; i < 16; i++) {
+ for (j = 0; j < 16; j++) {
+ if (i < t) {
+ /* red row */
+ tex[i][j][0] = 255;
+ tex[i][j][1] = 0;
+ tex[i][j][2] = 0;
+ tex[i][j][3] = 255;
+ }
+ else if ((i + j) & 1) {
+ tex[i][j][0] = 128;
+ tex[i][j][1] = 128;
+ tex[i][j][2] = 128;
+ tex[i][j][3] = 255;
+ }
+ else {
+ tex[i][j][0] = 255;
+ tex[i][j][1] = 255;
+ tex[i][j][2] = 255;
+ tex[i][j][3] = 255;
+ }
+ }
+ }
+
+ glBindTexture(GL_TEXTURE_2D, Tex[t]);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0,
+ GL_RGBA, GL_UNSIGNED_BYTE, tex);
+ }
+
+ glEnable(GL_TEXTURE_2D);
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ for (i = 0; i < NUM_TEX; i++) {
+
+ glBindTexture(GL_TEXTURE_2D, Tex[i]);
+
+ glPushMatrix();
+ glTranslatef(-4.0 + i, 0, 0);
+ glScalef(0.5, 0.5, 1.0);
+
+ glBegin(GL_QUADS);
+ glTexCoord2f(1,0);
+ glVertex3f( 0.9, -0.9, 0.0);
+ glTexCoord2f(1,1);
+ glVertex3f( 0.9, 0.9, 0.0);
+ glTexCoord2f(0,1);
+ glVertex3f(-0.9, 0.9, 0.0);
+ glTexCoord2f(0,0);
+ glVertex3f(-0.9, -0.9, 0.0);
+ glEnd();
+
+ glPopMatrix();
+ }
+
+
+ glutSwapBuffers();
+}
+
+
+int main(int argc, char **argv)
+{
+ glutInit(&argc, argv);
+ glutInitWindowSize(900, 200);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
+ Win = glutCreateWindow(*argv);
+ if (!Win) {
+ exit(1);
+ }
+ glewInit();
+ Init();
+ glutReshapeFunc(Reshape);
+ glutKeyboardFunc(Key);
+ glutDisplayFunc(Draw);
+ glutMainLoop();
+ return 0;
+}
diff --git a/progs/trivial/tri-scissor-tri.c b/progs/trivial/tri-scissor-tri.c
index d65502d91b..1bb15501bb 100644
--- a/progs/trivial/tri-scissor-tri.c
+++ b/progs/trivial/tri-scissor-tri.c
@@ -31,10 +31,14 @@
#define CI_OFFSET_1 16
#define CI_OFFSET_2 32
-GLint Width = 250, Height = 250;
+GLint Width = 300, Height = 300;
GLenum doubleBuffer;
+/* scissor bounds */
+static GLint Left, Right, Bottom, Top;
+
+
static void Init(void)
{
fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
@@ -47,26 +51,57 @@ static void Init(void)
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);
+
+ Width = width;
+ Height = height;
+
+ Left = Width / 4;
+ Right = Width * 3 / 4;
+ Bottom = Height / 4;
+ Top = Height * 3 / 4;
}
static void Key(unsigned char key, int x, int y)
{
+ int step = 2;
+ switch (key) {
+ case 'l':
+ Left -= step;
+ break;
+ case 'L':
+ Left += step;
+ break;
+ case 'r':
+ Right -= step;
+ break;
+ case 'R':
+ Right += step;
+ break;
+ case 'b':
+ Bottom -= step;
+ break;
+ case 'B':
+ Bottom += step;
+ break;
+ case 't':
+ Top -= step;
+ break;
+ case 'T':
+ Top += step;
+ break;
+ case 27:
+ exit(1);
+ default:
+ ;
+ }
- switch (key) {
- case 27:
- exit(1);
- default:
- break;
- }
-
- glutPostRedisplay();
+ glutPostRedisplay();
}
static void Draw(void)
@@ -82,7 +117,8 @@ static void Draw(void)
glVertex3f(-0.9, 0.0, -30.0);
glEnd();
- glScissor(Width / 4, Height / 4, Width / 2, Height / 2);
+ printf("Scissor %d, %d .. %d, %d\n", Left, Bottom, Right, Top);
+ glScissor(Left, Bottom, Right-Left, Top-Bottom);
glEnable(GL_SCISSOR_TEST);
glBegin(GL_TRIANGLES);
diff --git a/progs/trivial/tri-z-eq.c b/progs/trivial/tri-z-eq.c
index 6bdac47419..c04ffae7f1 100644
--- a/progs/trivial/tri-z-eq.c
+++ b/progs/trivial/tri-z-eq.c
@@ -69,6 +69,8 @@ static void Key(unsigned char key, int x, int y)
static void Draw(void)
{
+ float z = 1.0;
+
glClearColor(0.0, 0.0, 1.0, 0.0);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -77,15 +79,21 @@ static void Draw(void)
glBegin(GL_TRIANGLES);
glColor3f(0,0,.7);
- glVertex3f( 0.9, -0.9, 1.0);
+ glVertex3f( 0.9, -0.9, z);
glColor3f(.8,0,0);
- glVertex3f( 0.9, 0.9, 1.0);
+ glVertex3f( 0.9, 0.9, z);
glColor3f(0,.9,0);
- glVertex3f(-0.9, 0.0, 1.0);
+ glVertex3f(-0.9, 0.0, z);
glEnd();
glFlush();
+ {
+ GLfloat z;
+ glReadPixels(125, 125, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &z);
+ printf("Z at (125, 125) = %f\n", z);
+ }
+
if (doubleBuffer) {
glutSwapBuffers();
}