[RESOLVED]OpenGL and OBJ : strange results

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

[RESOLVED]OpenGL and OBJ : strange results

Postby tikimove » Thu Jun 11, 2009 5:22 pm

Hi all,

I am developing a small OpenGL renderer with a loader for OBJ files. It works well for some OBJ files and not for others... See the captures please.

Here is my code. Can you help me to determinate why I have these strange artifacts ?

Thanks

ModelRenderer.java :

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         public float xrot;
  3.  
  4.         public float yrot;
  5.  
  6.         public float camZ;
  7.  
  8.  
  9.  
  10.         public ModelRenderer(final Model pModel) {
  11.  
  12.                 super();
  13.  
  14.                 this.model = pModel;
  15.  
  16.                 this.xrot = 0;
  17.  
  18.                 this.yrot = 0;
  19.  
  20.                 this.camZ = 3;
  21.  
  22.         }
  23.  
  24.  
  25.  
  26.         public void onSurfaceCreated(final GL10 pGl, final EGLConfig pConfig) {
  27.  
  28.                 // Enabling the states...
  29.  
  30.                 pGl.glEnable(GL10.GL_DEPTH_TEST);
  31.  
  32.                 pGl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  33.  
  34.                 pGl.glEnableClientState(GL10.GL_COLOR_ARRAY);
  35.  
  36.                
  37.  
  38.                 pGl.glShadeModel(GL10.GL_SMOOTH);
  39.  
  40.         }
  41.  
  42.  
  43.  
  44.         public void onSurfaceChanged(final GL10 pGl, final int pWidth,
  45.  
  46.                         final int pHeight) {
  47.  
  48.                 pGl.glViewport(0, 0, pWidth, pHeight);
  49.  
  50.  
  51.  
  52.                 // Setup project matrix
  53.  
  54.                 pGl.glMatrixMode(GL10.GL_PROJECTION);
  55.  
  56.                 pGl.glLoadIdentity();
  57.  
  58.                 GLU.gluPerspective(pGl, 45.0f, (float) pWidth / pHeight, 1f, 200f);
  59.  
  60.         }
  61.  
  62.  
  63.  
  64.         public void onDrawFrame(final GL10 pGl) {
  65.  
  66.                 pGl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  67.  
  68.                 pGl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
  69.  
  70.  
  71.  
  72.                 pGl.glMatrixMode(GL10.GL_MODELVIEW);
  73.  
  74.                 pGl.glLoadIdentity();
  75.  
  76.                 GLU.gluLookAt(pGl, 0, 0, this.camZ, 0, 0, 0, 0, 1, 0);
  77.  
  78.  
  79.  
  80.                 Buffer vertices = this.model.getVertices();
  81.  
  82.                 pGl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
  83.  
  84.                
  85.  
  86.                 Buffer colors = this.model.getColors();
  87.  
  88.                 pGl.glColorPointer(4, GL10.GL_FLOAT, 0, colors);
  89.  
  90.  
  91.  
  92.                 pGl.glRotatef(this.xrot, 1, 0, 0);
  93.  
  94.                 pGl.glRotatef(this.yrot, 0, 1, 0);
  95.  
  96.  
  97.  
  98.                 pGl.glDrawElements(GL10.GL_TRIANGLES, this.model.getFacesCount(),
  99.  
  100.                                 GL10.GL_UNSIGNED_SHORT, this.model.getFaces());
  101.  
  102.         }
  103.  
  104.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4
Attachments
ko_model.png
Model with strange effects
ko_model.png (34.12 KiB) Viewed 1610 times
ok_model.png
Model which works well
ok_model.png (78.76 KiB) Viewed 1610 times
Last edited by tikimove on Thu Jun 11, 2009 5:52 pm, edited 1 time in total.
tikimove
Developer
Developer
 
Posts: 30
Joined: Tue Jan 13, 2009 2:59 pm

Top

Postby tikimove » Thu Jun 11, 2009 5:52 pm

Get it !

While exporting from 3DS, choose TRIANGLES instead of QUAD...
tikimove
Developer
Developer
 
Posts: 30
Joined: Tue Jan 13, 2009 2:59 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests