Ejemplo n.º 1
0
/* keep track of lighting */
void lightState(GLint light, int status) {
	ppRenderFuncs p = (ppRenderFuncs)gglobal()->RenderFuncs.prv;
    //printf ("start lightState, light %d, status %d\n",light,status);
    
    PRINT_GL_ERROR_IF_ANY("start lightState");
    
    
	if (light<0) return; /* nextlight will return -1 if too many lights */
	if (p->lightOnOff[light] != status) {
		if (status) {
			/* printf ("light %d on\n",light); */
            
#ifndef GL_ES_VERSION_2_0
			FW_GL_ENABLE(GL_LIGHT0+light);
#endif /* GL_ES_VERSION_2_0 */
            
			p->lightStatusDirty = TRUE;
		} else {
			/* printf ("light %d off\n",light);  */
            
#ifndef GL_ES_VERSION_2_0
			FW_GL_DISABLE(GL_LIGHT0+light);
#endif /* GL_ES_VERSION_2_0 */
            
			p->lightStatusDirty = TRUE;
		}
		p->lightOnOff[light]=status;
	}
    PRINT_GL_ERROR_IF_ANY("end lightState");
}
Ejemplo n.º 2
0
static int setActiveTexture (int c, GLfloat thisTransparency,  GLint *texUnit, GLint *texMode) 
{
	ttglobal tg = gglobal();

	/* which texture unit are we working on? */
    
	/* tie each fw_TextureX uniform into the correct texture unit */
    
	/* here we assign the texture unit to a specific number. NOTE: in the current code, this will ALWAYS
	 * be [0] = 0, [1] = 1; etc. */
	texUnit[c] = c;

#ifdef TEXVERBOSE
	if (getAppearanceProperties()->currentShaderProperties != NULL) {
		printf ("setActiveTexture %d, boundTextureStack is %d, sending to uniform %d\n",c,
			tg->RenderFuncs.boundTextureStack[c],
			getAppearanceProperties()->currentShaderProperties->TextureUnit[c]);
	} else {
		printf ("setActiveTexture %d, boundTextureStack is %d, sending to uniform [NULL--No Shader]\n",c,
			tg->RenderFuncs.boundTextureStack[c]);
	}
#endif
    
	/* is this a MultiTexture, or just a "normal" single texture?  When we
	 * bind_image, we store a pointer for the texture parameters. It is
	 * NULL, possibly different for MultiTextures */

	if (tg->RenderTextures.textureParameterStack[c].multitex_mode == INT_ID_UNDEFINED) {
        
		#ifdef TEXVERBOSE
		printf ("setActiveTexture - simple texture NOT a MultiTexture \n"); 
		#endif

		/* should we set the coloUr to 1,1,1,1 so that the material does not show
		 * through a RGB texture?? */
		/* only do for the first texture if MultiTexturing */
		if (c == 0) {
			#ifdef TEXVERBOSE
			printf ("setActiveTexture - firsttexture  \n"); 
			#endif
			texMode[c]= GL_MODULATE;
		} else {
			texMode[c]=GL_ADD;
		}

	} else {
	/* printf ("muititex source for %d is %d\n",c,tg->RenderTextures.textureParameterStack[c].multitex_source); */
		if (tg->RenderTextures.textureParameterStack[c].multitex_source != MTMODE_OFF) {
		} else {
			glDisable(GL_TEXTURE_2D); /* DISABLE_TEXTURES */
			return FALSE;
		}
	}


	PRINT_GL_ERROR_IF_ANY("");

	return TRUE;
}
Ejemplo n.º 3
0
void initializeLightTables() {
	int i;
        float pos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
        float dif[] = { 1.0f, 1.0f, 1.0f, 1.0f };
        float shin[] = { 0.6f, 0.6f, 0.6f, 1.0f };
        float As[] = { 0.0f, 0.0f, 0.0f, 1.0f };
	ppRenderFuncs p = (ppRenderFuncs)gglobal()->RenderFuncs.prv;

      PRINT_GL_ERROR_IF_ANY("start of initializeightTables");

	for(i=0; i<8; i++) {
                p->lightOnOff[i] = 9999;
                lightState(i,FALSE);
            
        	FW_GL_LIGHTFV(i, GL_POSITION, pos);
        	FW_GL_LIGHTFV(i, GL_AMBIENT, As);
        	FW_GL_LIGHTFV(i, GL_DIFFUSE, dif);
        	FW_GL_LIGHTFV(i, GL_SPECULAR, shin);
          	FW_GL_LIGHTF(i, GL_CONSTANT_ATTENUATION,1.0f);
        	FW_GL_LIGHTF(i, GL_LINEAR_ATTENUATION,0.0f);
        	FW_GL_LIGHTF(i, GL_QUADRATIC_ATTENUATION,0.0f);
        	FW_GL_LIGHTF(i, GL_SPOT_CUTOFF,180.0f);
        	FW_GL_LIGHTF(i, GL_SPOT_EXPONENT,0.0f);
            
            PRINT_GL_ERROR_IF_ANY("initizlizeLight2");
        }
        lightState(HEADLIGHT_LIGHT, TRUE);

	#ifndef GL_ES_VERSION_2_0
        FW_GL_LIGHTMODELI(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
        FW_GL_LIGHTMODELI(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
        FW_GL_LIGHTMODELI(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_FALSE);
        FW_GL_LIGHTMODELI(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
        FW_GL_LIGHTMODELFV(GL_LIGHT_MODEL_AMBIENT,As);
	#else
	//printf ("skipping light setups\n");
	#endif

    LIGHTING_INITIALIZE
	

    PRINT_GL_ERROR_IF_ANY("end initializeLightTables");
}
Ejemplo n.º 4
0
static void passedInGenTex(struct textureVertexInfo *genTex) {
	int c;
	int i;
	GLint texUnit[MAX_MULTITEXTURE];
	GLint texMode[MAX_MULTITEXTURE];
	ttglobal tg = gglobal();

    s_shader_capabilities_t *me = getAppearanceProperties()->currentShaderProperties;

	#ifdef TEXVERBOSE
	printf ("passedInGenTex, using passed in genTex, textureStackTop %d\n",tg->RenderFuncs.textureStackTop);
        printf ("passedInGenTex, cubeFace %d\n",getAppearanceProperties()->cubeFace);
	#endif 

    /* simple shapes, like Boxes and Cones and Spheres will have pre-canned arrays */
	if (genTex->pre_canned_textureCoords != NULL) {
       // printf ("passedInGenTex, A\n");
		for (c=0; c<tg->RenderFuncs.textureStackTop; c++) {
            //printf ("passedInGenTex, c= %d\n",c);
			/* are we ok with this texture yet? */
			if (tg->RenderFuncs.boundTextureStack[c]!=0) {
                //printf ("passedInGenTex, B\n");
				if (setActiveTexture(c,getAppearanceProperties()->transparency,texUnit,texMode)) {
                    struct X3D_Node *tt = getThis_textureTransform();
                    //printf ("passedInGenTex, C\n");
                    if (tt!=NULL) do_textureTransform(tt,c);
                    SET_TEXTURE_UNIT_AND_BIND(getAppearanceProperties()->cubeFace,c,tg->RenderFuncs.boundTextureStack[c]);
                   
                    FW_GL_TEXCOORD_POINTER (2,GL_FLOAT,0,genTex->pre_canned_textureCoords);
                }
			}
}
	} else {
        //printf ("passedInGenTex, B\n");
		for (c=0; c<tg->RenderFuncs.textureStackTop; c++) {
            //printf ("passedInGenTex, c=%d\n",c);
			/* are we ok with this texture yet? */
			if (tg->RenderFuncs.boundTextureStack[c]!=0) {
                //printf ("passedInGenTex, C, boundTextureStack %d\n",tg->RenderFuncs.boundTextureStack[c]);
				if (setActiveTexture(c,getAppearanceProperties()->transparency,texUnit,texMode)) {
                    //printf ("passedInGenTex, going to bind to texture %d\n",tg->RenderFuncs.boundTextureStack[c]);
                    struct X3D_Node *tt = getThis_textureTransform();
                    if (tt!=NULL) do_textureTransform(tt,c);
                    SET_TEXTURE_UNIT_AND_BIND(getAppearanceProperties()->cubeFace,c,tg->RenderFuncs.boundTextureStack[c]);
                    
					FW_GL_TEXCOORD_POINTER (genTex->TC_size, 
						genTex->TC_type,
						genTex->TC_stride,
						genTex->TC_pointer);
				}
			}
		}

	}
    
    /* set up the selected shader for this texture(s) config */
	if (me != NULL) {
        //printf ("passedInGenTex, we have tts %d tc %d\n",tg->RenderFuncs.textureStackTop, me->textureCount);
        
        if (me->textureCount != -1) 
        glUniform1i(me->textureCount, tg->RenderFuncs.textureStackTop);
        
        
	    for (i=0; i<tg->RenderFuncs.textureStackTop; i++) {
        	//printf (" sending in i%d tu %d mode %d\n",i,i,tg->RenderTextures.textureParameterStack[i].multitex_mode);
            glUniform1i(me->TextureUnit[i],i);
            glUniform1i(me->TextureMode[i],tg->RenderTextures.textureParameterStack[i].multitex_mode);
        }
	#ifdef TEXVERBOSE
	} else {
		printf (" NOT sending in %d i+tu+mode because currentShaderProperties is NULL\n",tg->RenderFuncs.textureStackTop);
	#endif
	}

    
    
	PRINT_GL_ERROR_IF_ANY("");
}