Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: glDrawArrays not rendering -LWJGL

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    4

    glDrawArrays not rendering -LWJGL

    Hello guys, recently i ended quake mdl loader, into lwjgl. But i decided to use VBO's to optimize and speed up models rendering, rather than using only glVertex3f.
    My code is the following:
    Code :
    	public void renderFrame(int n, boolean hasToRefreshSkin)
    	{
    		if ((n < 0) || (n > this.header.numFrames - 1))//Car n démarre à 0
    		{
    			System.out.println("n in invalid range !");
    			return;
    		}
     
    		if(this.texturesID[0] == 0)
    		{
    			this.makeTextureFromSkin();
    		}
    		else if(hasToRefreshSkin)
    			this.makeTextureFromSkin();
     
    //		glBegin(GL_TRIANGLES);
    		if(this.buffer == null)
    		{
    			for(int i = 0; i < 2; i++)
    			{
    				for(int j = 0; j < 3; j++)
    				{
    					Vertex vert = this.frames[n].verticesArray[this.triangles[i].verticesIndices[j]];
    					this.vertsList.add((this.header.scale.x * vert.coordinates[0]) + this.header.translate.x);
    					this.vertsList.add((this.header.scale.y * vert.coordinates[1]) + this.header.translate.y);
    					this.vertsList.add((this.header.scale.z * vert.coordinates[2]) + this.header.translate.z);
    				}
    			}
    //			float[] array = new float[]
    //					{
    //						0, 2, -4, -2, -2, -4, 2, -2, -4
    //					};
    //			float[] array = new float[]
    //					{
    //					86.0F,
    //					118.0F,
    //					143.0F,
    //					
    //					88.0F,
    //					117.0F,
    //					145.0F,
    //					
    //					91.0F,
    //					119.0F,
    //					146.0F,
    //					
    //					86.0F,
    //					118.0F,
    //					143.0F,
    //					
    //					79.0F,
    //					115.0F,
    //					149.0F,
    //					
    //					88.0F,
    //					117.0F,
    //					145.0F
    //
    //					};
    			float[] array = new float[vertsList.size()];
    			for(int i = 0; i < array.length; i++)
    				array[i] = vertsList.get(i);
    			buffer = BufferUtils.createFloatBuffer(this.header.numVertices * 3 * 4);
    			buffer.put(array);
    			buffer.rewind();
    //			buffer.flip();
    		}
     
    		for(int i = 0; i < this.header.numTriangles; i++)
    		{
    			for(int j = 0; j < 3; j++)
    			{
    				Vertex vert = this.frames[n].verticesArray[this.triangles[i].verticesIndices[j]];
     
    //				float s = this.textureCoordinates[this.triangles[i].verticesIndices[j]].s;
    //				float t = this.textureCoordinates[this.triangles[i].verticesIndices[j]].t;
    //				if(this.triangles[i].facesFront == 0 && this.textureCoordinates[this.triangles[i].verticesIndices[j]].onSeam == 1)
    //					s += this.header.skinWidth * 0.5F;//backface
    //				
    //				/* Scale s and t to range from 0.0 to 1.0 */
    //				s = (s + 0.5F) / this.header.skinWidth;
    //				t = (t + 0.5F) / this.header.skinHeight;
     
    //				glTexCoord2f(s, t);
     
    //				glNormal3f(this.normalTable[vert.normalIndex * 3], this.normalTable[(vert.normalIndex * 3) + 1], this.normalTable[(vert.normalIndex * 3) + 2]);
     
    //				glVertex3f((this.header.scale.x * vert.coordinates[0]) + this.header.translate.x,
    //						(this.header.scale.y * vert.coordinates[1]) + this.header.translate.y,
    //						(this.header.scale.z * vert.coordinates[2]) + this.header.translate.z);
    			}
    		}
    //				glVertex3f((this.header.scale.x * 86) + this.header.translate.x, (this.header.scale.y * 118) + this.header.translate.y, (this.header.scale.z * 143) + this.header.translate.z);
    //				glVertex3f((this.header.scale.x * 88) + this.header.translate.x, (this.header.scale.y * 117) + this.header.translate.y, (this.header.scale.z * 145) + this.header.translate.z);
    //				glVertex3f((this.header.scale.x * 91) + this.header.translate.x, (this.header.scale.y * 119) + this.header.translate.y, (this.header.scale.z * 146) + this.header.translate.z);
     
    				glEnableClientState(GL_VERTEX_ARRAY);
     
    					glVertexPointer(3, 0, buffer);
    					glDrawArrays(GL_TRIANGLES, 0, this.header.numVertices);
     
    				glDisableClientState(GL_VERTEX_ARRAY);
    //			}
    //		}
    		glEnd();
    	}
    But nothing appears on the screen, while glVertex3f works perfectly. Any idea ? Thank you in advance !
    Last edited by Plaigon; 12-15-2017 at 12:24 PM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    2,859
    Your counts are inconsistent. If you're going to copy an array to a buffer, use the actual length of the array, not the number of items you think might be in it. Likewise for the count parameter to glDrawArrays(). Also, you don't show the declaration or initialisation of vertsList; is that actually empty when renderFrame() is called?

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2017
    Posts
    4
    It's fixed, sorry for the inconvenience ! And thanks for your answer !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •