Exemplo n.º 1
0
EXPORT void HWRAPI( OglSdlSetPalette) (RGBA_t *palette, RGBA_t *pgamma)
{
	INT32 i = -1;
	UINT32 redgamma = pgamma->s.red, greengamma = pgamma->s.green,
		bluegamma = pgamma->s.blue;

#if 0 // changing the gamma to 127 is a bad idea
	i = SDL_SetGamma(byteasfloat(redgamma), byteasfloat(greengamma), byteasfloat(bluegamma));
#endif
	if (i == 0) redgamma = greengamma = bluegamma = 0x7F; //Alam: cool
	for (i = 0; i < 256; i++)
	{
		myPaletteData[i].s.red   = (UINT8)MIN((palette[i].s.red   * redgamma)  /127, 255);
		myPaletteData[i].s.green = (UINT8)MIN((palette[i].s.green * greengamma)/127, 255);
		myPaletteData[i].s.blue  = (UINT8)MIN((palette[i].s.blue  * bluegamma) /127, 255);
		myPaletteData[i].s.alpha = palette[i].s.alpha;
	}
#ifdef USE_PALETTED_TEXTURE
	if (glColorTableEXT)
	{
		for (i = 0; i < 256; i++)
		{
			palette_tex[(3*i)+0] = palette[i].s.red;
			palette_tex[(3*i)+1] = palette[i].s.green;
			palette_tex[(3*i)+2] = palette[i].s.blue;
		}
		glColorTableEXT(GL_TEXTURE_2D, GL_RGB8, 256, GL_RGB, GL_UNSIGNED_BYTE, palette_tex);
	}
#endif
	// on a chang�de palette, il faut recharger toutes les textures
	// jaja, und noch viel mehr ;-)
	Flush();
}
Exemplo n.º 2
0
void genTextureFromImg(int n, int offs)
{
    u8* tx = (u8*) texsBitmap;
    tx += offs*64*64;

    u8 texdata[64*64];

    for(int x = 0; x < 64; x++)
        for(int y = 0; y < 64; y++)
        {
            int c = texsPal[tx[x+y*64]];
            int a = c & 0x1F;

            texdata[x+y*64] = (u8) (a)<< 3 | 1;
        }

    glBindTexture(n, textureIDS[n]);
    glTexImage2D(0, 0, GL_RGB8_A5, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD | GL_TEXTURE_WRAP_T | GL_TEXTURE_WRAP_S, &texdata);

    u16 paldata[8];
    for(int i = 0; i <8; i++)
        paldata[i] = 0xFFFF;
    glColorTableEXT( 0, 0, 8, 0, 0, paldata );


}
Exemplo n.º 3
0
void PaletteRenderer::uploadTexture3D(VolumeRenderer::DataItem* dataItem) const
	{
	/* Get pointer to our own data item: */
	DataItem* myDataItem=static_cast<DataItem*>(dataItem);
	
	if(myDataItem->setParameters)
		{
		/* Set the OpenGL texturing parameters: */
		glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_BASE_LEVEL,0);
		glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAX_LEVEL,0);
		glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_S,GL_CLAMP);
		glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_T,GL_CLAMP);
		glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_WRAP_R,GL_CLAMP);
		glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MAG_FILTER,interpolationMode);
		glTexParameteri(GL_TEXTURE_3D,GL_TEXTURE_MIN_FILTER,interpolationMode);
		}
	
	/* Upload a color map only if necessary: */
	if(myDataItem->renderingPath==PalettedTexture&&myDataItem->uploadColorMap)
		{
		/* Set the texture's color map: */
		#ifdef __SGI_IRIX__
		glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors());
		#else
		glColorTableEXT(GL_TEXTURE_3D,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors());
		#endif
		}
	
	if(myDataItem->uploadData)
		{
		/* Determine the texture's format: */
		GLenum internalFormat=GL_INTENSITY8;
		GLenum uploadFormat=GL_LUMINANCE;
		
		#ifndef __SGI_IRIX__
		if(myDataItem->renderingPath==PalettedTexture)
			{
			internalFormat=GL_COLOR_INDEX8_EXT;
			uploadFormat=GL_COLOR_INDEX;
			}
		#endif
		
		/* Upload the texture block: */
		glPixelStorei(GL_UNPACK_ALIGNMENT,1);
		glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
		glPixelStorei(GL_UNPACK_ROW_LENGTH,0); // increments[1]); // Seems to be a bug in OpenGL - consistent across SGI/nVidia platforms
		glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
		glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,0); // increments[0]);
		glPixelStorei(GL_UNPACK_SKIP_IMAGES,0);
		#ifdef __SGI_IRIX__
		glTexImage3D(GL_TEXTURE_3D,0,internalFormat,textureSize[2],textureSize[1],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,values);
		#else
		glTexImage3DEXT(GL_TEXTURE_3D,0,internalFormat,textureSize[2],textureSize[1],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,0);
		glTexSubImage3DEXT(GL_TEXTURE_3D,0,0,0,0,size[2],size[1],size[0],uploadFormat,GL_UNSIGNED_BYTE,values);
		#endif
		}
	}
Exemplo n.º 4
0
void PaletteRenderer::prepareRenderAxisAligned(VolumeRenderer::DataItem* dataItem) const
	{
	DataItem* myDataItem=static_cast<DataItem*>(dataItem);
	
	/* Manage color palette uploads: */
	if(myDataItem->renderingPath==FragmentProgram)
		{
		/* Bind the color map texture to texture unit 1: */
		glActiveTextureARB(GL_TEXTURE1_ARB);
		glBindTexture(GL_TEXTURE_2D,myDataItem->paletteTextureObjectId);
		if(myDataItem->cachedColorMapVersion!=colorMapVersion)
			{
			/* Upload the color map as a 2D texture: */
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,256,1,0,GL_RGBA,GL_FLOAT,colorMap->getColors());
			
			/* Mark the cached color map as up-to-date: */
			myDataItem->cachedColorMapVersion=colorMapVersion;
			}
		glActiveTextureARB(GL_TEXTURE0_ARB);
		}
	else if(myDataItem->renderingPath==TextureShader)
		{
		/* Bind the color map texture to texture unit 1: */
		glActiveTextureARB(GL_TEXTURE1_ARB);
		glBindTexture(GL_TEXTURE_2D,myDataItem->paletteTextureObjectId);
		if(myDataItem->cachedColorMapVersion!=colorMapVersion)
			{
			/* Upload the color map as a 2D texture: */
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA8,256,1,0,GL_RGBA,GL_FLOAT,colorMap->getColors());
			
			/* Mark the cached color map as up-to-date: */
			myDataItem->cachedColorMapVersion=colorMapVersion;
			}
		glTexEnvi(GL_TEXTURE_SHADER_NV,GL_SHADER_OPERATION_NV,GL_DEPENDENT_AR_TEXTURE_2D_NV);
		glTexEnvi(GL_TEXTURE_SHADER_NV,GL_PREVIOUS_TEXTURE_INPUT_NV,GL_TEXTURE0_ARB);
		glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,textureFunction);
		glActiveTextureARB(GL_TEXTURE0_ARB);
		}
	else if(!textureCachingEnabled)
		{
		/* Sufficient to upload palette right here: */
		#ifdef __SGI_IRIX__
		glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors());
		#else
		glColorTableEXT(GL_TEXTURE_2D,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors());
		#endif
		}
	}
Exemplo n.º 5
0
void PaletteRenderer::setGlobalColorMap(const GLColorMap* newGlobalColorMap)
	{
	if(newGlobalColorMap->getNumEntries()==256)
		{
		/* Sufficient to upload palette right here: */
		#ifdef __SGI_IRIX__
		glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,newGlobalColorMap->getColors());
		#else
		glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT,GL_RGBA,256,GL_RGBA,GL_FLOAT,newGlobalColorMap->getColors());
		#endif
		}
	}
