static void Init( GLboolean ciMode ) { GLboolean have_read_format = GL_FALSE; printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat ); if (!Image) { printf("Couldn't read %s\n", IMAGE_FILE); exit(0); } if (ciMode) { /* Convert RGB image to grayscale */ GLubyte *indexImage = (GLubyte *) malloc( ImgWidth * ImgHeight ); GLint i; for (i=0; i<ImgWidth*ImgHeight; i++) { int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2]; indexImage[i] = gray / 3; } free(Image); Image = indexImage; ImgFormat = GL_COLOR_INDEX; for (i=0;i<255;i++) { float g = i / 255.0; glutSetColor(i, g, g, g); } } #ifdef GL_OES_read_format if ( glutExtensionSupported( "GL_OES_read_format" ) ) { glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, (GLint *) &ReadType); glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, (GLint *) &ReadFormat); have_read_format = GL_TRUE; } #endif printf( "GL_OES_read_format %ssupported. " "Using type / format = 0x%04x / 0x%04x\n", (have_read_format) ? "" : "not ", ReadType, ReadFormat ); printf("Loaded %d by %d image\n", ImgWidth, ImgHeight ); glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth); glPixelStorei(GL_PACK_ROW_LENGTH, ImgWidth); Reset(); /* allocate large TempImage to store and image data type, plus an * extra 1KB in case we're tinkering with pack alignment. */ TempImage = (GLubyte *) malloc(ImgWidth * ImgHeight * 4 * 4 + 1000); assert(TempImage); }
static void readTexture(const char *filename) { GLubyte *data; texture.x = 0; texture.y = 0; glGenTextures(1, &texture.id); glBindTexture(GL_TEXTURE_2D, texture.id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 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_REPLACE); data = LoadRGBImage(filename, &texture.width, &texture.height, &texture.format); if (!data) { printf("Error: couldn't load texture image '%s'\n", filename); exit(1); } printf("Texture %s (%d x %d)\n", filename, texture.width, texture.height); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, texture.width, texture.height, 0, texture.format, GL_UNSIGNED_BYTE, data); }
static void InitWindow(struct window *w) { GLint imgWidth, imgHeight; GLenum imgFormat; GLubyte *image = NULL; w->table_list = MakeTable(); MakeObjects(w->objects_list); image = LoadRGBImage( TABLE_TEXTURE, &imgWidth, &imgHeight, &imgFormat ); if (!image) { printf("Couldn't read %s\n", TABLE_TEXTURE); exit(0); } gluBuild2DMipmaps(GL_TEXTURE_2D, 3, imgWidth, imgHeight, imgFormat, GL_UNSIGNED_BYTE, image); free(image); 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, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glShadeModel( GL_FLAT ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHTING ); glClearColor( 0.5, 0.5, 0.9, 0.0 ); glEnable( GL_NORMALIZE ); }
TextureID LoadFontTexture(string Filename) { TEXTURE_RGBA Texture; TEXTURE_RGB image; ubyte *ip, *tp; TextureID ret; LoadRGBImage(image, Filename); Texture.sizeX = image.sizeX; Texture.sizeY = image.sizeY; Texture.buffer = unique_ptr<ubyte[]>(new unsigned char[image.sizeX * image.sizeY * 4]); if (Texture.buffer == nullptr) { printf("[console][Warning] Cannot alloc memory when loading %s\n", Filename.c_str()); return 0; } ip = image.buffer.get(); tp = Texture.buffer.get(); for (unsigned int i = 0; i != image.sizeX*image.sizeY; i++) { *tp = 255; tp++; *tp = 255; tp++; *tp = 255; tp++; *tp = 255 - *ip; tp++; ip += 3; } glGenTextures(1, &ret); glBindTexture(GL_TEXTURE_2D, ret); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Texture.sizeX, Texture.sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, Texture.buffer.get()); return ret; }
static void init( void ) { #ifdef GL_ARB_window_pos if (glutExtensionSupported("GL_ARB_window_pos")) { printf("Using GL_ARB_window_pos\n"); WindowPosFunc = &glWindowPos2fARB; } else #elif defined(GL_MESA_window_pos) if (glutExtensionSupported("GL_MESA_window_pos")) { printf("Using GL_MESA_window_pos\n"); WindowPosFunc = &glWindowPos2fMESA; } else #endif { printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n"); exit(1); } Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat ); if (!Image) { printf("Couldn't read %s\n", IMAGE_FILE); exit(0); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); }
static void _glmLoadTexture(GLMmaterial *mat) { if (mat->map_kd) { GLint imgWidth, imgHeight; GLenum imgFormat; GLubyte *image = NULL; glGenTextures(1, &mat->texture_kd); image = LoadRGBImage( mat->map_kd, &imgWidth, &imgHeight, &imgFormat ); if (!image) { /*fprintf(stderr, "Couldn't open texture %s\n", mat->map_kd);*/ free(mat->map_kd); mat->map_kd = NULL; mat->texture_kd = 0; return; } if (0) printf("load texture %s %d x %d\n", mat->map_kd, imgWidth, imgHeight); glBindTexture(GL_TEXTURE_2D, mat->texture_kd); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, imgWidth, imgHeight, imgFormat, GL_UNSIGNED_BYTE, image); free(image); 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, GL_LINEAR_MIPMAP_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); } }
static void Init(void) { printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); if (!glutExtensionSupported("GL_EXT_pixel_buffer_object")) { printf("Sorry, this demo requires GL_EXT_pixel_buffer_object\n"); exit(0); } Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat ); if (!Image) { printf("Couldn't read %s\n", IMAGE_FILE); exit(0); } printf("Loaded %d by %d image\n", ImgWidth, ImgHeight ); if (ImgFormat == GL_RGB) { /* convert to RGBA */ int i; GLubyte *image2 = (GLubyte *) malloc(ImgWidth * ImgHeight * 4); printf("Converting RGB image to RGBA\n"); for (i = 0; i < ImgWidth * ImgHeight; i++) { image2[i*4+0] = Image[i*3+0]; image2[i*4+1] = Image[i*3+1]; image2[i*4+2] = Image[i*3+2]; image2[i*4+3] = 255; } free(Image); Image = image2; ImgFormat = GL_RGBA; } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth); glPixelStorei(GL_PACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ROW_LENGTH, ImgWidth); Reset(); /* put image into DrawPBO */ glGenBuffersARB(1, &DrawPBO); glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_EXT, DrawPBO); glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_EXT, ImgWidth * ImgHeight * 4, Image, GL_STATIC_DRAW); /* Setup TempPBO - used for glReadPixels & glDrawPixels */ glGenBuffersARB(1, &TempPBO); glBindBufferARB(GL_PIXEL_PACK_BUFFER_EXT, TempPBO); glBufferDataARB(GL_PIXEL_PACK_BUFFER_EXT, ImgWidth * ImgHeight * 4, NULL, GL_DYNAMIC_COPY); }
static void Init( void ) { const char * const ver_string = (const char * const) glGetString( GL_VERSION ); const float ver = strtof( ver_string, NULL ); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_VERSION = %s\n", ver_string); if ( !glutExtensionSupported("GL_MESA_pack_invert") ) { printf("\nSorry, this program requires GL_MESA_pack_invert.\n"); exit(1); } if ( ver >= 1.4 ) { win_pos_2i = (PFNGLWINDOWPOS2IPROC) glutGetProcAddress( "glWindowPos2i" ); } else if ( glutExtensionSupported("GL_ARB_window_pos") ) { win_pos_2i = (PFNGLWINDOWPOS2IPROC) glutGetProcAddress( "glWindowPos2iARB" ); } else if ( glutExtensionSupported("GL_MESA_window_pos") ) { win_pos_2i = (PFNGLWINDOWPOS2IPROC) glutGetProcAddress( "glWindowPos2iMESA" ); } /* Do this check as a separate if-statement instead of as an else in case * one of the required extensions is supported but glutGetProcAddress * returns NULL. */ if ( win_pos_2i == NULL ) { printf("\nSorry, this program requires either GL 1.4 (or higher),\n" "GL_ARB_window_pos, or GL_MESA_window_pos.\n"); exit(1); } printf("\nThe left 2 squares should be the same color, and the right\n" "square should look upside-down.\n"); image = LoadRGBImage( IMAGE_FILE, & img_width, & img_height, & img_format ); if ( image == NULL ) { printf( "Could not open image file \"%s\".\n", IMAGE_FILE ); exit(1); } temp_image = malloc( 3 * img_height * img_width ); if ( temp_image == NULL ) { printf( "Could not allocate memory for temporary image.\n" ); exit(1); } }
TextureID LoadRGBTexture(string Filename) { TEXTURE_RGB image; TextureID ret; LoadRGBImage(image, Filename); glGenTextures(1, &ret); glBindTexture(GL_TEXTURE_2D, ret); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.sizeX, image.sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image.buffer.get()); return ret; }
static void Init(void) { Image[0] = LoadRGBImage(FILE1, &ImgWidth[0], &ImgHeight[0], &ImgFormat[0]); if (!Image[0]) { printf("Couldn't read %s\n", FILE1); exit(0); } Image[1] = LoadRGBImage(FILE2, &ImgWidth[1], &ImgHeight[1], &ImgFormat[1]); if (!Image[1]) { printf("Couldn't read %s\n", FILE2); exit(0); } glEnable(GL_STENCIL_TEST); glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); }
static void Init(void) { Image = LoadRGBImage(IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat); if (!Image) { printf("Couldn't read %s\n", IMAGE_FILE); exit(0); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_PACK_ALIGNMENT, 1); }
TextureID LoadRGBTexture(string Filename) { TEXTURE_RGB image; TextureID ret; LoadRGBImage(image, Filename); glGenTextures(1, &ret); glBindTexture(GL_TEXTURE_2D, ret); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, (int)log(image.sizeX)); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image.sizeX, image.sizeY, GL_RGB, GL_UNSIGNED_BYTE, image.buffer.get()); return ret; }
static void load(GLenum target, const char *filename, GLboolean flipTB, GLboolean flipLR) { GLint w, h; GLenum format; GLubyte *img = LoadRGBImage( filename, &w, &h, &format ); if (!img) { printf("Error: couldn't load texture image %s\n", filename); exit(1); } assert(format == GL_RGB); /* <sigh> the way the texture cube mapping works, we have to flip * images to make things look right. */ if (flipTB) { const int stride = 3 * w; GLubyte temp[3*1024]; int i; for (i = 0; i < h / 2; i++) { memcpy(temp, img + i * stride, stride); memcpy(img + i * stride, img + (h - i - 1) * stride, stride); memcpy(img + (h - i - 1) * stride, temp, stride); } } if (flipLR) { const int stride = 3 * w; GLubyte temp[3]; GLubyte *row; int i, j; for (i = 0; i < h; i++) { row = img + i * stride; for (j = 0; j < w / 2; j++) { int k = w - j - 1; temp[0] = row[j*3+0]; temp[1] = row[j*3+1]; temp[2] = row[j*3+2]; row[j*3+0] = row[k*3+0]; row[j*3+1] = row[k*3+1]; row[j*3+2] = row[k*3+2]; row[k*3+0] = temp[0]; row[k*3+1] = temp[1]; row[k*3+2] = temp[2]; } } } gluBuild2DMipmaps(target, GL_RGB, w, h, format, GL_UNSIGNED_BYTE, img); free(img); }
static void load_tex(const char *fname, int channel) { GLubyte *image; GLenum format; GLint w, h; GLubyte *grayImage; int i; GLubyte table[256][4]; image = LoadRGBImage(fname, &w, &h, &format); if (!image) exit(1); printf("%s %d x %d\n", fname, w, h); grayImage = malloc(w * h * 1); assert(grayImage); for (i = 0; i < w * h; i++) { int g = (image[i*3+0] + image[i*3+1] + image[i*3+2]) / 3; assert(g < 256); grayImage[i] = g; } glTexImage2D(GL_TEXTURE_2D, 0, GL_COLOR_INDEX, w, h, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, grayImage); for (i = 0; i < 256; i++) { table[i][0] = channel ? i : 0; table[i][1] = i; table[i][2] = channel ? 0 : i; table[i][3] = 255; } glColorTableEXT(GL_TEXTURE_2D, /* target */ GL_RGBA, /* internal format */ 256, /* table size */ GL_RGBA, /* table format */ GL_UNSIGNED_BYTE, /* table type */ table); /* the color table */ free(grayImage); free(image); }
static void init( void ) { if (GLEW_ARB_window_pos) { printf("Using GL_ARB_window_pos\n"); WindowPosFunc = glWindowPos2fARB; } else if (GLEW_MESA_window_pos) { printf("Using GL_MESA_window_pos\n"); WindowPosFunc = glWindowPos2fMESA; } else { printf("Sorry, GL_ARB/MESA_window_pos extension not available.\n"); exit(1); } Image = LoadRGBImage( IMAGE_FILE, &ImgWidth, &ImgHeight, &ImgFormat ); if (!Image) { printf("Couldn't read %s\n", IMAGE_FILE); exit(0); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); }
static void Init( GLboolean ciMode, const char *filename ) { printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); Image = LoadRGBImage( filename, &ImgWidth, &ImgHeight, &ImgFormat ); if (!Image) { printf("Couldn't read %s\n", filename); exit(0); } if (ciMode) { /* Convert RGB image to grayscale */ GLubyte *indexImage = (GLubyte *) malloc( ImgWidth * ImgHeight ); GLint i; for (i=0; i<ImgWidth*ImgHeight; i++) { int gray = Image[i*3] + Image[i*3+1] + Image[i*3+2]; indexImage[i] = gray / 3; } free(Image); Image = indexImage; ImgFormat = GL_COLOR_INDEX; for (i=0;i<255;i++) { float g = i / 255.0; glutSetColor(i, g, g, g); } } printf("Loaded %d by %d image\n", ImgWidth, ImgHeight ); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ROW_LENGTH, ImgWidth); Reset(); }
static void Init( void ) { GLubyte *image; int imgWidth, imgHeight, minDim, w; GLenum imgFormat; if (!glutExtensionSupported("GL_ARB_texture_non_power_of_two")) { printf("Sorry, this program requires GL_ARB_texture_non_power_of_two\n"); exit(1); } #if 1 image = LoadRGBImage( IMAGE_FILE, &imgWidth, &imgHeight, &imgFormat ); if (!image) { printf("Couldn't read %s\n", IMAGE_FILE); exit(0); } #else int i, j; imgFormat = GL_RGB; imgWidth = 3; imgHeight = 3; image = malloc(imgWidth * imgHeight * 3); for (i = 0; i < imgHeight; i++) { for (j = 0; j < imgWidth; j++) { int k = (i * imgWidth + j) * 3; if ((i + j) & 1) { image[k+0] = 255; image[k+1] = 0; image[k+2] = 0; } else { image[k+0] = 0; image[k+1] = 255; image[k+2] = 0; } } } #endif printf("Read %d x %d\n", imgWidth, imgHeight); minDim = imgWidth < imgHeight ? imgWidth : imgHeight; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, imgWidth, 0, imgFormat, GL_UNSIGNED_BYTE, image); assert(glGetError() == GL_NO_ERROR); glTexImage1D(GL_PROXY_TEXTURE_1D, 0, GL_RGB, imgWidth, 0, imgFormat, GL_UNSIGNED_BYTE, image); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_WIDTH, &w); assert(w == imgWidth); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0, imgFormat, GL_UNSIGNED_BYTE, image); assert(glGetError() == GL_NO_ERROR); glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0, imgFormat, GL_UNSIGNED_BYTE, image); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w); assert(w == imgWidth); glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, imgWidth, imgHeight, 1, 0, imgFormat, GL_UNSIGNED_BYTE, image); assert(glGetError() == GL_NO_ERROR); glTexImage3D(GL_PROXY_TEXTURE_3D, 0, GL_RGB, imgWidth, imgHeight, 1, 0, imgFormat, GL_UNSIGNED_BYTE, image); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &w); assert(w == imgWidth); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB, minDim, minDim, 0, imgFormat, GL_UNSIGNED_BYTE, image); assert(glGetError() == GL_NO_ERROR); glTexImage2D(GL_PROXY_TEXTURE_CUBE_MAP, 0, GL_RGB, minDim, minDim, 0, imgFormat, GL_UNSIGNED_BYTE, image); glGetTexLevelParameteriv(GL_PROXY_TEXTURE_CUBE_MAP, 0, GL_TEXTURE_WIDTH, &w); assert(w == minDim); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glEnable(GL_TEXTURE_2D); }
static void Init(void) { float ambient[] = {0.0, 0.0, 0.0, 1.0}; float diffuse[] = {1.0, 1.0, 1.0, 1.0}; float specular[] = {1.0, 1.0, 1.0, 1.0}; float position[] = {0.0, 0.0, 4.0, 0.0}; float fog_color[] = {0.0, 0.0, 0.0, 1.0}; float mat_ambient[] = {0.0, 0.0, 0.0, 1.0}; float mat_shininess[] = {90.0}; float mat_specular[] = {1.0, 1.0, 1.0, 1.0}; float mat_diffuse[] = {0.8, 0.8, 0.8, 1.0}; float lmodel_ambient[] = {0.2, 0.2, 0.2, 1.0}; float lmodel_twoside[] = {GL_TRUE}; int w, h; GLenum format; GLubyte *image; printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); SetDefaultSettings(); image = LoadRGBImage(imageFileName, &w, &h, &format); if (!image) { printf("Error: couldn't load %s\n", imageFileName); exit(1); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); gluBuild2DMipmaps(GL_TEXTURE_2D, format, w, h, GL_RGB, GL_UNSIGNED_BYTE, image); free(image); glFogf(GL_FOG_DENSITY, 0.125); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, 4.0); glFogf(GL_FOG_END, 8.5); glFogfv(GL_FOG_COLOR, fog_color); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, specular); glLightfv(GL_LIGHT0, GL_POSITION, position); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); glShadeModel(GL_SMOOTH); glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glFrontFace(GL_CW); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glTexGeniv(GL_S, GL_TEXTURE_GEN_MODE, sphereMap); glTexGeniv(GL_T, GL_TEXTURE_GEN_MODE, sphereMap); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magFilter); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, sWrapMode); glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, tWrapMode); glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, textureEnvironment); BuildLists(); }
static void inittextures(void) { GLenum gluerr; GLubyte tex[128][128][4]; glGenTextures(1, &groundid); glBindTexture(GL_TEXTURE_2D, groundid); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); #ifndef MONA if (!LoadRGBMipmaps("../images/s128.rgb", GL_RGB)) { #else if (!LoadRGBMipmaps("/MESA/S128.RGB", GL_RGB)) { #endif fprintf(stderr, "Error reading a texture.\n"); exit(-1); } 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_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glGenTextures(1, &treeid); glBindTexture(GL_TEXTURE_2D, treeid); if (1) { int w, h; GLenum format; int x, y; GLubyte *image = LoadRGBImage("../images/tree3.rgb", &w, &h, &format); if (!image) { fprintf(stderr, "Error reading a texture.\n"); exit(-1); } for (y = 0; y < 128; y++) for (x = 0; x < 128; x++) { tex[x][y][0] = image[(y + x * 128) * 3]; tex[x][y][1] = image[(y + x * 128) * 3 + 1]; tex[x][y][2] = image[(y + x * 128) * 3 + 2]; if ((tex[x][y][0] == tex[x][y][1]) && (tex[x][y][1] == tex[x][y][2]) && (tex[x][y][2] == 255)) tex[x][y][3] = 0; else tex[x][y][3] = 255; } if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) (tex)))) { fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr)); exit(-1); } } else { if (!LoadRGBMipmaps("../images/tree2.rgba", GL_RGBA)) { fprintf(stderr, "Error reading a texture.\n"); exit(-1); } } 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_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } static void inittree(void) { int i; float dist; for (i = 0; i < NUMTREE; i++) do { treepos[i][0] = vrnd() * TREEOUTR * 2.0 - TREEOUTR; treepos[i][1] = 0.0; treepos[i][2] = vrnd() * TREEOUTR * 2.0 - TREEOUTR; dist = sqrt(treepos[i][0] * treepos[i][0] + treepos[i][2] * treepos[i][2]); } while ((dist < TREEINR) || (dist > TREEOUTR)); }
static void Init( int argc, char *argv[] ) { GLboolean convolve = GL_FALSE; GLboolean fullscreen = GL_FALSE; int i; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-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)); } else if (strcmp(argv[i], "-c")==0) { convolve = GL_TRUE; } else if (strcmp(argv[i], "-f")==0) { fullscreen = GL_TRUE; } } if (fullscreen) glutFullScreen(); /* Cylinder object */ { static GLfloat height = 100.0; static GLfloat radius = 40.0; static GLint slices = 24; /* pie slices around Z axis */ static GLint stacks = 10; /* subdivisions along length of cylinder */ static GLint rings = 4; /* rings in the end disks */ GLUquadricObj *q = gluNewQuadric(); assert(q); gluQuadricTexture(q, GL_TRUE); CylinderObj = glGenLists(1); glNewList(CylinderObj, GL_COMPILE); glPushMatrix(); glTranslatef(0.0, 0.0, -0.5 * height); glMatrixMode(GL_TEXTURE); glLoadIdentity(); /*glScalef(8.0, 4.0, 2.0);*/ glMatrixMode(GL_MODELVIEW); /* cylinder */ gluQuadricNormals(q, GL_SMOOTH); gluQuadricTexture(q, GL_TRUE); gluCylinder(q, radius, radius, height, slices, stacks); /* end cap */ glMatrixMode(GL_TEXTURE); glLoadIdentity(); glScalef(3.0, 3.0, 1.0); glMatrixMode(GL_MODELVIEW); glTranslatef(0.0, 0.0, height); gluDisk(q, 0.0, radius, slices, rings); /* other end cap */ glTranslatef(0.0, 0.0, -height); gluQuadricOrientation(q, GLU_INSIDE); gluDisk(q, 0.0, radius, slices, rings); glPopMatrix(); glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glEndList(); gluDeleteQuadric(q); } /* Teapot */ { TeapotObj = glGenLists(1); glNewList(TeapotObj, GL_COMPILE); glFrontFace(GL_CW); glutSolidTeapot(40.0); glFrontFace(GL_CCW); glEndList(); } /* show cylinder by default */ Object = CylinderObj; /* lighting */ glEnable(GL_LIGHTING); { GLfloat pos[4] = { 3, 3, 3, 1 }; glLightfv(GL_LIGHT0, GL_AMBIENT, Black); glLightfv(GL_LIGHT0, GL_DIFFUSE, White); glLightfv(GL_LIGHT0, GL_SPECULAR, White); glLightfv(GL_LIGHT0, GL_POSITION, pos); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT, GL_AMBIENT, Black); glMaterialf(GL_FRONT, GL_SHININESS, Shininess); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1); } /* Base texture */ glGenTextures(1, &BaseTexture); glBindTexture(GL_TEXTURE_2D, BaseTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); if (!LoadRGBMipmaps(BASE_TEXTURE_FILE, GL_RGB)) { printf("Error: couldn't load texture image file %s\n", BASE_TEXTURE_FILE); exit(1); } /* Specular texture */ glGenTextures(1, &SpecularTexture); glBindTexture(GL_TEXTURE_2D, SpecularTexture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); if (convolve) { /* use convolution to blur the texture to simulate a dull finish * on the object. */ GLubyte *img; GLenum format; GLint w, h; GLfloat filter[FILTER_SIZE][FILTER_SIZE][4]; for (h = 0; h < FILTER_SIZE; h++) { for (w = 0; w < FILTER_SIZE; w++) { const GLfloat k = 1.0 / (FILTER_SIZE * FILTER_SIZE); filter[h][w][0] = k; filter[h][w][1] = k; filter[h][w][2] = k; filter[h][w][3] = k; } } glEnable(GL_CONVOLUTION_2D); glConvolutionParameteri(GL_CONVOLUTION_2D, GL_CONVOLUTION_BORDER_MODE, GL_CONSTANT_BORDER); glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_RGBA, FILTER_SIZE, FILTER_SIZE, GL_RGBA, GL_FLOAT, filter); img = LoadRGBImage(SPECULAR_TEXTURE_FILE, &w, &h, &format); if (!img) { printf("Error: couldn't load texture image file %s\n", SPECULAR_TEXTURE_FILE); exit(1); } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, format, GL_UNSIGNED_BYTE, img); free(img); } else { /* regular path */ if (!LoadRGBMipmaps(SPECULAR_TEXTURE_FILE, GL_RGB)) { printf("Error: couldn't load texture image file %s\n", SPECULAR_TEXTURE_FILE); exit(1); } } /* misc */ glEnable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glPolygonOffset( -1, -1 ); }
static void inittextures(void) { GLenum gluerr; GLubyte tex[128][128][4]; glGenTextures(1, &groundid); glBindTexture(GL_TEXTURE_2D, groundid); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); if (!LoadRGBMipmaps(DEMOS_DATA_DIR "s128.rgb", GL_RGB)) { fprintf(stderr, "Error reading a texture.\n"); exit(-1); } 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_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glGenTextures(1, &treeid); glBindTexture(GL_TEXTURE_2D, treeid); if (1) { int w, h; GLenum format; int x, y; GLubyte *image = LoadRGBImage(DEMOS_DATA_DIR "tree3.rgb", &w, &h, &format); if (!image) { fprintf(stderr, "Error reading a texture.\n"); exit(-1); } for (y = 0; y < 128; y++) for (x = 0; x < 128; x++) { tex[x][y][0] = image[(y + x * 128) * 3]; tex[x][y][1] = image[(y + x * 128) * 3 + 1]; tex[x][y][2] = image[(y + x * 128) * 3 + 2]; if ((tex[x][y][0] == tex[x][y][1]) && (tex[x][y][1] == tex[x][y][2]) && (tex[x][y][2] == 255)) tex[x][y][3] = 0; else tex[x][y][3] = 255; } if ((gluerr = gluBuild2DMipmaps(GL_TEXTURE_2D, 4, 128, 128, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) (tex)))) { fprintf(stderr, "GLULib%s\n", (char *) gluErrorString(gluerr)); exit(-1); } } else { if (!LoadRGBMipmaps(DEMOS_DATA_DIR "tree2.rgba", GL_RGBA)) { fprintf(stderr, "Error reading a texture.\n"); exit(-1); } } 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_LINEAR_MIPMAP_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); }
static void makeImages(int image) { #define WIDTH 512 #define HEIGHT 512 if (glutExtensionSupported("GL_SGIS_generate_mipmap") && image) { /* test auto mipmap generation */ GLint width, height, i; GLenum format; GLubyte *image = LoadRGBImage(TEXTURE_FILE, &width, &height, &format); if (!image) { printf("Error: could not load texture image %s\n", TEXTURE_FILE); exit(1); } /* resize */ if (width != WIDTH || height != HEIGHT) { GLubyte *newImage = malloc(WIDTH * HEIGHT * 4); gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, WIDTH, HEIGHT, GL_UNSIGNED_BYTE, newImage); free(image); image = newImage; } printf("Using GL_SGIS_generate_mipmap\n"); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); glTexImage2D(GL_TEXTURE_2D, 0, format, WIDTH, HEIGHT, 0, format, GL_UNSIGNED_BYTE, image); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE); free(image); /* make sure mipmap was really generated correctly */ width = WIDTH; height = HEIGHT; for (i = 0; i < 10; i++) { GLint w, h; glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); printf("Level %d size: %d x %d\n", i, w, h); width /= 2; height /= 2; } } else { static const GLubyte colors[10][3] = { {128, 128, 128}, {0, 255, 255}, {255, 255, 0}, {255, 0, 255}, {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {0, 255, 255}, {255, 255, 0}, {255, 255, 255} }; int i, sz = 512; for (i = 0; i < 10; i++) { MakeImage(i, sz, sz, colors[i]); printf("Level %d size: %d x %d\n", i, sz, sz); sz /= 2; } } }
static void Init( int argc, char *argv[] ) { const char *file; GLenum format; if (!glutExtensionSupported("GL_MESA_ycbcr_texture")) { printf("Sorry, GL_MESA_ycbcr_texture is required\n"); exit(0); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); if (argc > 1) file = argv[1]; else file = TEXTURE_FILE; /* First load the texture as YCbCr. */ glBindTexture(GL_TEXTURE_2D, yuvObj); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ImageYUV = LoadYUVImage(file, &ImgWidth, &ImgHeight ); if (!ImageYUV) { printf("Couldn't read %s\n", TEXTURE_FILE); exit(0); } printf("Image: %dx%d\n", ImgWidth, ImgHeight); glTexImage2D(GL_TEXTURE_2D, 0, GL_YCBCR_MESA, ImgWidth, ImgHeight, 0, GL_YCBCR_MESA, GL_UNSIGNED_SHORT_8_8_MESA, ImageYUV); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); /* Now load the texture as RGB. */ glBindTexture(GL_TEXTURE_2D, rgbObj); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ImageRGB = LoadRGBImage(file, &ImgWidth, &ImgHeight, &format ); if (!ImageRGB) { printf("Couldn't read %s\n", TEXTURE_FILE); exit(0); } printf("Image: %dx%d\n", ImgWidth, ImgHeight); glTexImage2D(GL_TEXTURE_2D, 0, format, ImgWidth, ImgHeight, 0, format, GL_UNSIGNED_BYTE, ImageRGB); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glShadeModel(GL_FLAT); 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)); } printf( "Both images should appear the same.\n" ); }
static void LoadTextures(GLuint n, const char *files[]) { GLuint i; NumTextures = n < MAX_TEXTURES ? n : MAX_TEXTURES; glGenTextures(n, Textures); SetTexParams(); for (i = 0; i < n; i++) { GLint w, h; glBindTexture(GL_TEXTURE_2D, Textures[i]); #if TEST_MIPMAPS { static const GLubyte color[9][4] = { {255, 0, 0}, {0, 255, 0}, {0, 0, 255}, {0, 255, 255}, {255, 0, 255}, {255, 255, 0}, {255, 128, 255}, {128, 128, 128}, {64, 64, 64} }; GLubyte image[256*256*4]; int i, level; w = h = 256; for (level = 0; level <= 8; level++) { for (i = 0; i < w * h; i++) { image[i*4+0] = color[level][0]; image[i*4+1] = color[level][1]; image[i*4+2] = color[level][2]; image[i*4+3] = color[level][3]; } printf("Load level %d: %d x %d\n", level, w>>level, h>>level); glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, w>>level, h>>level, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); } } #elif TEST_GEN_COMPRESSED_MIPMAPS { GLenum intFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; int f; GLenum format; GLubyte *img = LoadRGBImage(files[i], &w, &h, &format); GLboolean write_compressed = GL_FALSE; GLboolean read_compressed = GL_FALSE; glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexImage2D(GL_TEXTURE_2D, 0, intFormat, w, h, 0, format, GL_UNSIGNED_BYTE, img); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE); free(img); glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_INTERNAL_FORMAT, &f); printf("actual internal format 0x%x\n", f); if (write_compressed) { GLint i, sz, w, h; int num_levels = 8; for (i = 0; i < num_levels; i++) { char name[20], *buf; FILE *f; glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sz); printf("Writing level %d: %d x %d bytes: %d\n", i, w, h, sz); buf = malloc(sz); glGetCompressedTexImageARB(GL_TEXTURE_2D, i, buf); sprintf(name, "comp%d", i); f = fopen(name, "w"); fwrite(buf, 1, sz, f); fclose(f); free(buf); } } if (read_compressed) { GLint i, sz, w, h; int num_levels = 8; for (i = 01; i < num_levels; i++) { char name[20], *buf; FILE *f; glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_COMPRESSED_IMAGE_SIZE, &sz); buf = malloc(sz); sprintf(name, "comp%d", i); printf("Reading level %d: %d x %d bytes: %d from %s\n", i, w, h, sz, name); f = fopen(name, "r"); fread(buf, 1, sz, f); fclose(f); glCompressedTexImage2DARB(GL_TEXTURE_2D, i, intFormat, w, h, 0, sz, buf); free(buf); } } } #else if (!LoadRGBMipmaps2(files[i], GL_TEXTURE_2D, GL_RGB, &w, &h)) { printf("Error: couldn't load %s\n", files[i]); exit(1); } #endif TexAspect[i] = (float) w / (float) h; printf("Loaded %s\n", files[i]); } }
static void Init( void ) { const char * const ver_string = (const char *) glGetString( GL_VERSION ); GLfloat temp[16][16][2]; GLubyte *image = NULL; GLint imgWidth, imgHeight; GLenum imgFormat; GLint i,j; GLint param, paramArray[16]; GLfloat paramMat[4]; printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); printf("GL_VERSION = %s\n", ver_string); if ( !glutExtensionSupported("GL_ATI_envmap_bumpmap")) { printf("\nSorry, this program requires GL_ATI_envmap_bumpmap\n"); exit(1); } glGetTexBumpParameterivATI(GL_BUMP_ROT_MATRIX_SIZE_ATI, ¶m); printf("BUMP_ROT_MATRIX_SIZE_ATI = %d\n", param); glGetTexBumpParameterivATI(GL_BUMP_NUM_TEX_UNITS_ATI, ¶m); printf("BUMP_NUM_TEX_UNITS_ATI = %d\n", param); glGetTexBumpParameterfvATI(GL_BUMP_ROT_MATRIX_ATI, paramMat); printf("initial rot matrix %f %f %f %f\n", paramMat[0], paramMat[1], paramMat[2], paramMat[3]); glGetTexBumpParameterivATI(GL_BUMP_TEX_UNITS_ATI, paramArray); printf("units supporting bump mapping: "); for (i = 0; i < param; i++) printf("%d ", paramArray[i] - GL_TEXTURE0); printf("\n"); image = LoadRGBImage(TexFile, &imgWidth, &imgHeight, &imgFormat); if (!image) { printf("Couldn't read %s\n", TexFile); exit(0); } glBindTexture( GL_TEXTURE_2D, 1 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexImage2D( GL_TEXTURE_2D, 0, imgFormat, imgWidth, imgHeight, 0, imgFormat, GL_UNSIGNED_BYTE, image ); for (j = 0; j < 16; j++) { for (i = 0; i < 16; i++) { temp[j][i][0] = cos((float)(i) * 3.1415 / 16.0); temp[j][i][1] = -0.5; } } glBindTexture( GL_TEXTURE_2D, 2 ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE ); glTexImage2D( GL_TEXTURE_2D, 0, GL_DU8DV8_ATI, 16, 16, 0, GL_DUDV_ATI, GL_FLOAT, temp ); glNewList( 1, GL_COMPILE ); glBegin(GL_QUADS); glColor3f( 0.9, 0.0, 0.0 ); glMultiTexCoord2f( GL_TEXTURE0, 0.0, 0.0 ); glMultiTexCoord2f( GL_TEXTURE1, 0.0, 0.0 ); glVertex2f(-1, -1); glMultiTexCoord2f( GL_TEXTURE0, 1.0, 0.0 ); glMultiTexCoord2f( GL_TEXTURE1, 1.0, 0.0 ); glVertex2f( 1, -1); glMultiTexCoord2f( GL_TEXTURE0, 1.0, 1.0 ); glMultiTexCoord2f( GL_TEXTURE1, 1.0, 1.0 ); glVertex2f( 1, 1); glMultiTexCoord2f( GL_TEXTURE0, 0.0, 1.0 ); glMultiTexCoord2f( GL_TEXTURE1, 0.0, 1.0 ); glVertex2f(-1, 1); glEnd(); glEndList(); }
HSVImage::HSVImage(cv::Mat &InputImage) { LoadRGBImage(InputImage); }
/* 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); free(texData3); free(texData4); free(image); } }
static void Init( void ) { GLfloat maxBias; if (!glutExtensionSupported("GL_EXT_texture_lod_bias")) { printf("Sorry, GL_EXT_texture_lod_bias not supported by this renderer.\n"); exit(1); } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &TexObj); glBindTexture(GL_TEXTURE_2D, TexObj); if (glutExtensionSupported("GL_SGIS_generate_mipmap")) { /* test auto mipmap generation */ GLint width, height, i; GLenum format; GLubyte *image = LoadRGBImage(TEXTURE_FILE, &width, &height, &format); if (!image) { printf("Error: could not load texture image %s\n", TEXTURE_FILE); exit(1); } /* resize to 256 x 256 */ if (width != 256 || height != 256) { GLubyte *newImage = malloc(256 * 256 * 4); gluScaleImage(format, width, height, GL_UNSIGNED_BYTE, image, 256, 256, GL_UNSIGNED_BYTE, newImage); free(image); image = newImage; } printf("Using GL_SGIS_generate_mipmap\n"); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); glTexImage2D(GL_TEXTURE_2D, 0, format, 256, 256, 0, format, GL_UNSIGNED_BYTE, image); free(image); /* make sure mipmap was really generated correctly */ width = height = 256; for (i = 0; i < 9; i++) { GLint w, h; glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_WIDTH, &w); glGetTexLevelParameteriv(GL_TEXTURE_2D, i, GL_TEXTURE_HEIGHT, &h); printf("Level %d size: %d x %d\n", i, w, h); assert(w == width); assert(h == height); width /= 2; height /= 2; } } else if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { printf("Error: could not load texture image %s\n", TEXTURE_FILE); exit(1); } /* 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); printf("LOD bias range: [%g, %g]\n", -maxBias, maxBias); BiasMin = -100 * maxBias; BiasMax = 100 * maxBias; /* Since we have (about) 8 mipmap levels, no need to bias beyond * the range [-1, +8]. */ if (BiasMin < -100) BiasMin = -100; if (BiasMax > 800) BiasMax = 800; }