Beispiel #1
0
void
fge_mesh_draw(struct fge_mesh mesh)
{
	int	i;

	glBegin(GL_TRIANGLES);
	for (i = 0; (unsigned)i < mesh.count_faces; i++ ){
		glNormal3fv((float*)&mesh.vertices[mesh.faces[i].index[0]].n);
		glMultiTexCoord3fv(GL_TEXTURE1_ARB, (float*)&mesh.vertices[mesh.faces[i].index[0]].t);
		glMultiTexCoord3fv(GL_TEXTURE2_ARB, (float*)&mesh.vertices[mesh.faces[i].index[0]].b);
		glMultiTexCoord2fv(GL_TEXTURE0_ARB, (float*)&mesh.vertices[mesh.faces[i].index[0]].tex);
		glVertex3fv((float*)&mesh.vertices[mesh.faces[i].index[0]].pos);

		glNormal3fv((float*)&mesh.vertices[mesh.faces[i].index[1]].n);
		glMultiTexCoord3fv(GL_TEXTURE1_ARB, (float*)&mesh.vertices[mesh.faces[i].index[1]].t);
		glMultiTexCoord3fv(GL_TEXTURE2_ARB, (float*)&mesh.vertices[mesh.faces[i].index[1]].b);
		glMultiTexCoord2fv(GL_TEXTURE0_ARB, (float*)&mesh.vertices[mesh.faces[i].index[1]].tex);
		glVertex3fv((float*)&mesh.vertices[mesh.faces[i].index[1]].pos);

		glNormal3fv((float*)&mesh.vertices[mesh.faces[i].index[2]].n);
		glMultiTexCoord3fv(GL_TEXTURE1_ARB, (float*)&mesh.vertices[mesh.faces[i].index[2]].t);
		glMultiTexCoord3fv(GL_TEXTURE2_ARB, (float*)&mesh.vertices[mesh.faces[i].index[2]].b);
		glMultiTexCoord2fv(GL_TEXTURE0_ARB, (float*)&mesh.vertices[mesh.faces[i].index[2]].tex);
		glVertex3fv((float*)&mesh.vertices[mesh.faces[i].index[2]].pos);
	}
	glEnd();
}
	void drawWithMultiTexture(GLuint texName1, GLuint texName2, float translate[2]) {
		// Initilize 2 textures for light mapping
		glEnable(GL_COLOR_MATERIAL);
		glColor3f(1.0,1.0,1.0);
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texName1);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		glActiveTexture(GL_TEXTURE1);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texName2);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		glMatrixMode(GL_TEXTURE);
			glPushMatrix();
			glLoadIdentity();
			glTranslatef(translate[1], translate[0], 0.0);
		glMatrixMode(GL_MODELVIEW);
		glBegin(GL_QUADS);
			glNormal3fv(this->n);
			glMultiTexCoord2fv(GL_TEXTURE0, t1);
			glMultiTexCoord2f(GL_TEXTURE1, 0, 0);
			glVertex3fv(this->v1);
			glNormal3fv(this->n);
			glMultiTexCoord2fv(GL_TEXTURE0, t2);
			glMultiTexCoord2f(GL_TEXTURE1, 0, 1);
			glVertex3fv(this->v2);
			glNormal3fv(this->n);
			glMultiTexCoord2fv(GL_TEXTURE0, t3);
			glMultiTexCoord2f(GL_TEXTURE1, 1, 1);
			glVertex3fv(this->v3);
			glNormal3fv(this->n);
			glMultiTexCoord2fv(GL_TEXTURE0, t4);
			glMultiTexCoord2f(GL_TEXTURE1, 1, 0);
			glVertex3fv(this->v4);
		glEnd();
		glFlush();
		//glDisable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE0);
		glDisable(GL_TEXTURE_2D);
		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glMatrixMode(GL_TEXTURE);
			glPopMatrix();
		glMatrixMode(GL_MODELVIEW);
		//glEnable(GL_COLOR_MATERIAL);
	}
