Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…works into 3DGraphics
  • Loading branch information
NickHardeman committed Jan 18, 2013
2 parents 81d2470 + 7947250 commit e9bb475
Show file tree
Hide file tree
Showing 498 changed files with 45,692 additions and 22,812 deletions.
87 changes: 63 additions & 24 deletions addons/ofx3DModelLoader/src/3DS/model3DS.cpp
Expand Up @@ -523,7 +523,14 @@ void mesh3DS::draw(){
float shininess = currentMaterial.getShininess();
float adjustedSpecular[4] = {specular[0]*shininess, specular[1]*shininess, specular[2]*shininess, 1};

#ifndef TARGET_OPENGLES
glPushAttrib(GL_LIGHTING_BIT);
#endif

#ifdef TARGET_OPENGLES
/* In OpenGL ES, the GL_FRONT_AND_BACK flag is the only flag that can be passed */
materialFaces = GL_FRONT_AND_BACK;
#else
if(currentMaterial.isTwoSided()){
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1);
materialFaces = GL_FRONT_AND_BACK;
Expand All @@ -532,6 +539,7 @@ void mesh3DS::draw(){
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,0);
materialFaces = GL_FRONT;
}
#endif

// Apply material colors
if(glIsEnabled(GL_LIGHTING)){
Expand All @@ -545,44 +553,74 @@ void mesh3DS::draw(){
glMaterialfv(materialFaces, GL_SPECULAR, adjustedSpecular);
glMaterialf(materialFaces, GL_SHININESS, 128.f * currentMaterial.getSpecularExponent());
}
else glColor3fv(currentMaterial.getDiffuseColor());
else
{
const float* color = currentMaterial.getDiffuseColor();
glColor4f(color[0], color[1], color[2], 1.0f);
}

const std::vector<ushort> *currentMatFaces = &(materialsIter->second);
numFaces = (int)currentMatFaces->size(); //number of faces in this material

switch(m_drawMode){
case DRAW_IMMEDIATE_MODE:

glBegin(GL_TRIANGLES);
// This is like DRAW_VERTEX_ARRAY, but the array is not already constructed, so we need to do it here
for(face=0; face<numFaces; face+=3){
if(hasTextureMap){
texcoordIndex = (*currentMatFaces)[face]*2;
glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
int vertexIndices[] = {
(*currentMatFaces)[face]*3,
(*currentMatFaces)[face+1]*3,
(*currentMatFaces)[face+2]*3
};
float vertex_data[] = {
m_normals[vertexIndices[0]], m_normals[vertexIndices[0]+1], m_normals[vertexIndices[0]+2],
m_normals[vertexIndices[1]], m_normals[vertexIndices[1]+1], m_normals[vertexIndices[1]+2],
m_normals[vertexIndices[2]], m_normals[vertexIndices[2]+1], m_normals[vertexIndices[2]+2]

};
float normal_data[] = {
m_vertices[vertexIndices[0]], m_vertices[vertexIndices[0]+1], m_vertices[vertexIndices[0]+2],
m_vertices[vertexIndices[1]], m_vertices[vertexIndices[1]+1], m_vertices[vertexIndices[1]+2],
m_vertices[vertexIndices[2]], m_vertices[vertexIndices[2]+1], m_vertices[vertexIndices[2]+2]

};

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
if (hasTextureMap) {
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
}
vertexIndex = (*currentMatFaces)[face]*3;
glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
glVertex3f(m_vertices[vertexIndex], m_vertices[vertexIndex+1], m_vertices[vertexIndex+2]);

if(hasTextureMap){
texcoordIndex = (*currentMatFaces)[face+1]*2;
glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
glVertexPointer(3, GL_FLOAT, 0, vertex_data);
glNormalPointer(GL_FLOAT, 0, normal_data);

if (hasTextureMap) {
int texCoordIndices[] = {
(*currentMatFaces)[face]*2,
(*currentMatFaces)[face+1]*2,
(*currentMatFaces)[face+2]*2
};
float texcoord_data[] = {
m_texcoords[texCoordIndices[0]], m_texcoords[texCoordIndices[0]+1],
m_texcoords[texCoordIndices[1]], m_texcoords[texCoordIndices[1]+1],
m_texcoords[texCoordIndices[2]], m_texcoords[texCoordIndices[2]+1]
};

glTexCoordPointer(2, GL_FLOAT, 0, texcoord_data);
// don't move this statement out of the block since texcoord_data will be out of scope otherwise
glDrawArrays(GL_TRIANGLES, 0, 3);
}
else
{
glDrawArrays(GL_TRIANGLES, 0, 3);
}
vertexIndex = (*currentMatFaces)[face+1]*3;
glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
glVertex3f(m_vertices[vertexIndex], m_vertices[vertexIndex+1], m_vertices[vertexIndex+2]);

glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
if(hasTextureMap){
texcoordIndex = (*currentMatFaces)[face+2]*2;
glTexCoord2f(m_texcoords[texcoordIndex], m_texcoords[texcoordIndex+1]);
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
vertexIndex = (*currentMatFaces)[face+2]*3;
glNormal3f(m_normals[vertexIndex], m_normals[vertexIndex+1], m_normals[vertexIndex+2]);
glVertex3f(m_vertices[vertexIndex], m_vertices[vertexIndex+1], m_vertices[vertexIndex+2]);
}
glEnd();

break;

case DRAW_VERTEX_ARRAY:

glEnableClientState( GL_VERTEX_ARRAY );
Expand Down Expand Up @@ -630,8 +668,9 @@ void mesh3DS::draw(){
std::cout<<"[3DS] ERROR: Invalid mesh draw mode specified"<<std::endl;
break;
}

#ifndef TARGET_OPENGLES
glPopAttrib(); // GL_LIGHTING_BIT
#endif
}
}

Expand Down
5 changes: 5 additions & 0 deletions addons/ofx3DModelLoader/src/3DS/texture3DS.cpp
Expand Up @@ -78,7 +78,12 @@ texture3DS::texture3DS(string filename, const int textureId){
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

// Upload texture to card with bound texture ID
#ifdef TARGET_OPENGLES
glTexParameterf(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, m_width, m_height, 0, fileFormat, GL_UNSIGNED_BYTE, flippedPixels);
#else
gluBuild2DMipmaps(GL_TEXTURE_2D, internalFormat, m_width, m_height, fileFormat, GL_UNSIGNED_BYTE, flippedPixels);
#endif

ofLog(OF_LOG_NOTICE, "texture3DS Texture %s loaded", filename.c_str());
}
2 changes: 1 addition & 1 deletion addons/ofxAndroid/ofAndroidLib/project.properties
Expand Up @@ -9,4 +9,4 @@

android.library=true
# Project target.
target=android-8
target=android-17
@@ -0,0 +1,7 @@
package cc.openframeworks;

import android.app.Activity;

public abstract class OFActivity extends Activity {
public void onGLSurfaceCreated(){}
}

0 comments on commit e9bb475

Please sign in to comment.