mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2024-11-25 03:04:29 +08:00
Add tests for ARB_fp trig instructions and also for 1D texturing
This commit is contained in:
parent
5d3568f36c
commit
ab41a96ae7
@ -12,6 +12,7 @@ SOURCES = antialias.c \
|
||||
arbfpspec.c \
|
||||
arbfptest1.c \
|
||||
arbfptexture.c \
|
||||
arbfptrig.c \
|
||||
arbvptest1.c \
|
||||
arbvptest3.c \
|
||||
arbvptorus.c \
|
||||
@ -29,6 +30,7 @@ SOURCES = antialias.c \
|
||||
seccolor.c \
|
||||
sharedtex.c \
|
||||
stencilwrap.c \
|
||||
tex1d.c \
|
||||
texline.c \
|
||||
texrect.c \
|
||||
texwrap.c \
|
||||
|
156
progs/tests/arbfptrig.c
Normal file
156
progs/tests/arbfptrig.c
Normal file
@ -0,0 +1,156 @@
|
||||
/* GL_ARB_fragment_program texture test */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/glut.h>
|
||||
|
||||
#include "readtex.c"
|
||||
|
||||
|
||||
#define TEXTURE_FILE "../images/girl.rgb"
|
||||
|
||||
static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
|
||||
|
||||
#define PI 3.141592
|
||||
|
||||
static void Display( void )
|
||||
{
|
||||
glClear( GL_COLOR_BUFFER_BIT );
|
||||
|
||||
glPushMatrix();
|
||||
glRotatef(Xrot, 1.0, 0.0, 0.0);
|
||||
glRotatef(Yrot, 0.0, 1.0, 0.0);
|
||||
glRotatef(Zrot, 0.0, 0.0, 1.0);
|
||||
|
||||
glBegin(GL_POLYGON);
|
||||
glTexCoord2f(-PI, 0); glVertex2f(-1, -1);
|
||||
glTexCoord2f(PI, 0); glVertex2f( 1, -1);
|
||||
glTexCoord2f(PI, 1); glVertex2f( 1, 1);
|
||||
glTexCoord2f(-PI, 1); glVertex2f(-1, 1);
|
||||
glEnd();
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
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, -8.0 );
|
||||
}
|
||||
|
||||
|
||||
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 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 *modulate2D =
|
||||
"!!ARBfp1.0\n"
|
||||
"TEMP R0;\n"
|
||||
"MOV R0, {0,0,0,1};\n"
|
||||
"SCS R0, fragment.texcoord[0].x; \n"
|
||||
"ADD R0, R0, {1.0}.x;\n"
|
||||
"MUL R0, R0, {0.5}.x;\n"
|
||||
"MOV result.color, R0; \n"
|
||||
"END"
|
||||
;
|
||||
GLuint modulateProg;
|
||||
GLuint Texture;
|
||||
|
||||
if (!glutExtensionSupported("GL_ARB_fragment_program")) {
|
||||
printf("Error: GL_ARB_fragment_program not supported!\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
|
||||
|
||||
/* Setup the fragment program */
|
||||
glGenProgramsARB(1, &modulateProg);
|
||||
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
|
||||
glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
|
||||
strlen(modulate2D), (const GLubyte *)modulate2D);
|
||||
|
||||
printf("glGetError = 0x%x\n", (int) glGetError());
|
||||
printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
|
||||
(char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
|
||||
assert(glIsProgramARB(modulateProg));
|
||||
|
||||
glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
||||
|
||||
/* 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);
|
||||
}
|
||||
/* XXX this enable shouldn't really be needed!!! */
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glClearColor(.3, .3, .3, 0);
|
||||
}
|
||||
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
glutInit( &argc, argv );
|
||||
glutInitWindowPosition( 0, 0 );
|
||||
glutInitWindowSize( 250, 250 );
|
||||
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
|
||||
glutCreateWindow(argv[0]);
|
||||
glutReshapeFunc( Reshape );
|
||||
glutKeyboardFunc( Key );
|
||||
glutSpecialFunc( SpecialKey );
|
||||
glutDisplayFunc( Display );
|
||||
Init();
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
139
progs/tests/tex1d.c
Normal file
139
progs/tests/tex1d.c
Normal file
@ -0,0 +1,139 @@
|
||||
|
||||
/* Exercise 1D textures
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "GL/glut.h"
|
||||
|
||||
static GLuint Window = 0;
|
||||
static GLuint TexObj[2];
|
||||
static GLfloat Angle = 0.0f;
|
||||
|
||||
|
||||
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 );
|
||||
glBindTexture( GL_TEXTURE_1D, TexObj[0] );
|
||||
glBegin( GL_POLYGON );
|
||||
glTexCoord1f( 0.0 ); glVertex2f( -1.0, -1.0 );
|
||||
glTexCoord1f( 1.0 ); glVertex2f( 1.0, -1.0 );
|
||||
glTexCoord1f( 1.0 ); glVertex2f( 1.0, 1.0 );
|
||||
glTexCoord1f( 0.0 ); glVertex2f( -1.0, 1.0 );
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void idle( void )
|
||||
{
|
||||
Angle += 2.0;
|
||||
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:
|
||||
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 )
|
||||
{
|
||||
GLubyte tex[256][3];
|
||||
GLint i;
|
||||
|
||||
|
||||
glDisable( GL_DITHER );
|
||||
|
||||
/* Setup texturing */
|
||||
glEnable( GL_TEXTURE_1D );
|
||||
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
|
||||
|
||||
|
||||
/* generate texture object IDs */
|
||||
glGenTextures( 2, TexObj );
|
||||
|
||||
/* setup first texture object */
|
||||
glBindTexture( GL_TEXTURE_1D, TexObj[0] );
|
||||
|
||||
|
||||
for (i = 0; i < 256; i++) {
|
||||
GLfloat f;
|
||||
|
||||
/* map 0..255 to -PI .. PI */
|
||||
f = ((i / 255.0) - .5) * (3.141592 * 2);
|
||||
|
||||
f = sin(f);
|
||||
|
||||
/* map -1..1 to 0..255 */
|
||||
tex[i][0] = (f+1.0)/2.0 * 255.0;
|
||||
tex[i][1] = 0;
|
||||
tex[i][2] = 0;
|
||||
}
|
||||
|
||||
glTexImage1D( GL_TEXTURE_1D, 0, 3, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, tex );
|
||||
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
|
||||
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
|
||||
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT );
|
||||
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT );
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
glutInit(&argc, argv);
|
||||
glutInitWindowPosition(0, 0);
|
||||
glutInitWindowSize(300, 300);
|
||||
glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
|
||||
|
||||
Window = glutCreateWindow("Texture Objects");
|
||||
if (!Window) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
glutReshapeFunc( reshape );
|
||||
glutKeyboardFunc( key );
|
||||
/* glutIdleFunc( idle ); */
|
||||
glutDisplayFunc( draw );
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user