Beispiel #3
0
void glArrayElement(GLint i) {
    if (i < 0) {
        ERROR(GL_INVALID_VALUE);
    }
    GLfloat *v;
    pointer_state_t *p;
    p = &state.pointers.color;
    if (state.enable.color_array && p->pointer) {
        v = gl_pointer_index(p, i);
        GLuint scale = gl_max_value(p->type);
        // color[3] defaults to 1.0f
        if (p->size < 4)
            v[3] = 1.0f;

        // scale color coordinates to a 0 - 1.0 range
        for (int i = 0; i < p->size; i++) {
            v[i] /= scale;
        }
        glColor4fv(v);
    }
    p = &state.pointers.normal;
    if (state.enable.normal_array && p->pointer) {
        v = gl_pointer_index(p, i);
        glNormal3fv(v);
    }
    for (int i = 0; i < MAX_TEX; i++) {
        p = &state.pointers.tex_coord[i];
        if (state.enable.tex_coord_array[i] && p->pointer) {
            v = gl_pointer_index(p, i);
            glMultiTexCoord2fv(GL_TEXTURE0 + i, v);
        }
    }
    p = &state.pointers.vertex;
    if (state.enable.vertex_array && p->pointer) {
        v = gl_pointer_index(p, i);
        if (p->size == 4) {
            glVertex4fv(v);
        } else {
            glVertex3fv(v);
        }
    }
}
Beispiel #4
0
void
Butterfly::draw()
{
    // the position of the butterfly
    // used by the shader
    glUniform3fARB(glGetUniformLocationARB(shader->getPid(), "worldpos"), pos[0], pos[1], pos[2]);

    glDepthMask(GL_TRUE);
    glEnable(GL_DEPTH_TEST);

    // local frame
    float rot[16] =
    {
        binormal[0], binormal[1], binormal[2], 0,
        dir[0], dir[1], dir[2], 0,
        normal[0], normal[1], normal[2], 0,
        pos[0], pos[1], pos[2], 1
    };
    glPushMatrix();
    glMultMatrixf(rot);
//	fprintf(stdout, "%f, %f, %f\n", pos[0], pos[1], pos[2]);

    for(int j=0; j<NUM_OBJS; j++)
    {
        glPushMatrix();
        float tmp = fabs(wing_cnt)-wing_angle;
        if(j<(NUM_OBJS>>1)) glRotatef(tmp, 0, 1, 0);
        else glRotatef(-tmp, 0, 1, 0);
        glScalef(size, size, size);

        // thickness/bump mapping texture
        glActiveTexture(GL_TEXTURE0);
        tex[(j*2)%NUM_TEXTURES].bind();
        // backface texture
        glActiveTexture(GL_TEXTURE1);
        tex[(j*2+1)%NUM_TEXTURES].bind();

//		if(j%2==0)
//		{
//			glEnable (GL_POLYGON_OFFSET_FILL);
//			glPolygonOffset (1., 1.);
//		}

        glBegin(GL_TRIANGLES);
        for(int i=0; i<geom[j].numFacets*3; i++)
        {
            glNormal3fv(geom[j].normals[geom[j].normalIdx[i]]);
            glMultiTexCoord2fv(GL_TEXTURE0, geom[j].texcoords[geom[j].texcoordIdx[i]]);
            glVertex3fv(geom[j].verts[geom[j].vertIdx[i]]);
        }
        glEnd();

//		if(j%2==0) glDisable (GL_POLYGON_OFFSET_FILL);

        glActiveTexture(GL_TEXTURE0);
        tex[(j*2)%NUM_TEXTURES].unbind();
        glActiveTexture(GL_TEXTURE1);
        tex[(j*2+1)%NUM_TEXTURES].unbind();

        glPopMatrix();

    }
Beispiel #5
0
void draw_stuff(){
    int i;
    struct point front[4] = {
    {0.0,0.0,1.0},{0.0,1.0,1.0},{1.0,1.0,1.0},{1.0,0.0,1.0}
    };
    struct point back[4] = {
    {1.0,0.0,0.0},{1.0,1.0,0.0},{0.0,1.0,0.0},{0.0,0.0,0.0}
    };
    struct point left[4] = {
    {0.0,0.0,0.0},{0.0,1.0,0.0},{0.0,1.0,1.0},{0.0,0.0,1.0}
    };
    struct point right[4] = {
    {1.0,0.0,1.0},{1.0,1.0,1.0},{1.0,1.0,0.0},{1.0,0.0,0.0}
    };
    struct point top[4] = {
    {0.0,1.0,1.0},{0.0,1.0,0.0},{1.0,1.0,0.0},{1.0,1.0,1.0}
    };
    struct point bottom[4] = {
    {0.0,0.0,0.0},{0.0,0.0,1.0},{1.0,0.0,1.0},{1.0,0.0,0.0}
    };

    glClearColor(0.35,0.35,0.35,0.0);
    float t = 1.0;
    float mytexcoords[4][2] = {{0.0,t},{t,t},{t,0.0},{0.0,0.0}};
    struct texture_control *tcp;
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
    glShadeModel(GL_SMOOTH);

    glColor3f(1.0,1.0,0.0);

    glBegin(GL_QUADS);

    glNormal3f(0.0,0.0,1.0);
    for(i=0;i<4;i++) {
		tcp = tc;
		while(tcp->name){
			glMultiTexCoord2fv(tcp->texunit,mytexcoords[i]);
			tcp++;
		}		
		glVertex3f(front[i].x,front[i].y,front[i].z);
	}
	glEnd();
	tcp = tc;
	while(tcp->name){
			glActiveTexture(tcp->texunit);
			glDisable(GL_TEXTURE_2D);
			tcp++;
		}	
	
	glBegin(GL_QUADS);
    glNormal3f(0.0,0.0,-1.0);
    for(i=0;i<4;i++) glVertex3f(back[i].x,back[i].y,back[i].z);
    glNormal3f(-1.0,0.0,0.0);
    for(i=0;i<4;i++) glVertex3f(left[i].x,left[i].y,left[i].z);
    glNormal3f(1.0,0.0,0.0);
    for(i=0;i<4;i++) glVertex3f(right[i].x,right[i].y,right[i].z);
    glNormal3f(0.0,1.0,0.0);
    for(i=0;i<4;i++) glVertex3f(top[i].x,top[i].y,top[i].z);
    glNormal3f(0.0,-1.0,0.0);
    for(i=0;i<4;i++) glVertex3f(bottom[i].x,bottom[i].y,bottom[i].z);
    glEnd();
    //glPopMatrix();
    glFlush();
    //glutSwapBuffers();
    //glutPostRedisplay();
}
Beispiel #6
0
static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELIGHT teamcolour, int pieFlag, int pieFlagData)
{
	iIMDPoly *pPolys;
	bool light = true;
	bool shaders = pie_GetShaderUsage();

	pie_SetAlphaTest((pieFlag & pie_PREMULTIPLIED) == 0);

	/* Set fog status */
	if (!(pieFlag & pie_FORCE_FOG) && 
		(pieFlag & pie_ADDITIVE || pieFlag & pie_TRANSLUCENT || pieFlag & pie_BUTTON || pieFlag & pie_PREMULTIPLIED))
	{
		pie_SetFogStatus(false);
	}
	else
	{
		pie_SetFogStatus(true);
	}

	/* Set tranlucency */
	if (pieFlag & pie_ADDITIVE)
	{
		pie_SetRendMode(REND_ADDITIVE);
		colour.byte.a = (UBYTE)pieFlagData;
		light = false;
	}
	else if (pieFlag & pie_TRANSLUCENT)
	{
		pie_SetRendMode(REND_ALPHA);
		colour.byte.a = (UBYTE)pieFlagData;
		light = false;
	}
	else if (pieFlag & pie_PREMULTIPLIED)
	{
		pie_SetRendMode(REND_PREMULTIPLIED);
		light = false;
	}
	else
	{
		if (pieFlag & pie_BUTTON)
		{
			pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
			light = false;
			if (shaders)
			{
				pie_ActivateShader(SHADER_BUTTON, shape, teamcolour, colour);
			}
			else
			{
				pie_ActivateFallback(SHADER_BUTTON, shape, teamcolour, colour);
			}
		}
		pie_SetRendMode(REND_OPAQUE);
	}
	if (pieFlag & pie_ECM)
	{
		pie_SetRendMode(REND_ALPHA);
		light = true;
		pie_SetShaderEcmEffect(true);
	}

	if (light)
	{
		glMaterialfv(GL_FRONT, GL_AMBIENT, shape->material[LIGHT_AMBIENT]);
		glMaterialfv(GL_FRONT, GL_DIFFUSE, shape->material[LIGHT_DIFFUSE]);
		glMaterialfv(GL_FRONT, GL_SPECULAR, shape->material[LIGHT_SPECULAR]);
		glMaterialf(GL_FRONT, GL_SHININESS, shape->shininess);
		glMaterialfv(GL_FRONT, GL_EMISSION, shape->material[LIGHT_EMISSIVE]);
		if (shaders)
		{
			pie_ActivateShader(SHADER_COMPONENT, shape, teamcolour, colour);
		}
		else
		{
			pie_ActivateFallback(SHADER_COMPONENT, shape, teamcolour, colour);
		}
	}

	if (pieFlag & pie_HEIGHT_SCALED)	// construct
	{
		glScalef(1.0f, (float)pieFlagData / (float)pie_RAISE_SCALE, 1.0f);
	}
	if (pieFlag & pie_RAISE)		// collapse
	{
		glTranslatef(1.0f, (-shape->max.y * (pie_RAISE_SCALE - pieFlagData)) * (1.0f / pie_RAISE_SCALE), 1.0f);
	}

	glColor4ubv(colour.vector);     // Only need to set once for entire model
	pie_SetTexturePage(shape->texpage);

	frame %= MAX(1, shape->numFrames);

	glBegin(GL_TRIANGLES);
	for (pPolys = shape->polys; pPolys < shape->polys + shape->npolys; pPolys++)
	{
		Vector3f	vertexCoords[3];
		unsigned int	n, frameidx = frame;
		int	*index;

		if (!(pPolys->flags & iV_IMD_TEXANIM))
		{
			frameidx = 0;
		}

		for (n = 0, index = pPolys->pindex;
				n < pPolys->npnts;
				n++, index++)
		{
			vertexCoords[n].x = shape->points[*index].x;
			vertexCoords[n].y = shape->points[*index].y;
			vertexCoords[n].z = shape->points[*index].z;
		}

		polyCount++;

		glNormal3fv((GLfloat*)&pPolys->normal);
		for (n = 0; n < pPolys->npnts; n++)
		{
			GLfloat* texCoord = (GLfloat*)&pPolys->texCoord[frameidx * pPolys->npnts + n];
			glTexCoord2fv(texCoord);
			if (!shaders)
			{
				glMultiTexCoord2fv(GL_TEXTURE1, texCoord);
			}
			glVertex3fv((GLfloat*)&vertexCoords[n]);
		}
	}
	glEnd();

	if (light || (pieFlag & pie_BUTTON))
	{
		if (shaders)
		{
			pie_DeactivateShader();
		}
		else
		{
			pie_DeactivateFallback();
		}
	}
	pie_SetShaderEcmEffect(false);

	if (pieFlag & pie_BUTTON)
	{
		pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);
	}
}
Beispiel #7
0
static void pie_Draw3DShape2(iIMDShape *shape, int frame, PIELIGHT colour, PIELIGHT teamcolour, WZ_DECL_UNUSED PIELIGHT specular, int pieFlag, int pieFlagData)
{
	iIMDPoly *pPolys;
	bool light = lighting;

	pie_SetAlphaTest(true);

	/* Set fog status */
	if (!(pieFlag & pie_FORCE_FOG) && 
		(pieFlag & pie_ADDITIVE || pieFlag & pie_TRANSLUCENT || pieFlag & pie_BUTTON))
	{
		pie_SetFogStatus(false);
	}
	else
	{
		pie_SetFogStatus(true);
	}

	/* Set tranlucency */
	if (pieFlag & pie_ADDITIVE)
	{
		pie_SetRendMode(REND_ADDITIVE);
		colour.byte.a = (UBYTE)pieFlagData;
		light = false;
	}
	else if (pieFlag & pie_TRANSLUCENT)
	{
		pie_SetRendMode(REND_ALPHA);
		colour.byte.a = (UBYTE)pieFlagData;
		light = false;
	}
	else
	{
		if (pieFlag & pie_BUTTON)
		{
			pie_SetDepthBufferStatus(DEPTH_CMP_LEQ_WRT_ON);
		}
		pie_SetRendMode(REND_OPAQUE);
	}

	if (light)
	{
		const float ambient[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
		const float diffuse[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
		const float specular[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
		const float shininess = 10;

		glEnable(GL_LIGHTING);
		glEnable(GL_NORMALIZE);

		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambient);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular);
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
	}

	if (pieFlag & pie_HEIGHT_SCALED)	// construct
	{
		glScalef(1.0f, (float)pieFlagData / (float)pie_RAISE_SCALE, 1.0f);
	}
	if (pieFlag & pie_RAISE)		// collapse
	{
		glTranslatef(1.0f, (-shape->max.y * (pie_RAISE_SCALE - pieFlagData)) / pie_RAISE_SCALE, 1.0f);
	}

	glColor4ubv(colour.vector);	// Only need to set once for entire model
	pie_SetTexturePage(shape->texpage);

	// Activate TCMask if needed
	if (shape->flags & iV_IMD_TCMASK &&	rendStates.rendMode == REND_OPAQUE)
	{
#ifdef _DEBUG
	glErrors();
#endif
		if (pie_GetShadersStatus())
		{
			pie_ActivateShader_TCMask(teamcolour, shape->tcmaskpage);
		}
		else
		{
			//Set the environment colour with tcmask
			GLfloat tc_env_colour[4];  
			pal_PIELIGHTtoRGBA4f(&tc_env_colour[0], teamcolour);

			// TU0
			glActiveTexture(GL_TEXTURE0);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,	GL_COMBINE);
			glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, tc_env_colour);

			// TU0 RGB
			glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,		GL_ADD_SIGNED);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB,		GL_TEXTURE);
			glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,		GL_SRC_COLOR);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB,		GL_CONSTANT);
			glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB,		GL_SRC_COLOR);

			// TU0 Alpha
			glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA,		GL_REPLACE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA,		GL_TEXTURE);
			glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,	GL_SRC_ALPHA);

			// TU1
			glActiveTexture(GL_TEXTURE1);
			glEnable(GL_TEXTURE_2D);
			glBindTexture(GL_TEXTURE_2D, _TEX_PAGE[shape->tcmaskpage].id);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,	GL_COMBINE);

			// TU1 RGB
			glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB,		GL_INTERPOLATE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB,		GL_PREVIOUS);
			glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB,		GL_SRC_COLOR);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB,		GL_TEXTURE0);
			glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB,		GL_SRC_COLOR);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB,		GL_TEXTURE);
			glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB,		GL_SRC_ALPHA);

			// TU1 Alpha
			glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA,		GL_REPLACE);
			glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA,		GL_PREVIOUS);
			glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA,	GL_SRC_ALPHA);


			// This is why we are doing in opaque mode.
			glEnable(GL_BLEND);
			glBlendFunc(GL_CONSTANT_COLOR, GL_ZERO);
			glBlendColor(colour.byte.r / 255.0, colour.byte.g / 255.0,
						colour.byte.b / 255.0, colour.byte.a / 255.0);
		}
