- (Void) display
{
static GLfloat lightPosition [4] = {20.0, 20.0, 21};
static GLfloat lightDefuse [4] = {1.0, 1, 1, 1.0};
static GLfloat lightAmbient [4] = {1.0, 1.0, 1.0, 1.0};
/ / NSLog (@ "__display");
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/ / Draw 3d model
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable (GL_COLOR_MATERIAL);
/ / Rough reflection
glLightfv (GL_LIGHT0, GL_DIFFUSE, lightDefuse);
/ / Multiple reflections
glLightfv (GL_LIGHT0, GL_AMBIENT, lightAmbient);
glLightf (GL_LIGHT0, GL_SPOT_EXPONENT, 68);
glLightfv (GL_LIGHT0, GL_POSITION, lightPosition);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0, -0, -5);
glRotatef (g_RotateX, 0, 1.0f, 0);
g_RotateX - = 5;
for (int i = 0; i
if (g_3DModel.pObject.size () <= 0) break;
t3DObject * pObject = & g_3DModel.pObject [i];
if (pObject-> bHasTexture) {
glEnable (GL_BLEND);
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, tex.name);
} Else {
glDisable (GL_TEXTURE_2D);
glColor4f (1, 1, 1, 1);
}
for (int j = 0; j
{
glPushMatrix ();
GLfloat normalV [9] = {0};
GLfloat vertex [9] = {0};
GLfloat texcoord [6] = {0};
GLfloat color [12] = {0};
for (int whichVertex = 0; whichVertex <3; whichVertex + +)
{
int index = pObject-> pFaces [j] vertIndex [whichVertex];.
normalV [whichVertex * 3] = pObject-> pNormals [index] x;.
normalV [whichVertex * 3 +1] = pObject-> pNormals [index] y;.
normalV [whichVertex * 3 +2] = pObject-> pNormals [index] z;.
if (pObject-> bHasTexture) {
if (pObject-> pTexVerts) {
texcoord [(whichVertex) * 2] = pObject-> pTexVerts [index] x;.
texcoord [(whichVertex) * 2 +1] = pObject-> pTexVerts [index] y;.
}
} Else {
if (g_3DModel.pMaterials.size () && pObject-> materialID> = 0)
{
GLubyte * pColor = g_3DModel.pMaterials [pObject-> materialID] color;.
color [whichVertex * 4] = pColor [0] / (float) 255;
color [whichVertex * 4 +1] = pColor [1] / (float) 255;
color [whichVertex * 4 +2] = pColor [2] / (float) 255;
color [whichVertex * 4 +3] = 1;
}
}
vertex [whichVertex * 3] = pObject-> pVerts [index] x;.
vertex [whichVertex * 3 +1] = pObject-> pVerts [index] y;.
vertex [whichVertex * 3 +2] = pObject-> pVerts [index] z;.
}
if (pObject-> bHasTexture) {
if (pObject-> pTexVerts) {
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (2, GL_FLOAT, 0, texcoord);
}
} Else {
if (g_3DModel.pMaterials.size () && pObject-> materialID> = 0)
{
glEnableClientState (GL_COLOR_ARRAY);
glColorPointer (4, GL_FLOAT, 0, color);
}
}
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glEnableClientState (GL_VERTEX_ARRAY);
glEnableClientState (GL_NORMAL_ARRAY);
glBindTexture (GL_TEXTURE_2D, tex.name);
glTexCoordPointer (2, GL_FLOAT, 0, texcoord);
glVertexPointer (3, GL_FLOAT, 0, vertex);
/ / GlColor4f (0.9, 0.5, 0.5, 1);
glScalef (0.5,0.5, 0.5);
glNormalPointer (GL_FLOAT, 0, normalV);
glDrawArrays (GL_TRIANGLES, 0, 3);
glDisableClientState (GL_VERTEX_ARRAY);
glDisableClientState (GL_NORMAL_ARRAY);
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
if (pObject-> bHasTexture) {
if (pObject-> pTexVerts) {
glDisableClientState (GL_TEXTURE_COORD_ARRAY);
}
} Else {
if (g_3DModel.pMaterials.size () && pObject-> materialID> = 0)
{
glDisableClientState (GL_COLOR_ARRAY);
}
}
if (pObject-> bHasTexture) {
glDisable (GL_TEXTURE_2D);
}
glPopMatrix ();
}
}
NSLog (@ "________________exit");
glDisable (GL_LIGHT0);
glDisable (GL_LIGHTING);
[Self drawView];
}
This is my drawing code to draw 3ds model, currently able to draw out the model, if the model is composed of a color does not normally drawn maps, if the model has maps can only draw a white model, texture paste does not go up. Please greatly help us to see, this is why?
Reply:
Reply:
Brother can introduce in the next ios 3d developed what stuff you use
No comments:
Post a Comment