Beispiel #1
0
	uint RendererGL::createTexture(const String& name, void* data, uint width, uint height, uint format, uint type, bool mipmap)
	{
		// Create an OpenGL texture object.
		//

		GLuint theTexture;
		glGenTextures( 1, &theTexture );

		// Configure the texture object.
		//
		glBindTexture( GL_TEXTURE_2D, theTexture );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
		GLenum ddd = glGetError();

		// Load the texture object from DevIL.
		//
		glPixelStoref(GL_UNPACK_ALIGNMENT,1);

		format = GLTypes::Map(format);
		type = GLTypes::Map(type);

		glTexImage2D( 
			GL_TEXTURE_2D, 0, 
			GL_RGBA, 
			width, height, 0, 
			format, type, data );

		if(mipmap)
			glGenerateMipmap(GL_TEXTURE_2D);

		m_texVec.push_back(theTexture);
		return m_texVec.size()-1;
	}
Beispiel #2
0
GLuint ATLLoadTexture(const char *fileName)
{
	BITMAP bm;
	GLuint idTexture = 0;
	CImage img;				//需要头文件atlimage.h
	HRESULT hr = img.Load(fileName);
	if (!SUCCEEDED(hr))	//文件加载失败
	{
		MessageBox(NULL, "文件加载失败", "ERROR", 0);
		return NULL;
	}
	HBITMAP hbmp = img;
	if (!GetObject(hbmp, sizeof(bm), &bm))
		return 0;

	glGenTextures(1, &idTexture);
	if (idTexture)
	{
		glBindTexture(GL_TEXTURE_2D, idTexture);
		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);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		glPixelStoref(GL_PACK_ALIGNMENT, 1);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, bm.bmWidth, bm.bmHeight, 0, GL_BGR, GL_UNSIGNED_BYTE, bm.bmBits);	//这里不是GL_RGB
	}
	return idTexture;
}
Beispiel #3
0
////////////////////////////////////////////////////////
// setUpTextureState
//
/////////////////////////////////////////////////////////
void pix_texture :: setUpTextureState() {
  m_doRepeat=m_repeat;
  if (m_rectangle && m_canRectangle){
    if ( m_textureType ==  GL_TEXTURE_RECTANGLE_ARB || m_textureType == GL_TEXTURE_RECTANGLE_EXT)
      {
        glTexParameterf(m_textureType, GL_TEXTURE_PRIORITY, 0.0f);
        // JMZ: disabled the following, as rectangle-textures are clamped anyhow
        // JMZ: and normalized ones, lose their setting
        // TIGITAL: this is necessary on osx, at least with non-powerof2 textures!
        //			otherwise, weird texturing occurs (looks similar to pix_refraction)
        // NPOT: GL_CLAMP, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_BORDER
        // POT:  above plus GL_REPEAT, GL_MIRRORED_REPEAT
        m_doRepeat = GL_CLAMP_TO_EDGE;
        debug("using rectangle texture");
      }
  }

  if (GLEW_APPLE_client_storage){
    if(m_clientStorage){
      glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
      debug("using client storage");
    } else {
      glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_FALSE);
      debug("not using client storage");
    }
  } else
    glPixelStoref(GL_UNPACK_ALIGNMENT, 1);

  setTexFilters(m_textureMinQuality != GL_LINEAR_MIPMAP_LINEAR || (m_wantMipmap && m_canMipmap));
  glTexParameterf(m_textureType, GL_TEXTURE_WRAP_S, m_doRepeat);
  glTexParameterf(m_textureType, GL_TEXTURE_WRAP_T, m_doRepeat);
}
Beispiel #4
0
////////////////////////////////////////////////////////
// setUpTextureState
//
/////////////////////////////////////////////////////////
void pix_cubemap :: setUpTextureState() {
  glPixelStoref(GL_UNPACK_ALIGNMENT, 1);

  glTexParameterf(m_textureType, GL_TEXTURE_MIN_FILTER, m_textureQuality);
  glTexParameterf(m_textureType, GL_TEXTURE_MAG_FILTER, m_textureQuality);
  glTexParameterf(m_textureType, GL_TEXTURE_WRAP_S, m_repeat);
  glTexParameterf(m_textureType, GL_TEXTURE_WRAP_T, m_repeat);

  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, m_env);
}
// Updates the texture by copying the block corresponding to the current timestep to GPU memory
void OpenGLRenderer::UpdateTexture(int currentTimestep, VolumeDataset &volume)
{
	glBindTexture(GL_TEXTURE_3D, currTexture3D);

	if (!volume.littleEndian)
		glPixelStoref(GL_UNPACK_SWAP_BYTES, true);

	if (volume.elementType == "MET_UCHAR")
		glTexImage3D(GL_TEXTURE_3D, 0, GL_R8, volume.xRes, volume.yRes, volume.zRes, 0,  GL_RED, GL_UNSIGNED_BYTE, volume.memblock3D + (textureSize * currentTimestep));

	else if (volume.elementType == "SHORT")
		glTexImage3D(GL_TEXTURE_3D, 0, GL_R16F, volume.xRes, volume.yRes, volume.zRes, 0, GL_RED, GL_UNSIGNED_SHORT, volume.memblock3D + (textureSize * currentTimestep));

	else if (volume.elementType == "FLOAT")
		glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, volume.xRes, volume.yRes, volume.zRes, 0, GL_RED, GL_FLOAT, volume.memblock3D + (textureSize * currentTimestep));

	glPixelStoref(GL_UNPACK_SWAP_BYTES, false);

	glBindTexture(GL_TEXTURE_3D, 0);
}
// Generates the original 3D texture
GLuint OpenGLRenderer::GenerateTexture(VolumeDataset &volume)
{
	GLuint tex;
	textureSize = volume.xRes * volume.yRes * volume.zRes * volume.bytesPerElement;

	glEnable(GL_TEXTURE_3D);
	glGenTextures(1, &tex);
	glBindTexture(GL_TEXTURE_3D, tex);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);


	// Reverses endianness in copy
	if (!volume.littleEndian)
		glPixelStoref(GL_UNPACK_SWAP_BYTES, true);

	if (volume.elementType == "MET_UCHAR")
		glTexImage3D(GL_TEXTURE_3D, 0, GL_R8, volume.xRes, volume.yRes, volume.zRes, 0,  GL_RED, GL_UNSIGNED_BYTE, volume.memblock3D);

	else if (volume.elementType == "SHORT")
		glTexImage3D(GL_TEXTURE_3D, 0, GL_R16F, volume.xRes, volume.yRes, volume.zRes, 0, GL_RED, GL_UNSIGNED_SHORT, volume.memblock3D);

	else if (volume.elementType == "FLOAT")
		glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, volume.xRes, volume.yRes, volume.zRes, 0, GL_RED, GL_FLOAT, volume.memblock3D);

	glPixelStoref(GL_UNPACK_SWAP_BYTES, false);
	
	glBindTexture(GL_TEXTURE_3D, 0);

	return tex;
}
Beispiel #7
0
static bool
test(float val, int expect)
{
	GLint out;

	glPixelStoref(GL_UNPACK_ROW_LENGTH, val);
	glGetIntegerv(GL_UNPACK_ROW_LENGTH, &out);

	if (out != expect) {
		printf("Set row length to %.1f, expected %d, got %d\n",
		       val, expect, out);
		return false;
	} else {
		printf("Set row length to %.1f and got %d\n", val, out);
	}

	return true;
}
Beispiel #8
0
int __glXDisp_PixelStoref(__GLXclientState *cl, GLbyte *pc)
{
	__GLXcontext *cx;
	int error;

	cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
	if (!cx) {
		return error;
	}
	pc += __GLX_SINGLE_HDR_SIZE;

	glPixelStoref( 
		*(GLenum   *)(pc + 0),
		*(GLfloat  *)(pc + 4)
	);
	__GLX_NOTE_UNFLUSHED_CMDS(cx);
	return Success;
}
Beispiel #9
0
void drawImage() {
	int i = 0;
	int j = 0;

	glPixelStoref(GL_UNPACK_ALIGNMENT, 1);
	glClear(GL_COLOR_BUFFER_BIT);
	glColor3f(1.0, 1.0, 1.0);
	glPixelZoom(1.0, -1.0);
	glBitmap(0, 0, 0, 0, info->width*0.5, info->height+lines*15+19, NULL);
	if (info->bpp/8 == 3) {
		glDrawPixels(info->width, info->height, GL_RGB, GL_UNSIGNED_BYTE, image);
	} else {
		glDrawPixels(info->width, info->height, GL_LUMINANCE, GL_UNSIGNED_BYTE, image);
	}
	glBitmap(0, 0, 0, 0, -info->width*0.5, -info->height-lines*15-19, NULL);

	glBegin(GL_LINES); //Border left
	 glVertex2f(info->width*0.5, lines*15+19);
	 glVertex2f(info->width*0.5, info->height+lines*15+19);
	glEnd();
	glBegin(GL_LINES); //Border bottom
	 glVertex2f(info->width*0.5-1, lines*15+19);
	 glVertex2f(info->width*1.5+1, lines*15+19);
	glEnd();
	glBegin(GL_LINES); //Border right
	 glVertex2f(info->width*1.5+1, lines*15+19);
	 glVertex2f(info->width*1.5+1, info->height+lines*15+19);
	glEnd();
	glBegin(GL_LINES); //Border top
	 glVertex2f(info->width*0.5-1, info->height+lines*15+19);
	 glVertex2f(info->width*1.5+1, info->height+lines*15+19);
	glEnd();

	do {
		glRasterPos2f(info->width*0.1, (lines-1-i)*15+10);
		for (j = 0; j < 27 && (i*27+j < (int)strlen(text)); j++) {
			glutBitmapCharacter(GLUT_BITMAP_9_BY_15, text[i*27+j]);
		}
		i++;
	} while (i <= ((int)strlen(text))/27);
	glRasterPos2f(0,0);

	glFlush();
}
Beispiel #10
0
void
piglit_init(int argc, char **argv)
{
	int ret;
	bool pass = true;
	ret = fesetround(FE_UPWARD);
	if (ret != 0) {
		printf("Couldn't set rounding mode\n");
		piglit_report_result(PIGLIT_SKIP);
	}

	pass = test(2.2, 2) && pass;
	pass = test(2.8, 3) && pass;
	pass = test(-0.1, 0) && pass;
	pass = piglit_check_gl_error(GL_NO_ERROR) && pass;

	printf("Setting row length -0.9, and expecting error\n");
	glPixelStoref(GL_UNPACK_ROW_LENGTH, -0.9);
	pass = piglit_check_gl_error(GL_INVALID_VALUE) && pass;

	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
}
Beispiel #11
0
void Texture::setPixelStorageMode( GLenum pname, GLfloat param )
{
    KVS_ASSERT( this->isBound() );
    KVS_GL_CALL( glPixelStoref( pname, param ) );
}
Beispiel #12
0
GLuint Texture::loadBitmap(const char * imagepath){
	// Data read from the header of the BMP file
	unsigned char header[54];		// Each BMP file begins by a 54-bytes header
	unsigned int dataPos;			// Position in the file where the actual data begins
	unsigned int width, height;	//Pretty self explanatory
	unsigned int imageSize;			// = width*height*3
	unsigned char * data;			// Actual RGB data
	unsigned int textureID;
	FILE * file = fopen(imagepath,"rb"); //Open file
	if (!file){ 
		std::cerr << "ERROR OPENING BITMAP" << std::endl;
		return -1;
	}
	
	if (fread(header, 1, 54, file)!=54 ){ // If not 54 bytes read : problem
		std::cerr << "ERROR READING BITMAP HEADER" << std::endl;
		return -1;
	}
	
	if (header[0]!='B' || header[1]!='M'){
		std::cerr << "ERROR READING BITMAP HEADER" << std::endl;
		return -1;
	}
	
	// Read ints from the byte array
	dataPos    = *(int*)&(header[0x0A]);  //Header points to a certain point on the string. Since it calls for the pointed by its memory address,it is the actual pointer.
	imageSize  = *(int*)&(header[0x22]);
	width      = *(int*)&(header[0x12]);
	height     = *(int*)&(header[0x16]);
	
	

	// Some BMP files are misformatted, guess missing information
	if (imageSize==0)    imageSize=width*height*3; // 3 : one byte for each Red, Green and Blue component
	if (dataPos==0)      dataPos=54; // The BMP header is done that way
		
	//std::cout << imageSize << "w:" << width << "h:" << height <<std::endl;
	// Create a buffer
	data = new unsigned char [imageSize];
	
	// Read the actual data from the file into the buffer
	fread(data,1,imageSize,file);
	
	//Everything is in memory now, the file can be closed
	fclose(file);
	
	glPixelStoref( GL_UNPACK_ALIGNMENT, 1);

	// Create one OpenGL textur
	
	glGenTextures(1, &textureID);
	
	// "Bind" the newly created texture : all future texture functions will modify this texture
	glBindTexture(GL_TEXTURE_2D, textureID);
	
	// Give the image to OpenGL
	glTexImage2D(GL_TEXTURE_2D, 0,GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, data);
	
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	_textures[imagepath] = textureID;
	
	if(gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height, GL_BGR, GL_UNSIGNED_BYTE, data ) != 0){
		std::cerr << "ERROR BUILDING MIPMAP" << std::endl;
		return -1;
	}

	
	return textureID;
	
	
}
		void PixelStoref(const EPixelStorage::Value PName, const GLfloat Param)
		{
			glPixelStoref(PName, Param);
		}