#ifdef _DEBUG
	glErrors();
#endif
	}

	for (pPolys = shape->polys; pPolys < shape->polys + shape->npolys; pPolys++)
	{
		Vector2f	texCoords[pie_MAX_VERTICES_PER_POLYGON];
		Vector3f	vertexCoords[pie_MAX_VERTICES_PER_POLYGON];
		unsigned int n;
		VERTEXID	*index;

		for (n = 0, index = pPolys->pindex;
				n < pPolys->npnts;
				n++, index++)
		{
			vertexCoords[n].x = shape->points[*index].x;
			vertexCoords[n].y = shape->points[*index].y;
			vertexCoords[n].z = shape->points[*index].z;
			texCoords[n].x = pPolys->texCoord[n].x;
			texCoords[n].y = pPolys->texCoord[n].y;
		}

		polyCount++;

		// Run TextureAnimation (exluding the new teamcoloured models)
		if (frame && pPolys->flags & iV_IMD_TEXANIM && !(shape->flags & iV_IMD_TCMASK))
		{
			frame %= shape->numFrames;

			if (frame > 0)
			{
				const int framesPerLine = OLD_TEXTURE_SIZE_FIX / (pPolys->texAnim.x * OLD_TEXTURE_SIZE_FIX);
				const int uFrame = (frame % framesPerLine) * (pPolys->texAnim.x * OLD_TEXTURE_SIZE_FIX);
				const int vFrame = (frame / framesPerLine) * (pPolys->texAnim.y * OLD_TEXTURE_SIZE_FIX);

				for (n = 0; n < pPolys->npnts; n++)
				{
					texCoords[n].x += uFrame / OLD_TEXTURE_SIZE_FIX;
					texCoords[n].y += vFrame / OLD_TEXTURE_SIZE_FIX;
				}
			}
		}

		glBegin(GL_TRIANGLE_FAN);

		if (light)
		{
			glNormal3fv((GLfloat*)&pPolys->normal);
		}

		for (n = 0; n < pPolys->npnts; n++)
		{
			glTexCoord2fv((GLfloat*)&texCoords[n]);
			if (shape->flags & iV_IMD_TCMASK && rendStates.rendMode == REND_OPAQUE &&
				!pie_GetShadersStatus())
			{
				glMultiTexCoord2fv(GL_TEXTURE1, (GLfloat*)&texCoords[n]);
			}
			glVertex3fv((GLfloat*)&vertexCoords[n]);
		}

		glEnd();
	}

	// Deactivate TCMask if it was previously enabled
	if (shape->flags & iV_IMD_TCMASK && rendStates.rendMode == REND_OPAQUE)
	{
		if (pie_GetShadersStatus())
		{
			pie_DeactivateShader();
		}
		else
		{
			glDisable(GL_BLEND);

			glActiveTexture(GL_TEXTURE1);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
			glDisable(GL_TEXTURE_2D);

			glActiveTexture(GL_TEXTURE0);
			glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
		}
	}

	if (pieFlag & pie_BUTTON)
	{
		pie_SetDepthBufferStatus(DEPTH_CMP_ALWAYS_WRT_ON);
	}

	if (light)
	{
		glDisable(GL_LIGHTING);
		glDisable(GL_NORMALIZE);
	}
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GL13_nglMultiTexCoord2fv(JNIEnv *__env, jclass clazz, jint texture, jlong vAddress, jlong __functionAddress) {
	const GLfloat *v = (const GLfloat *)(intptr_t)vAddress;
	glMultiTexCoord2fvPROC glMultiTexCoord2fv = (glMultiTexCoord2fvPROC)(intptr_t)__functionAddress;
	UNUSED_PARAMS(__env, clazz)
	glMultiTexCoord2fv(texture, v);
}
Beispiel #9
0
void setTexture(int i) {
	switch (globalscene->mList[i].texWay)
	{
	case 0:
		/* 画出物体 */
		obj_display(globalscene->mList[i].obejct);
		break;
	case 1:
		// 必须要开启alpha test 把透明的地方挖空!
		glEnable(GL_ALPHA_TEST);
		glAlphaFunc(GL_GREATER, 0.5f);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, globalscene->mList[i].texObject1);
		//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

		/* 画出物体 */
		obj_display(globalscene->mList[i].obejct);
		/* 关闭贴图 */
		glDisable(GL_TEXTURE_2D);
		glDisable(GL_ALPHA_TEST);
		glBindTexture(GL_TEXTURE_2D, 0);
		break;
	case 2:
		//bind texture 0
		glActiveTexture(GL_TEXTURE0);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, globalscene->mList[i].texObject1);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
		glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
		//bind texture 1
		glActiveTexture(GL_TEXTURE1);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, globalscene->mList[i].texObject2);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
		glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);

		/* 画出物体 */
		// 两幅贴图的物体,贴图方式有所不同,需要另外完成,画图功能,不能直接调用 obj_display()
		{
			int lastMaterial = -1;
			for(size_t k=0;k < globalscene->mList[i].obejct->fTotal;++k)
			{
				// set material property if this face used different material
				if(lastMaterial !=globalscene->mList[i].obejct->faceList[k].m)
				{
					lastMaterial = (int)globalscene->mList[i].obejct->faceList[k].m;
					glMaterialfv(GL_FRONT, GL_AMBIENT  , globalscene->mList[i].obejct->mList[lastMaterial].Ka);
					glMaterialfv(GL_FRONT, GL_DIFFUSE  , globalscene->mList[i].obejct->mList[lastMaterial].Kd);
					glMaterialfv(GL_FRONT, GL_SPECULAR , globalscene->mList[i].obejct->mList[lastMaterial].Ks);
					glMaterialfv(GL_FRONT, GL_SHININESS, &globalscene->mList[i].obejct->mList[lastMaterial].Ns);

					//you can obtain the texture name by object->mList[lastMaterial].map_Kd
					//load them once in the main function before mainloop
					//bind them in display function here
				}

				glBegin(GL_TRIANGLES);
				for (size_t j=0;j<3;++j)
				{
					//textex corrd. 
					glMultiTexCoord2fv(GL_TEXTURE0, globalscene->mList[i].obejct->tList[globalscene->mList[i].obejct->faceList[k][j].t].ptr);
					glMultiTexCoord2fv(GL_TEXTURE1, globalscene->mList[i].obejct->tList[globalscene->mList[i].obejct->faceList[k][j].t].ptr);
					glNormal3fv(globalscene->mList[i].obejct->nList[globalscene->mList[i].obejct->faceList[k][j].n].ptr);
					glVertex3fv(globalscene->mList[i].obejct->vList[globalscene->mList[i].obejct->faceList[k][j].v].ptr);	
				}
				glEnd();
			}
		}
		//unbind texture 1
		glActiveTexture(GL_TEXTURE1);
		glDisable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, 0);
		//unbind texture 0
		glActiveTexture(GL_TEXTURE0);
		glDisable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, 0);
		break;
	case 3:
		//bind texture 0
		glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
		glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
		glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP);
		glEnable(GL_TEXTURE_GEN_S);
		glEnable(GL_TEXTURE_GEN_T);
		glEnable(GL_TEXTURE_GEN_R);
		glEnable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_CUBE_MAP, globalscene->mList[i].texObject1);
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
		/* 画出物体 */
		obj_display(globalscene->mList[i].obejct);
		/* 关闭贴图 */
		glDisable(GL_TEXTURE_GEN_S);
		glDisable(GL_TEXTURE_GEN_T);
		glDisable(GL_TEXTURE_GEN_R);
		glDisable(GL_TEXTURE_CUBE_MAP);
		glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
		break;
	}
}
Beispiel #10
0
void obj_display() {

	// 只有一个物体
	mesh *object = globalscene->mList[0].obejct;
	//bind texture 0
	// glUnifor1i( 0) for colorTexture
	glActiveTexture( GL_TEXTURE0 );
	glBindTexture(GL_TEXTURE_2D, globalscene->mList[0].ambTextureId);
	GLint location0 = glGetUniformLocation(MyShader, "colorTexture");
	if(location0 == -1)
		printf("Cant find texture name: colorTexture\n");
	else
		glUniform1i(location0, 0);
	//bind texture 1
	// glUnifor1i( 1) for diffuse Texture
	glActiveTexture( GL_TEXTURE1 );
	glBindTexture(GL_TEXTURE_2D, globalscene->mList[0].difTextureId);
	GLint location1 = glGetUniformLocation(MyShader, "diffuseTex");
	if(location1 == -1)
		printf("Cant find texture name: diffuseTex\n");
	else
		glUniform1i(location1, 1);
	//bind texture 2
	// glUnifor1i( 2) for specular Texture
	glActiveTexture( GL_TEXTURE2 );
	glBindTexture(GL_TEXTURE_2D, globalscene->mList[0].spcTextureId);
	GLint location2 = glGetUniformLocation(MyShader, "specularTex");
	if(location2 == -1)
		printf("Cant find texture name: specularTex\n");
	else
		glUniform1i(location2, 2);

	// 确定顶点属性的 location,算完切向量后,再设置属性值
	tangent_loc = glGetAttribLocation(MyShader, "tangent");
	bitangent_loc = glGetAttribLocation(MyShader, "bitangent");

	int lastMaterial = -1;
	for(size_t i=0;i < object->fTotal;++i)
	{
		// set material property if this face used different material
		if(lastMaterial != object->faceList[i].m)
		{
			lastMaterial = (int)object->faceList[i].m;
			glMaterialfv(GL_FRONT, GL_AMBIENT  , object->mList[lastMaterial].Ka);
			glMaterialfv(GL_FRONT, GL_DIFFUSE  , object->mList[lastMaterial].Kd);
			glMaterialfv(GL_FRONT, GL_SPECULAR , object->mList[lastMaterial].Ks);
			glMaterialfv(GL_FRONT, GL_SHININESS, &object->mList[lastMaterial].Ns);

			//you can obtain the texture name by object->mList[lastMaterial].map_Kd
			//load them once in the main function before mainloop
			//bind them in display function here
		}

		// 取得三个顶点 p0 p1 p2 坐标
		float *vertex0 = object->vList[object->faceList[i][0].v].ptr;
		float *vertex1 = object->vList[object->faceList[i][1].v].ptr;
		float *vertex2 = object->vList[object->faceList[i][2].v].ptr;
		glm::vec3 p0(vertex0[0], vertex0[1], vertex0[2]);
		glm::vec3 p1(vertex1[0], vertex1[1], vertex1[2]);
		glm::vec3 p2(vertex2[0], vertex2[1], vertex2[2]);
		// 取得贴图三点 对应贴图坐标
		float *texture0 = object->tList[object->faceList[i][0].t].ptr;
		float *texture1 = object->tList[object->faceList[i][1].t].ptr;
		float *texture2 = object->tList[object->faceList[i][2].t].ptr;
		glm::vec2 UV0(texture0[0], texture0[1]);
		glm::vec2 UV1(texture1[0], texture1[1]);
		glm::vec2 UV2(texture2[0], texture2[1]);
		// 得到两边
		glm::vec3 Edge1 = p1 - p0;
		glm::vec3 Edge2 = p2 - p0;
		glm::vec2 Edge1uv = UV1 - UV0;
		glm::vec2 Edge2uv = UV2 - UV0;
		// 计算切向量,副切向量
		glm::vec3 tangent, bitangent;
		float cp = Edge1uv.x * Edge2uv.y - Edge2uv.x * Edge1uv.y;
		if(cp != 0.0f) {
			float mul = 1.0f /cp;
			tangent = (Edge1 * Edge2uv.y + Edge2 * -Edge1uv.y) * mul;
			bitangent = (Edge1 * -Edge2uv.x + Edge2 * Edge1uv.x) * mul;
		}
		// specify the value of a generic vertex attribute 设置顶点属性
		glVertexAttrib3f(tangent_loc, tangent.x, tangent.y, tangent.z);
		glVertexAttrib3f(bitangent_loc, bitangent.x, bitangent.y, bitangent.z);

		glBegin(GL_TRIANGLES);
		for (size_t j=0;j<3;++j)
		{
			//textex corrd. 
			glMultiTexCoord2fv(GL_TEXTURE0, object->tList[object->faceList[i][j].t].ptr);
			glMultiTexCoord2fv(GL_TEXTURE1, object->tList[object->faceList[i][j].t].ptr);
			glMultiTexCoord2fv(GL_TEXTURE2, object->tList[object->faceList[i][j].t].ptr);
			glNormal3fv(object->nList[object->faceList[i][j].n].ptr);
			glVertex3fv(object->vList[object->faceList[i][j].v].ptr);	
		}
		glEnd();
	}
}