Hi there,
I was encoutering a problem and have no idea how to fix it. the code is as below, the problem is that, when i draw one .obj file, everytiing is fine. but if i draw 2 diffient obj files, the color of the first obj would be overwrited by the following obj. I seached a lot and i guess it must be something about "color clear or something", but after hundreds of times of trying,still stucked here... public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClearColor(0.95f, 0.95f, 0.95f, 0.5f); gl.glClearDepth(1.0f);// set clear depth value to farthest gl.glEnable(GL2.GL_DEPTH_TEST); // enables depth testing gl.glEnable(GL2.GL_CULL_FACE); gl.glDepthFunc(GL2.GL_LEQUAL); // the type of depth test to do gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); gl.glShadeModel(GL2.GL_SMOOTH); gl.glEnable(GL2.GL_NORMALIZE); loadModels(gl); gl.glMatrixMode(GL2.GL_MODELVIEW); animator.start(); } public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); setLight(gl,lightAmb,lightDif); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrthof(-frameWidth/2, frameWidth/2, -frameHeight/2, frameHeight/2, -near,near); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glShadeModel(GL2.GL_SMOOTH); gl.glScaled(fScale *0.1, fScale *0.1, fScale*0.1); gl.glTranslatef(transf.x, transf.y, transf.z); gl.glRotatef(rotatef.y, 1f, 0f, 0f); gl.glRotatef(rotatef.x, 0f, 1f, 0f); gl.glScaled(fScale * fScaleRate, fScale * fScaleRate, fScale * fScaleRate); drawAsixes(gl); if (iCounter<10) { if(mObj.size()==0) { mObj.add(new M3DPart(gl,"E:/123.obj")); } mObj.get(0).mDrawInPos(0, 100, 0, 0, 0, 0); }else { if(mObj.size()==1) { mObj.add(new M3DPart(gl,"E:/xxx.obj")); } mObj.get(0).mDrawInPos(0, 100, 0, 0, 0, 0); mObj.get(1).mDrawInPos(0, 200, 0, 0, 0, 0); } gl.glFlush(); if (animator.isPaused() == false) { iCounter++; animator.pause(); } } public void Draw() { gl.glEnable(GL2.GL_COLOR_MATERIAL); gl.glEnableVertexAttribArray(0); gl.glBindBuffer(GL_ARRAY_BUFFER, vbo.get(0)); gl.glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); gl.glEnableClientState(GL_VERTEX_ARRAY); gl.glEnableVertexAttribArray(1); gl.glBindBuffer(GL_ARRAY_BUFFER, vbo.get(1)); gl.glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0); gl.glEnableClientState(GL_COLOR_ARRAY); gl.glEnableVertexAttribArray(2); gl.glBindBuffer(GL_ARRAY_BUFFER, vbo.get(2)); gl.glVertexAttribPointer(2, 2, GL_FLOAT, false, 0, 0); gl.glEnableClientState(GL_NORMAL_ARRAY); gl.glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo.get(0)); gl.glDrawElements(GL_TRIANGLES, data.faceCounter*3, GL_UNSIGNED_INT, 0); gl.glEnableClientState(GL_ELEMENT_ARRAY_BUFFER); // gl.glDisableVertexAttribArray(0); // gl.glDisableVertexAttribArray(1); // gl.glDisableVertexAttribArray(2); gl.glDisable(GL2.GL_COLOR_MATERIAL); } |
Administrator
|
Please can you post a SSCCE?
http://sscce.org/ I don't think that it comes from the clear color, look at the content of your VBOs and ensure that you bind the good one. Look at Xerxes's example in the wiki.
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |