-void LoadTextureRGBA(qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight)
-{
- static float fGamma = -1;
- float total[3];
- byte *outpixels = 0;
- int nCount = nWidth * nHeight;
-
- if (fGamma != g_texture_globals.fGamma)
- {
- fGamma = g_texture_globals.fGamma;
- ResampleGamma(fGamma);
- }
-
- q->width = nWidth;
- q->height = nHeight;
-
- total[0] = total[1] = total[2] = 0.0f;
-
- // resample texture gamma according to user settings
- for (int i = 0; i < (nCount * 4); i += 4)
- {
- for (int j = 0; j < 3; j++)
- {
- total[j] += (pPixels + i)[j];
- byte b = (pPixels + i)[j];
- (pPixels + i)[j] = g_gammatable[b];
- }
- }
-
- q->color[0] = total[0] / (nCount * 255);
- q->color[1] = total[1] / (nCount * 255);
- q->color[2] = total[2] / (nCount * 255);
-
- glGenTextures (1, &q->texture_number);
-
- glBindTexture( GL_TEXTURE_2D, q->texture_number );
-
- SetTexParameters(g_texture_mode);
-
- int gl_width = 1;
- while(gl_width < nWidth)
- gl_width <<= 1;
-
- int gl_height = 1;
- while(gl_height < nHeight)
- gl_height <<= 1;
-
- bool resampled = false;
- if (!(gl_width == nWidth && gl_height == nHeight))
- {
- resampled = true;
- outpixels = (byte *)malloc(gl_width * gl_height * 4);
- R_ResampleTexture(pPixels, nWidth, nHeight, outpixels, gl_width, gl_height, 4);
- }
- else
- {
- outpixels = pPixels;
- }
-
- int quality_reduction = max_texture_quality - g_Textures_textureQuality.m_value;
- int target_width = min_int(gl_width >> quality_reduction, max_tex_size);
- int target_height = min_int(gl_height >> quality_reduction, max_tex_size);
-
- while (gl_width > target_width || gl_height > target_height)
- {
- GL_MipReduce(outpixels, outpixels, gl_width, gl_height, target_width, target_height);
-
- if (gl_width > target_width)
- gl_width >>= 1;
- if (gl_height > target_height)
- gl_height >>= 1;
- }
-
- int mip = 0;
- glTexImage2D(GL_TEXTURE_2D, mip++, g_texture_globals.texture_components, gl_width, gl_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, outpixels);
- while (gl_width > 1 || gl_height > 1)
- {
- GL_MipReduce(outpixels, outpixels, gl_width, gl_height, 1, 1);
-
- if (gl_width > 1)
- gl_width >>= 1;
- if (gl_height > 1)
- gl_height >>= 1;
-
- glTexImage2D(GL_TEXTURE_2D, mip++, g_texture_globals.texture_components, gl_width, gl_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, outpixels);
- }
-
- glBindTexture(GL_TEXTURE_2D, 0);
- if (resampled)
- free(outpixels);
+void LoadTextureRGBA( qtexture_t* q, unsigned char* pPixels, int nWidth, int nHeight ){
+ static float fGamma = -1;
+ float total[3];
+ byte *outpixels = 0;
+ int nCount = nWidth * nHeight;
+
+ if ( fGamma != g_texture_globals.fGamma ) {
+ fGamma = g_texture_globals.fGamma;
+ ResampleGamma( fGamma );
+ }
+
+ q->width = nWidth;
+ q->height = nHeight;
+
+ total[0] = total[1] = total[2] = 0.0f;
+
+ // resample texture gamma according to user settings
+ for ( int i = 0; i < ( nCount * 4 ); i += 4 )
+ {
+ for ( int j = 0; j < 3; j++ )
+ {
+ total[j] += ( pPixels + i )[j];
+ byte b = ( pPixels + i )[j];
+ ( pPixels + i )[j] = g_gammatable[b];
+ }
+ }
+
+ q->color[0] = total[0] / ( nCount * 255 );
+ q->color[1] = total[1] / ( nCount * 255 );
+ q->color[2] = total[2] / ( nCount * 255 );
+
+ glGenTextures( 1, &q->texture_number );
+
+ glBindTexture( GL_TEXTURE_2D, q->texture_number );
+
+ SetTexParameters( g_texture_mode );
+
+ int gl_width = 1;
+ while ( gl_width < nWidth )
+ gl_width <<= 1;
+
+ int gl_height = 1;
+ while ( gl_height < nHeight )
+ gl_height <<= 1;
+
+ bool resampled = false;
+ if ( !( gl_width == nWidth && gl_height == nHeight ) ) {
+ resampled = true;
+ outpixels = (byte *)malloc( gl_width * gl_height * 4 );
+ R_ResampleTexture( pPixels, nWidth, nHeight, outpixels, gl_width, gl_height, 4 );
+ }
+ else
+ {
+ outpixels = pPixels;
+ }
+
+ int quality_reduction = max_texture_quality - g_Textures_textureQuality.m_value;
+ int target_width = min_int( gl_width >> quality_reduction, max_tex_size );
+ int target_height = min_int( gl_height >> quality_reduction, max_tex_size );
+
+ while ( gl_width > target_width || gl_height > target_height )
+ {
+ GL_MipReduce( outpixels, outpixels, gl_width, gl_height, target_width, target_height );
+
+ if ( gl_width > target_width ) {
+ gl_width >>= 1;
+ }
+ if ( gl_height > target_height ) {
+ gl_height >>= 1;
+ }
+ }
+
+ int mip = 0;
+ glTexImage2D( GL_TEXTURE_2D, mip++, g_texture_globals.texture_components, gl_width, gl_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, outpixels );
+ while ( gl_width > 1 || gl_height > 1 )
+ {
+ GL_MipReduce( outpixels, outpixels, gl_width, gl_height, 1, 1 );
+
+ if ( gl_width > 1 ) {
+ gl_width >>= 1;
+ }
+ if ( gl_height > 1 ) {
+ gl_height >>= 1;
+ }
+
+ glTexImage2D( GL_TEXTURE_2D, mip++, g_texture_globals.texture_components, gl_width, gl_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, outpixels );
+ }
+
+ glBindTexture( GL_TEXTURE_2D, 0 );
+ if ( resampled ) {
+ free( outpixels );
+ }