void myinit()
{
    int i;
    glClearColor (0.0, 0.0, 0.0, 1.0);
    gluOrtho2D(0.0, (GLdouble) n, 0.0, (GLdouble) m);//(left, right,bottom,top)

// define pseudocolor maps, ramps for red blue green

    for(i=0;i<255;i++){
		//redmap[i]=(sin (PI/(i+1))+1)/2;//rings, not a large range of color,
		//redmap[i] = 1-i/255.0; //bright center dark top/bot
		//redmap[i] = i/255.0;//edges faint
		redmap[i] = 0.7*((i<128)?i/128.0: 1-(i-128)/128.0);//edges faint
		bluemap[i]=(i<128)?1-i/128.0: (i-128)/128.0;//filled center bright edges (red)
		greenmap[i]=(i<64)?1-(i+64)/128.0:((i<172)?(i-64)/128.0:1-(i-172)/128.0);//edges center 
		//redmap[i] = (i*i/ pow(1.1,i))/60;//rings and edges
		//redmap[i] = (0.0003259469*i*i-0.000001278223*i*i*i)/3.2;//edges and top/bot
		//redmap[i] = 0.0;
		//greenmap[i] = 0.0;
		//bluemap[i] = 0.0;
    }
    glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, bluemap);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, redmap);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, greenmap);
}
Beispiel #2
0
void
piglit_init(int argc, char **argv)
{
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glTranslatef(-1.0, -1.0, 0.0);
	glScalef(2.0/piglit_width, 2.0/piglit_height, 1.0);

	glDisable(GL_DITHER);
	glClearColor(1, 1, 1, 1);
	glBlendFunc(GL_SRC_ALPHA, GL_ZERO);

	glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, r_map);
	glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, g_map);
	glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, b_map);
	glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, a_map);

	glPixelTransferi(GL_MAP_COLOR, GL_FALSE);

	glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
	glPixelStorei(GL_UNPACK_ALIGNMENT, ALIGN);

	glGenTextures(1, &tex_name);
	glBindTexture(GL_TEXTURE_2D, tex_name);

	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
void Texture::setup_pixel_transfer_for_grayscale(int nb_colors )
{
	nb_colors_ = nb_colors ;
	ogf_assert(nb_colors_ <= 512) ;
	if(!encode_indexed_to_rgb_) {
		static float i2r[512] ;
		static float i2g[512] ;
		static float i2b[512] ;
		static float i2a[512] ;
		for(int i=0; i<nb_colors_; i++) {
			float c = float(i) / float(nb_colors - 1) ;
			i2r[i] = c ;  
			i2g[i] = c ;
			i2b[i] = c ;
			i2a[i] = c ; 
		}
		glPixelMapfv(GL_PIXEL_MAP_I_TO_R, nb_colors, i2r);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_G, nb_colors, i2g);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_B, nb_colors, i2b);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_A, nb_colors, i2a);
	} else {
		for(int i=0; i<nb_colors_; i++) {
			Memory::byte c = Memory::byte( 
				255.0 * float(i) / float(nb_colors - 1) 
				) ;
			i2r_[i] = c ;  
			i2g_[i] = c ;
			i2b_[i] = c ;
			i2a_[i] = c ; 
		}
	}
}
void Texture::setup_pixel_transfer_for_colormap(const Colormap* colormap) 
{
	nb_colors_ = colormap->size() ;
	ogf_assert(nb_colors_ <= 512) ;
	if(!encode_indexed_to_rgb_) {
		static float i2r[512] ;
		static float i2g[512] ;
		static float i2b[512] ;
		static float i2a[512] ;
		for(int i=0; i<nb_colors_; i++) {
			i2r[i] = float(colormap->color_cell(i).r()) / 255.0f ;
			i2g[i] = float(colormap->color_cell(i).g()) / 255.0f ;
			i2b[i] = float(colormap->color_cell(i).b()) / 255.0f ;
			i2a[i] = float(colormap->color_cell(i).a()) / 255.0f ;
		}
		glPixelMapfv(GL_PIXEL_MAP_I_TO_R, nb_colors_, i2r);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_G, nb_colors_, i2g);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_B, nb_colors_, i2b);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_A, nb_colors_, i2a);
	} else {
		for(int i=0; i<nb_colors_; i++) {
			i2r_[i] = colormap->color_cell(i).r() ;
			i2g_[i] = colormap->color_cell(i).g() ;
			i2b_[i] = colormap->color_cell(i).b() ;
			i2a_[i] = colormap->color_cell(i).a() ;
		}
	}
}
Win32GLGrDriver2D::Context::Context( Win32GLGraphics *g ):BBGrContext(g),
graphics(g),font(_font),glFont(0),cliprect(0,0,g->width(),g->height()),color(BBColor::white()){

	font->retain();

	if( !graphics->glContext() ) return;

	bbPushGLContext( graphics->glContext() );

	glViewport( 0,0,g->width(),g->height() );

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();
	glOrtho( 0,g->width(),g->height(),0,0,1 );

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glAlphaFunc( GL_GREATER,.5f );

	glColor3ub( 255,255,255 );

	float pm[2]={0,1};

	glPixelMapfv( GL_PIXEL_MAP_I_TO_R,2,pm );
	glPixelMapfv( GL_PIXEL_MAP_I_TO_G,2,pm );
	glPixelMapfv( GL_PIXEL_MAP_I_TO_B,2,pm );

	bbPopGLContext();
}
Beispiel #6
0
void ogl_Setup() {
	glViewport(0, 0, g_iWidth, g_iHeight);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity(); 
	
	gluPerspective(45.0, static_cast<float>(g_iWidth) / static_cast<float>(g_iHeight), 0.1, 100);

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

	glClearDepth(1.0f);
	glDepthFunc(GL_LESS);
	glEnable(GL_DEPTH_TEST); 

	glShadeModel(GL_SMOOTH);
	glDisable(GL_LIGHTING);

	glCullFace(GL_BACK);
	glFrontFace(GL_CCW);
	glEnable(GL_CULL_FACE);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDisable(GL_ALPHA_TEST);	

	glEnable(GL_TEXTURE_2D);

	glGenTextures(1, &g_uiTexName);

	img_Load8bppBMP(std::string("test.bmp"));

	for (int i = 0; i < 256; i++) g_apal[i] = 1.0f;

/*	std::ofstream tf("maps.txt");
	for (i = 0; i < 256; i++) {
		tf << i << " R: " << g_rpal[i] << ", G: " << g_gpal[i] << ", B: " << g_bpal[i] << ", A: " << g_apal[i] << std::endl;			
	}	  */

	/*std::ofstream bin("index.bin", std::ios_base::binary | std::ios_base::out);
	bin.write(g_data, 512*512);*/

	glPixelTransferi(GL_MAP_COLOR, GL_TRUE);

	glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, g_rpal);
	glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, g_gpal);
	glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, g_bpal);
	glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 256, g_apal);

	glBindTexture(GL_TEXTURE_2D, g_uiTexName);
	glTexImage2D(GL_TEXTURE_2D, 0, 4, g_iTexWid, g_iTexHei, 0, GL_COLOR_INDEX, GL_UNSIGNED_BYTE, g_pcData);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
void WaterfallContext::refreshTheme() {
    glEnable (GL_TEXTURE_2D);

    for (int i = 0; i < 2; i++) {
        glBindTexture(GL_TEXTURE_2D, waterfall[i]);

        glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
        glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getRed())[0]);
        glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getGreen())[0]);
        glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, &(ThemeMgr::mgr.currentTheme->waterfallGradient.getBlue())[0]);
    }
}
Beispiel #8
0
void RenderToTexture(size_t screenw, size_t screenh)
{
	static bool once(false);
	static size_t w(0), h(0);

	if(selected_shader == -1)
		return;

	if(!once)
	{
		glGenTextures(1, &r2texture);
		once = true;
	}
	
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, r2texture);

	if(selected_shader == -1)
	{
		// no shading at all, use imaging extension
		float map[256];
		for(int i = 0; i < 256; i++)map[i]=(float)(i)/256;
		//glPixelTransferi(GL_MAP_COLOR, true);
//		glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 256, map);

		//glPixelMapfv(GL_PIXEL_MAP_I_TO_I, 256, map);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, map);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, map);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, map);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 256, map);
	}	

	if(w != next_pow2(screenw) || h != next_pow2(screenh))
	{
		w = next_pow2(screenw);
		h = next_pow2(screenh);
		
		glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, w, h, 0);
		
		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);
	}
	else
	{
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screenw, screenh);
	}

	if(selected_shader == -1)
		glPixelTransferi(GL_MAP_COLOR, false);
}
Beispiel #9
0
void Texture::enablePalette()
{
    #ifndef HAVE_GLES
        if (!hasPalette()) return;

        glPixelTransferi(GL_INDEX_SHIFT, 0);
        glPixelTransferi(GL_INDEX_OFFSET, 0);
        glPixelTransferi(GL_MAP_COLOR, GL_TRUE);

        glPixelMapfv(GL_PIXEL_MAP_I_TO_R, paletteSize, paletteRed);
        glPixelMapfv(GL_PIXEL_MAP_I_TO_G, paletteSize, paletteGreen);
        glPixelMapfv(GL_PIXEL_MAP_I_TO_B, paletteSize, paletteBlue);

    #endif
}
void Win32GLGrDriver2D::setColor( BBColor c ){

	_context->color=c;

	if( !_glContext ) return;

	glColor3ub( c.r,c.g,c.b );

	float pm_r[]={0,c.r/255.0f};
	float pm_g[]={0,c.g/255.0f};
	float pm_b[]={0,c.b/255.0f};

	glPixelMapfv( GL_PIXEL_MAP_I_TO_R,2,pm_r );
	glPixelMapfv( GL_PIXEL_MAP_I_TO_G,2,pm_g );
	glPixelMapfv( GL_PIXEL_MAP_I_TO_B,2,pm_b );
}
void key(unsigned char k, int xx, int yy){
	int i;
	if(k=='r'){
		if(redTog==1){
			for(i=0;i<256;i++){
				redmap[i] = 0.0;
			}
			redTog=0;
		}else{
			for(i=0;i<256;i++){
				redmap[i] = (i<128)?1-i/128.0: (i-128)/128.0;
			}
			redTog=1;
		}
	}
	if(k=='b'){
		if(blueTog==1){
			for(i=0;i<256;i++){
				bluemap[i] = 0.0;
			}
			blueTog=0;
		}else{
			for(i=0;i<256;i++){
				bluemap[i] = i/255.0;
			}
			blueTog=1;
		}
	}
	if(k=='g'){
		if(greenTog==1){
			for(i=0;i<256;i++){
				greenmap[i] = 0.0;
			}
			greenTog=0;
		}else{
			for(i=0;i<256;i++){
				greenmap[i] = (i<64)?1-(i+64)/128.0:((i<172)?(i-64)/128.0:1-(i-172)/128.0);
			}
			greenTog=1;
		}
	}
	glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, bluemap);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, redmap);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, greenmap);
	glDrawPixels(n,m,GL_COLOR_INDEX, GL_UNSIGNED_BYTE, dimention[dimIter].image);
	glFlush();
}
Beispiel #12
0
void __glXDisp_PixelMapfv(GLbyte *pc)
{
	glPixelMapfv( 
		*(GLenum   *)(pc + 0),
		*(GLint    *)(pc + 4),
		(GLfloat  *)(pc + 8)
	);
}
Beispiel #13
0
void download_palette(Image const * palette)
{
    Image_Format format = palette->format;
    int const map_size = format.size.x;

    /* XXX relax for other format and types */
    assert(format.format == GL_RGBA);
    assert(format.type == GL_UNSIGNED_BYTE);
    assert(format.size.y == 1);
    assert(format.size.z == 1);

    unsigned char * pixels = (unsigned char *) palette->pixels;

    float * map[4] =
    {
		(float *) malloc(map_size * sizeof(GLubyte)),
		(float *) malloc(map_size * sizeof(GLubyte)),
		(float *) malloc(map_size * sizeof(GLubyte)),
		(float *) malloc(map_size * sizeof(GLubyte))
    };

    int i;
    for (i = 0; i != map_size; ++ i)
    {
        map[0][i] = pixels[i * 4 + 0] / 255.0;
        map[1][i] = pixels[i * 4 + 1] / 255.0;
        map[2][i] = pixels[i * 4 + 2] / 255.0;
        map[3][i] = pixels[i * 4 + 3] / 255.0;
    }

    glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_R, map_size, map[0]);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_G, map_size, map[1]);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_B, map_size, map[2]);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_A, map_size, map[3]);

    free(map[0]);
    free(map[1]);
    free(map[2]);
    free(map[3]);
}
Beispiel #14
0
void set_palette() {
    GLfloat red[256], green[256], blue[256];

    for (int i = 0; i < 256 ; i++) {
        red[i] = colors[i+COLOROFFSET][0];
        green[i] = colors[i+COLOROFFSET][1];
        blue[i] = colors[i+COLOROFFSET][2];
    }

    glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, red);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, green);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, blue);

    glPixelTransferi(GL_INDEX_SHIFT, -8);


    // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    // glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);


}
Beispiel #15
0
/* use pixel path to remap 3D texture data */
void
remaptex(void)
{
    int i, size;
    GLfloat *map;

    glPixelTransferi(GL_MAP_COLOR, GL_TRUE);

    glGetIntegerv(GL_MAX_PIXEL_MAP_TABLE, &size);

    map = (GLfloat *)malloc(sizeof(GLfloat) * size);
    for(i = 0; i < size;i++)
    {
	map[i] = (GLfloat)i/(size - 1);
	if(((GLfloat)i/size > minboost) &&
	   ((GLfloat)i/size < minboost + boostwid))
	{
	    map[i] *= boost;
	}
	else
	    map[i] /= boost;
    }

    glPixelMapfv(GL_PIXEL_MAP_R_TO_R, size, map);
    glPixelMapfv(GL_PIXEL_MAP_G_TO_G, size, map);
    glPixelMapfv(GL_PIXEL_MAP_B_TO_B, size, map);
    glPixelMapfv(GL_PIXEL_MAP_A_TO_A, size, map);

#ifdef GL_EXT_texture3D
    glTexImage3DEXT(GL_TEXTURE_3D_EXT, 0, GL_LUMINANCE_ALPHA,
		    texwid, texht, texdepth,
		    0,
		    GL_RGBA, GL_UNSIGNED_BYTE, tex3ddata);
#endif

    glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
    free(map);

    CHECK_ERROR("OpenGL Error in remaptex()");
}
void myinit()
{
    float redmap[256], greenmap[256],bluemap[256];
    int i;

    glClearColor (1.0, 1.0, 1.0, 1.0);
    gluOrtho2D(0.0, 0.0, (GLfloat) n, (GLfloat) m);

    /* Define pseudocolor maps, ramps for red and blue,
       random for green */


    for(i=0; i<256; i++)
    {
        redmap[i]=i/255.;
        greenmap[i]=drand48();
        bluemap[i]=1.0-i/255.;
    }

    glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, redmap);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, greenmap);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, bluemap);
}
Beispiel #17
0
void 
init(void)
{
    int colorMatrixExtension,
        blendMinMaxExtension;

    /*
     * Points 
     */
    points = (Point *) malloc(maxPoints * sizeof(Point));
    makepoints();
    makecone();

    /*
     * Matrices 
     */
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-1.0, 1.0, -1.0, 1.0, -4.0, 4.0);
    glMatrixMode(GL_MODELVIEW);
    glScalef(2.0 / w, 2.0 / h, 1.0);
    glTranslatef(-w / 2.0, -h / 2.0, 0.0);

    /*
     * Misc 
     */
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);

    /*
     * Test for the required features 
     */
    colorMatrixExtension = isExtensionSupported("GL_SGI_color_matrix");
    blendMinMaxExtension = isExtensionSupported("GL_EXT_blend_minmax");
    canDrawEdges = (colorMatrixExtension && blendMinMaxExtension) ||
	(strncmp((const char *) glGetString(GL_VERSION), "1.2", 3) == 0);

    /*
     * Test for blend extension 
     */
    if (canDrawEdges) {
	GLfloat table[256];
	int i;

	/*
	 * Pixel transfer parameters 
	 */
	table[0] = 1.0;
	for (i = 1; i < 256; i++)
	    table[i] = 0.0;
	glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 256, table);
	glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 256, table);
	glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 256, table);
    } else {
	printf("This OpenGL implementation does not support the color matrix and/or\n");
	printf("the min/max blending equations, therefore the option to draw the\n");
	printf("Voronoi region edges is unavailable.\n\n");
	printf("The required features are available with OpenGL 1.2 or the GL_EXT_blend_minmax\n");
	printf("and GL_SGI_color_matrix extensions.\n");
    }
}
Beispiel #18
0
M(void, glPixelMapfv, jint map, jint mapsize, jobject values) {
	glPixelMapfv(map, mapsize, BUFF(GLfloat, values));
}
Beispiel #19
0
void app_DrawFrame() {
	static float rot = 0.0f;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glTranslatef(0.0f, 0.0f, -3.0f);

	if (g_bRotate) rot += 1.0f;

	glRotatef(rot, 0.0, 1.0, 0.0);

	if (g_bCycle1) {
		GLfloat tmp[4];
		tmp[0] = g_rpal[256 - 16 - 1];
		tmp[1] = g_gpal[256 - 16 - 1];
		tmp[2] = g_bpal[256 - 16 - 1];
		tmp[3] = g_apal[256 - 16 - 1];
		for (int i = 256 - 16 - 1; i > 0; i--) {
			g_rpal[i] = g_rpal[i-1];
			g_gpal[i] = g_gpal[i-1];
			g_bpal[i] = g_bpal[i-1];
			g_apal[i] = g_apal[i-1];
		}

		g_rpal[0] = tmp[0];
		g_gpal[0] = tmp[1];
		g_bpal[0] = tmp[2];
		g_apal[0] = tmp[3];
	}

	if (g_bCycle2) {
		GLfloat tmp[4];
		tmp[0] = g_rpal[256 - 1];
		tmp[1] = g_gpal[256 - 1];
		tmp[2] = g_bpal[256 - 1];
		tmp[3] = g_apal[256 - 1];
		for (int i = 256 - 1; i > 256 - 16; i--) {
			g_rpal[i] = g_rpal[i-1];
			g_gpal[i] = g_gpal[i-1];
			g_bpal[i] = g_bpal[i-1];
			g_apal[i] = g_apal[i-1];
		}

		g_rpal[256 - 16] = tmp[0];
		g_gpal[256 - 16] = tmp[1];
		g_bpal[256 - 16] = tmp[2];
		g_apal[256 - 16] = tmp[3];
	}

	if (g_bCycle1 || g_bCycle2) {
		glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, g_rpal);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, g_gpal);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, g_bpal);
		glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 256, g_apal);

		glBindTexture(GL_TEXTURE_2D, g_uiTexName);
		glTexSubImage2D
		(
			GL_TEXTURE_2D,
			0, 0, 0,
			g_iTexWid, g_iTexHei,
			GL_COLOR_INDEX, GL_UNSIGNED_BYTE,
			g_pcData
		);
	}

	glBegin(GL_QUADS);
		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
		glBindTexture(GL_TEXTURE_2D, g_uiTexName);

		// Front face
		glTexCoord2f(1.0f, 0.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(-1.0f, 1.0f, 0.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(-1.0f, -1.0f, 0.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(1.0f, -1.0f, 0.0f);

		// Back face
		glTexCoord2f(1.0f, 0.0f);
		glVertex3f(-1.0f, 1.0f, 0.0f);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(1.0f, -1.0f, 0.0f);
		glTexCoord2f(1.0f, 1.0f);
		glVertex3f(-1.0f, -1.0f, 0.0f);
	glEnd();

	glFlush();
}
Beispiel #20
0
static void Draw(void)
{
    float mapI[2], mapIA[2], mapIR[2];

    glClear(GL_COLOR_BUFFER_BIT);

    mapI[0] = 0.0;
    mapI[1] = 1.0;
    mapIR[0] = 0.0;
    mapIR[1] = 0.0;
    mapIA[0] = 1.0;
    mapIA[1] = 1.0;
    
    glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, mapIR);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, mapI);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, mapI);
    glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, mapIA);
    glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
    
    SetColor(COLOR_WHITE);
    glRasterPos3fv(boxA);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 24);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 8);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, 2);
    glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glBitmap(16, 12, 8.0, 0.0, 0.0, 0.0, logo_bits);

    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
    glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    SetColor(COLOR_WHITE);
    glRasterPos3fv(boxB);
    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
	     OpenGL_bits1);
    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
	     OpenGL_bits2);

    SetColor(COLOR_YELLOW);
    glRasterPos3fv(boxC);
    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
	     OpenGL_bits1);
    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
	     OpenGL_bits2);

    SetColor(COLOR_CYAN);
    glRasterPos3fv(boxD);
    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
	     OpenGL_bits1);
    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
	     OpenGL_bits2);

    SetColor(COLOR_RED);
    glRasterPos3fv(boxE);
    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
	     OpenGL_bits1);
    glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
	     OpenGL_bits2);

    glFlush();

    if (doubleBuffer) {
	glutSwapBuffers();
    }
}
Beispiel #21
0
void
DisplayScene(void)
{
  static GLboolean pixelsFlipped = GL_FALSE;
  static GLfloat   saturation    = 1.0;
  GLfloat          colorMap[256];
  GLint            i;
    
  glClear(GL_COLOR_BUFFER_BIT);
        
  /* 
   * Let OpenGL know that when it reads our pixel data from memory it's 
   * TIGHTLY packed. Not packed to it's default of 4 bytes.
   */
  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    
  switch(renderMode) 
  {
    case 1:
      if(pixelsFlipped != GL_TRUE) 
      {
        glPixelZoom(-1.0, -1.0);
        glRasterPos2i(img->width, img->height);
        pixelsFlipped = GL_TRUE;
      }
      else 
      {
        glPixelZoom(1.0, 1.0);
        glRasterPos2i(0, 0);
        pixelsFlipped = GL_FALSE;
      }
      break;
                
    case 2:
      glPixelTransferf(GL_RED_SCALE, 1.0);
      glPixelTransferf(GL_GREEN_SCALE, 1.0);
      glPixelTransferf(GL_BLUE_SCALE, 1.0);
      break;
            
    case 3:
      glPixelTransferf(GL_RED_SCALE, 1.0);
      glPixelTransferf(GL_GREEN_SCALE, 0.0);
      glPixelTransferf(GL_BLUE_SCALE, 0.0);
      break;
            
    case 4:
      glPixelTransferf(GL_RED_SCALE, 0.0);
      glPixelTransferf(GL_GREEN_SCALE, 1.0);
      glPixelTransferf(GL_BLUE_SCALE, 0.0);
      break;
            
    case 5:
      glPixelTransferf(GL_RED_SCALE, 0.0);
      glPixelTransferf(GL_GREEN_SCALE, 0.0);
      glPixelTransferf(GL_BLUE_SCALE, 1.0);
      break;
            
    case 6:
      saturation -= 0.5;
      glPixelTransferf(GL_RED_SCALE, saturation);
      glPixelTransferf(GL_GREEN_SCALE, saturation);
      glPixelTransferf(GL_BLUE_SCALE, saturation);
      break;
            
    case 7:
      saturation += 0.5;
      glPixelTransferf(GL_RED_SCALE, saturation);
      glPixelTransferf(GL_GREEN_SCALE, saturation);
      glPixelTransferf(GL_BLUE_SCALE, saturation);
      break;
            
    case 8:
      colorMap[0] = 1.0f;
      for(i = 1; i < 256; i++)
        colorMap[i] = 1.0f - (1.0f / 255.0f * (GLfloat)i);
                
      glPixelMapfv(GL_PIXEL_MAP_R_TO_R, 255, colorMap);
      glPixelMapfv(GL_PIXEL_MAP_G_TO_G, 255, colorMap);
      glPixelMapfv(GL_PIXEL_MAP_B_TO_B, 255, colorMap);
      glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
      break;
            
    default:
      break;
  }
  glDrawPixels(img->width, 
               img->height, 
               img->format, 
               GL_UNSIGNED_BYTE, 
               img->image);
  glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
  glFlush();
}
Beispiel #22
0
void tile_set_draw_tile(struct tile_set *ts, struct tile_texture *tt)
{
    if (!tt->texture_valid) {
        glGenTextures( 1, &tt->texture_id );
        tt->texture_valid = 1;

        glPixelTransferi(GL_INDEX_SHIFT, 0);
        glPixelTransferi(GL_INDEX_OFFSET, 0);
        glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
      
        uint8_t *data = (uint8_t*) malloc(tt->tile->width * tt->tile->height);
        
        gridmap_decode_base(data, tt->tile->width, tt->tile->height, tt->tile->data, tt->tile->datalen);
        
        glPixelStorei (GL_UNPACK_ROW_LENGTH, tt->tile->width);
        glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
        glBindTexture (GL_TEXTURE_2D, tt->texture_id);
        glTexImage2D (GL_TEXTURE_2D, 
                      0, 
                      GL_RGBA8, 
                      tt->tile->width, tt->tile->height, 
                      0, 
                      GL_COLOR_INDEX, 
                      GL_UNSIGNED_BYTE,
                      data);
        
        glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
        glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
        glBindTexture (GL_TEXTURE_2D, 0);

        free(data);
    }

    glPushAttrib (GL_ENABLE_BIT);
    glEnable (GL_BLEND);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable (GL_DEPTH_TEST);
    glEnable (GL_TEXTURE_2D);
    
    if (ts->r && ts->g && ts->b && ts->a) {
        glPixelTransferi(GL_INDEX_SHIFT, 0);
        glPixelTransferi(GL_INDEX_OFFSET, 0);
        glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
        
        glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 256, ts->r);
        glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 256, ts->g);
        glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 256, ts->b);
        glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 256, ts->a);
    }

    glPixelStorei (GL_UNPACK_ROW_LENGTH, tt->tile->width);
    glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
    glBindTexture (GL_TEXTURE_2D, tt->texture_id);
    
    glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
                    GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
                    GL_NEAREST);
    
    double x0 = tt->tile->x0;
    double x1 = tt->tile->x0 + tt->tile->width * tt->tile->meters_per_pixel;
    double y0 = tt->tile->y0;
    double y1 = tt->tile->y0 + tt->tile->height * tt->tile->meters_per_pixel;
    
    int d = 1;
    glBegin (GL_QUADS);
    glTexCoord2i (0,0);
    glVertex2d (x0, y0);
    glTexCoord2i (0, d);
    glVertex2d (x0, y1);
    glTexCoord2i (d, d);
    glVertex2d (x1, y1);
    glTexCoord2i (d, 0);
    glVertex2d (x1, y0);
    glEnd ();

    glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
    glBindTexture (GL_TEXTURE_2D, 0);
    glPopAttrib ();
}