Exemplo n.º 6
0
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);
}
Exemplo n.º 7
0
// removed old 3dfx code
void VID_Init8bitPalette()
{
    // Check for 8bit Extensions and initialize them.
    int i;
    char thePalette[256*3];
    char *oldPalette, *newPalette;

    if (strstr(gl_extensions, "GL_EXT_shared_texture_palette") == NULL)
        return;

    Com_Printf ("8-bit GL extensions enabled.\n");
    glEnable( GL_SHARED_TEXTURE_PALETTE_EXT );
    oldPalette = (char *) d_8to24table; //d_8to24table3dfx;
    newPalette = thePalette;
    for (i=0;i<256;i++)
    {
        *newPalette++ = *oldPalette++;
        *newPalette++ = *oldPalette++;
        *newPalette++ = *oldPalette++;
        oldPalette++;
    }
    glColorTableEXT(GL_SHARED_TEXTURE_PALETTE_EXT, GL_RGB, 256, GL_RGB, GL_UNSIGNED_BYTE, (void *) thePalette);
    is8bit = true;
}
Exemplo n.º 8
0
void genTextures()
{


//	int pal_addr = gluTexLoadPal( &paldata[0], 8, GL_RGB8_A5 );

    u16 paldata[8];
    for(int i = 0; i <8; i++)
        paldata[i] = 0xFFFF;

    u8 texdata[64*64];



    for(int x = 0; x < 64; x++)
        for(int y = 0; y < 64; y++)
        {
            texdata[x+y*64] = (u8)  1;
        }

    glBindTexture(0, textureIDS[0]);
    glTexImage2D(0, 0, GL_RGB256, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, &texdata);
    glColorTableEXT( 0, 0, 8, 0, 0, paldata );


    genTextureFromImg(1, 0);
    genTextureFromImg(2, 1);
    genTextureFromImg(3, 2);


    u8* texdata2 = new u8[256*64];
    u8* text = (u8*) introtextBitmap;
    for(int x = 0; x < 256; x++)
        for(int y = 0; y < 64; y++)
        {
            u8 val = 0;
            if(text[x+y*256] == 0x01)
                val = 31<<3;
            texdata2[x+y*256] = val;
        }


    glBindTexture(4, textureIDS[4]);
    glTexImage2D(0, 0, GL_RGB8_A5, TEXTURE_SIZE_256, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, texdata2);
    glColorTableEXT( 0, 0, 8, 0, 0, paldata );

    genTextureFromImg(6, 3);
    genTextureFromImg(8, 4);


    for(int x = 0; x < 64; x++)
        for(int y = 0; y < 64; y++)
            texdata[x+y*64] = (u8) (31)<< 3 | 1;

    glBindTexture(7, textureIDS[7]);
    glTexImage2D(0, 0, GL_RGB8_A5, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, &texdata);
    glColorTableEXT( 0, 0, 8, 0, 0, paldata );

    for(int x = 0; x < 64; x++)
        for(int y = 0; y < 64; y++)
        {
            int dist = (x-32)*(x-32)+(y-32)*(y-32);
            dist = sqrt32(dist);
//			dist /= 32;
            if(dist>31) dist = 31;
            if(dist<0) dist = 0;
            if(dist !=31)
                texdata[x+y*64] = (u8) 31<< 3 | 1;
            else
                texdata[x+y*64] = (u8) 0;

        }

    glBindTexture(9, textureIDS[9]);
    glTexImage2D(0, 0, GL_RGB8_A5, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, &texdata);
    glColorTableEXT( 0, 0, 9, 0, 0, paldata );

    genTextureFromImg(10, 5);
    genTextureFromImg(11, 6);
    genTextureFromImg(12, 7);
    genTextureFromImg(13, 8);

    delete[] texdata2;
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTPalettedTexture_nglColorTableEXT(JNIEnv *env, jclass clazz, jint target, jint internalFormat, jint width, jint format, jint type, jlong data, jlong function_pointer) {
	const GLvoid *data_address = (const GLvoid *)(intptr_t)data;
	glColorTableEXTPROC glColorTableEXT = (glColorTableEXTPROC)((intptr_t)function_pointer);
	glColorTableEXT(target, internalFormat, width, format, type, data_address);
}
Exemplo n.º 10
0
void PaletteRenderer::uploadTexture2D(VolumeRenderer::DataItem* dataItem,int axis,int index) const
	{
	/* Get pointer to our own data item: */
	DataItem* myDataItem=static_cast<DataItem*>(dataItem);
	
	if(myDataItem->setParameters)
		{
		/* Set the OpenGL texturing parameters: */
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,interpolationMode);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,interpolationMode);
		}
	
	/* Upload a color map only if necessary: */
	if(myDataItem->renderingPath==PalettedTexture&&myDataItem->uploadColorMap)
		{
		/* Set the texture's color map: */
		#ifdef __SGI_IRIX__
		glColorTableSGI(GL_TEXTURE_COLOR_TABLE_SGI,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors());
		#else
		glColorTableEXT(GL_TEXTURE_2D,GL_RGBA,256,GL_RGBA,GL_FLOAT,colorMap->getColors());
		#endif
		}
	
	if(myDataItem->uploadData)
		{
		/* Determine the texture's format: */
		GLenum internalFormat=GL_INTENSITY8;
		GLenum uploadFormat=GL_LUMINANCE;
		
		#ifndef __SGI_IRIX__
		if(myDataItem->renderingPath==PalettedTexture)
			{
			internalFormat=GL_COLOR_INDEX8_EXT;
			uploadFormat=GL_COLOR_INDEX;
			}
		#endif
		
		/* Upload a texture slice: */
		const Voxel* slicePtr=values+index*increments[axis];
		switch(axis)
			{
			case 0:
				glTexImage2D(GL_TEXTURE_2D,0,internalFormat,textureSize[2],textureSize[1],0,uploadFormat,GL_UNSIGNED_BYTE,0);
				glTexSubImage2D(GL_TEXTURE_2D,0,0,0,size[2],size[1],increments[2],increments[1],uploadFormat,GL_UNSIGNED_BYTE,slicePtr);
				break;
			
			case 1:
				glTexImage2D(GL_TEXTURE_2D,0,internalFormat,textureSize[2],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,0);
				glTexSubImage2D(GL_TEXTURE_2D,0,0,0,size[2],size[0],increments[2],increments[0],uploadFormat,GL_UNSIGNED_BYTE,slicePtr);
				break;
			
			case 2:
				glTexImage2D(GL_TEXTURE_2D,0,internalFormat,textureSize[1],textureSize[0],0,uploadFormat,GL_UNSIGNED_BYTE,0);
				glTexSubImage2D(GL_TEXTURE_2D,0,0,0,size[1],size[0],increments[1],increments[0],uploadFormat,GL_UNSIGNED_BYTE,slicePtr);
				break;
			}
		}
	}