Beispiel #14
0
M(void, glPixelStoref, jint pname, jfloat param) {
	glPixelStoref(pname, param);
}
Beispiel #15
0
bool glWindow::ResetGL () {

    if (m_resetGLMode == RGM_RECREATEWINDOW) {
        RecreateWindow (m_fullScreen, m_border, m_width, m_height, m_bpp, m_stencil, m_title, m_allowResizing, m_fitToWorkArea);
        return true;
    }
    else if (m_resetGLMode == RGM_RECREATECONTEXT) {
        RecreateGLContext ();
        return true;
    }

    // Setup OpenGL defaults.
    // This should reset as much as possible back to the initial state of OpenGL.

    // Exceptions:
    //      * Projection matrix is initialised to a perspective transform

    // End current gl block
    try { glEnd ();                                                             } catch (...) { ; }    
    m_dontPaint = false;

    // Intialise matrices
    try { glMatrixMode (GL_PROJECTION);   ClearGLMatrix ();                     } catch (...) { ; }
    try { glMatrixMode (GL_TEXTURE);      ClearGLMatrix ();                     } catch (...) { ; }
    try { glMatrixMode (GL_MODELVIEW);    ClearGLMatrix ();                     } catch (...) { ; }

    // Initialise state
    int i;
    try { glColor4f (1, 1, 1, 1);                                               } catch (...) { ; }
    try { glIndexi (1);                                                         } catch (...) { ; }
    try { glTexCoord4f (0, 0, 0, 1);                                            } catch (...) { ; }
    try { glNormal3f (0, 0, 1);                                                 } catch (...) { ; }
//    try { glRasterPos4f (0, 0, 0, 1);                                           } catch (...) { ; }
    try { glEdgeFlag (GL_TRUE);                                                 } catch (...) { ; }
    try { glDisable (GL_VERTEX_ARRAY);                                          } catch (...) { ; }
    try { glDisable (GL_NORMAL_ARRAY);                                          } catch (...) { ; }
    try { glDisable (GL_COLOR_ARRAY);                                           } catch (...) { ; }
    try { glDisable (GL_INDEX_ARRAY);                                           } catch (...) { ; }
    try { glDisable (GL_TEXTURE_COORD_ARRAY);                                   } catch (...) { ; }
    try { glDisable (GL_EDGE_FLAG_ARRAY);                                       } catch (...) { ; }
    try { glDepthRange (0, 1);                                                  } catch (...) { ; }
    try { glDisable (GL_NORMALIZE);                                             } catch (...) { ; }
    for (i = 0; i < GL_MAX_CLIP_PLANES; i++)
        try { glDisable (GL_CLIP_PLANE0 + i);                                   } catch (...) { ; }
    GLfloat fog[] = {0, 0, 0, 0};
    try { glFogfv (GL_FOG_COLOR, fog);                                          } catch (...) { ; }
    try { glFogi (GL_FOG_INDEX, 0);                                             } catch (...) { ; }
    try { glFogf (GL_FOG_DENSITY, 1.0);                                         } catch (...) { ; }
    try { glFogf (GL_FOG_START, 0.0);                                           } catch (...) { ; }
    try { glFogf (GL_FOG_END, 1.0);                                             } catch (...) { ; }
    try { glFogi (GL_FOG_MODE, GL_EXP);                                         } catch (...) { ; }
    try { glDisable (GL_FOG);                                                   } catch (...) { ; }
    try { glShadeModel (GL_SMOOTH);                                             } catch (...) { ; }
    try { glDisable (GL_LIGHTING);                                              } catch (...) { ; }
    try { glDisable (GL_COLOR_MATERIAL);                                        } catch (...) { ; }
    try { glColorMaterial (GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);          } catch (...) { ; }

    GLfloat ambient[]   = { 0.2, 0.2, 0.2, 1.0 },
            diffuse[]   = { 0.8, 0.8, 0.8, 1.0 },
            specular[]  = { 0.0, 0.0, 0.0, 1.0 },
            emission[]  = { 0.0, 0.0, 0.0, 1.0 },
            shininess[] = { 0.0 };
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT,    ambient);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,    diffuse);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,  specular);             } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_EMISSION,   emission);            } catch (...) { ; }
    try { glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS,  shininess);           } catch (...) { ; }
    try { glLightModelfv (GL_LIGHT_MODEL_AMBIENT, ambient);                     } catch (...) { ; }
    try { glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);                } catch (...) { ; }
    try { glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);                    } catch (...) { ; }
    GLfloat lambient[]      = { 0.0, 0.0, 0.0, 1.0 },
            ldiffuse0[]     = { 1.0, 1.0, 1.0, 1.0 },
            ldiffuse1[]     = { 0.0, 0.0, 0.0, 1.0 },
            lspecular0[]    = { 1.0, 1.0, 1.0, 1.0 },
            lspecular1[]    = { 0.0, 0.0, 0.0, 1.0 },
            lposition[]     = { 0.0, 0.0, 1.0, 0.0 };
    for (i = 0; i < 8; i++) {
        try { glLightfv (GL_LIGHT0 + i, GL_AMBIENT, lambient);                              } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_DIFFUSE, i == 0 ? ldiffuse0 : ldiffuse1);        } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_SPECULAR, i == 0 ? lspecular0 : lspecular1);     } catch (...) { ; }
        try { glLightfv (GL_LIGHT0 + i, GL_POSITION, lposition);                            } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_SPOT_EXPONENT, 0.0);                              } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_CONSTANT_ATTENUATION, 1.0);                       } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_LINEAR_ATTENUATION, 0.0);                         } catch (...) { ; }
        try { glLightf (GL_LIGHT0 + i, GL_QUADRATIC_ATTENUATION, 0.0);                      } catch (...) { ; }
        try { glDisable (GL_LIGHT0 + i);                                                    } catch (...) { ; }
    }

    try { glPointSize (1.0);                                                    } catch (...) { ; }
    try { glDisable (GL_POINT_SMOOTH);                                          } catch (...) { ; }
    try { glLineWidth (1.0);                                                    } catch (...) { ; }
    try { glDisable (GL_LINE_SMOOTH);                                           } catch (...) { ; }
    try { glLineStipple (1, 0xffff);                                            } catch (...) { ; }
    try { glDisable (GL_LINE_STIPPLE);                                          } catch (...) { ; }
    try { glDisable (GL_CULL_FACE);                                             } catch (...) { ; }
    try { glCullFace (GL_BACK);                                                 } catch (...) { ; }
    try { glFrontFace (GL_CCW);                                                 } catch (...) { ; }
    try { glDisable (GL_POLYGON_SMOOTH);                                        } catch (...) { ; }
    try { glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);                           } catch (...) { ; }
    try { glDisable (GL_TEXTURE_1D);                                            } catch (...) { ; }
    try { glDisable (GL_TEXTURE_2D);                                            } catch (...) { ; }

    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);                } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);                    } catch (...) { ; }
    try { glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);                    } catch (...) { ; }
    GLfloat texBorder[] = {0, 0, 0, 0};
    try { glTexParameterfv (GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, texBorder);             } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_T);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_S);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_R);                                                     } catch (...) { ; }
    try { glDisable (GL_TEXTURE_GEN_Q);                                                     } catch (...) { ; }
    for (i = 0; i < 4; i++) {
        GLenum coord;
        switch (i) {
        case 0: coord = GL_T; break;
        case 1: coord = GL_S; break;
        case 2: coord = GL_R; break;
        case 3: coord = GL_Q; break;
        }
        try { glTexGeni (coord, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);            } catch (...) { ; }
    }

    try { glDisable (GL_SCISSOR_TEST);                                          } catch (...) { ; }
    try { glDisable (GL_ALPHA_TEST);                                            } catch (...) { ; }
    try { glAlphaFunc (GL_ALWAYS, 0);                                           } catch (...) { ; }
    try { glDisable (GL_STENCIL_TEST);                                          } catch (...) { ; }
    try { glStencilFunc (GL_ALWAYS, 0, 0xffffffff);                             } catch (...) { ; }
    try { glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);                              } catch (...) { ; }
    try { glDisable (GL_DEPTH_TEST);                                            } catch (...) { ; }
    try { glDepthFunc (GL_LESS);                                                } catch (...) { ; }
    try { glDisable (GL_BLEND);                                                 } catch (...) { ; }
    try { glBlendFunc (GL_ONE, GL_ZERO);                                        } catch (...) { ; }
    try { glDrawBuffer (GL_BACK);                                               } catch (...) { ; }
    try { glColorMask (GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);                     } catch (...) { ; }
    try { glDepthMask (GL_TRUE);                                                } catch (...) { ; }
    try { glClearAccum (0, 0, 0, 0);                                            } catch (...) { ; }
    try { glClearColor (0, 0, 0, 0);                                            } catch (...) { ; }
    try { glClearDepth (1);                                                     } catch (...) { ; }
    try { glClearIndex (0);                                                     } catch (...) { ; }
    try { glClearStencil (0);                                                   } catch (...) { ; }

    try { glPixelStorei (GL_PACK_SWAP_BYTES, GL_FALSE);                         } catch (...) { ; }
    try { glPixelStorei (GL_PACK_LSB_FIRST, GL_FALSE);                          } catch (...) { ; }
    try { glPixelStoref (GL_PACK_ROW_LENGTH, 0);                                } catch (...) { ; }
    try { glPixelStoref (GL_PACK_SKIP_PIXELS, 0);                               } catch (...) { ; }
    try { glPixelStorei (GL_PACK_ALIGNMENT, 4);                                 } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);                       } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);                        } catch (...) { ; }
    try { glPixelStoref (GL_UNPACK_ROW_LENGTH, 0);                              } catch (...) { ; }
    try { glPixelStoref (GL_UNPACK_SKIP_PIXELS, 0);                             } catch (...) { ; }
    try { glPixelStorei (GL_UNPACK_ALIGNMENT, 4);                               } catch (...) { ; }
    try { glPixelTransferi (GL_MAP_COLOR, GL_FALSE);                            } catch (...) { ; }
    try { glPixelTransferi (GL_MAP_STENCIL, GL_FALSE);                          } catch (...) { ; }
    try { glPixelTransferi (GL_INDEX_SHIFT, 0);                                 } catch (...) { ; }
    try { glPixelTransferi (GL_INDEX_OFFSET, 0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_RED_SCALE, 1.0);                                 } catch (...) { ; }
    try { glPixelTransferf (GL_GREEN_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_BLUE_SCALE, 1.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_ALPHA_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_DEPTH_SCALE, 1.0);                               } catch (...) { ; }
    try { glPixelTransferf (GL_RED_BIAS, 0.0);                                  } catch (...) { ; }
    try { glPixelTransferf (GL_GREEN_BIAS, 0.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_BLUE_BIAS, 0.0);                                 } catch (...) { ; }
    try { glPixelTransferf (GL_ALPHA_BIAS, 0.0);                                } catch (...) { ; }
    try { glPixelTransferf (GL_DEPTH_BIAS, 0.0);                                } catch (...) { ; }

    try { glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE);                } catch (...) { ; }
    try { glHint (GL_POINT_SMOOTH_HINT, GL_DONT_CARE);                          } catch (...) { ; }
    try { glHint (GL_LINE_SMOOTH_HINT, GL_DONT_CARE);                           } catch (...) { ; }
    try { glHint (GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE);                        } catch (...) { ; }
    try { glHint (GL_FOG_HINT, GL_DONT_CARE);                                   } catch (...) { ; }

    // Multitexturing
    if (ExtensionSupported ("GL_ARB_multitexture")) {

        // Disable texturing for all texture units
        int units;
        try { glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &units);                 } catch (...) { ; }
        for (int i = 0; i < units; i++) {
            if (glActiveTexture != NULL)
                glActiveTexture (GL_TEXTURE0_ARB + i);
            try { glDisable (GL_TEXTURE_2D);                                    } catch (...) { ; }
            try { glDisable (GL_TEXTURE_1D);                                    } catch (...) { ; }
            if (i == 0) try { glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } catch (...) { ; }
            else        try { glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);    } catch (...) { ; }
        }

        if (glActiveTexture != NULL)
            try { glActiveTexture (GL_TEXTURE0_ARB);                            } catch (...) { ; }
    }

    // Setup OpenGL defaults
    OpenGLDefaults ();

	return TRUE;									// Initialization Went OK
}