[Problem].Obj Model not loaded fully using VBO/VAO

Hello everyone :slight_smile:

Lately I am trying to make small game in java using lwjgl. I also try as much as I can to write my own code, since I want to learn java and openGL. So far most of code is mine - sometimes I have to copy others - I cannot reinvent the wheel…

Now on to the issue :
I am trying to import .obj models into my “engine/game” and so far I managed to load only part of it and the problem is that I cannot figure out why my whole model isn’t being rendered.

I made simple cube in Blender 2.72b - here is .obj

# Blender v2.72 (sub 0) OBJ File: ''
# www.blender.org
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -0.999999
v 0.999999 1.000000 1.000001
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
s off
f 1 2 3 4
f 5 8 7 6
f 1 5 6 2
f 2 6 7 3
f 3 7 8 4
f 5 1 4 8

And when I run the program I get only top and bottom face :

http://pokit.org/get/img/4fe6d14ce93f1da3aef980a729ee223c.png

My code for loading .obj is (NOTE : it probably looks noobish and “weird” - I am still learning :slight_smile: )

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import static org.lwjgl.opengl.ARBBufferObject.*;
import static org.lwjgl.opengl.ARBVertexBufferObject.*;
import com.jogamp.opengl.*;

import javax.swing.JOptionPane;

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.*;
public class ObjectLoad {
	
	ByteBuffer inx;
	int indices[];
	float verts[];
	public int vaoID = 0;
	public int vboID = 0;
	public ObjectLoad(String objfolder, String objfile, int size)
	{
		 
		ArrayList<Float> verticesL = new ArrayList<Float>();
		ArrayList<Integer> indicesL = new ArrayList<Integer>();
		
		FileReader objectfile = null;
		try {
			objectfile = new FileReader(objfolder + "/" + objfile);
		} catch (FileNotFoundException e2) {
			System.out.println(" File not found !");
			JOptionPane.showMessageDialog(null,
				    "File not found.",
				    "Error - Failed to Load Object",
				    JOptionPane.ERROR_MESSAGE);
			e2.printStackTrace();
		}
		
		String line;
		
		
		try{
		BufferedReader br = new BufferedReader(objectfile);
		while( (line=br.readLine()) != null)
		{
			if( line.startsWith("v"))
			{
				String parts[] = line.split(" ");
				verticesL.add(Float.parseFloat(parts[1]));
				verticesL.add(Float.parseFloat(parts[2]));
				verticesL.add(Float.parseFloat(parts[3]));
			}
			if (line.startsWith("f"))
			{
				String parts[] = line.split(" ");
				indicesL.add(Integer.parseInt(parts[1]));
				indicesL.add(Integer.parseInt(parts[2]));
				indicesL.add(Integer.parseInt(parts[3]));
				indicesL.add(Integer.parseInt(parts[4]));
			}
		}
		}catch(FileNotFoundException e){
			e.printStackTrace();
			
		}catch( Exception e1)
		{
			e1.printStackTrace();
		
		}
		float[] verticesA = new float[verticesL.size()];
		int[] indicesA = new int[indicesL.size()];
		for(int i = 0;i < verticesL.size(); i++)
		verticesA[i] = verticesL.get(i);
		for(int i = 0;i < indicesL.size(); i++)
		indicesA[i] = indicesL.get(i);
		
		indices = indicesA;
		verts = verticesA;
		for(int i = 0;i < verts.length; i++)
			System.out.println(i + ". vertex : " + verts[i]);
		
		
		
		
		
	}
	public void setUP()
	{
	
		FloatBuffer vertexData = BufferUtils.createFloatBuffer(verts.length);
		vertexData.put(verts);
		vertexData.flip();
		
		vaoID = GL30.glGenVertexArrays();
		GL30.glBindVertexArray(vaoID);
		vboID = GL15.glGenBuffers();
	
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID );
		GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertexData , GL15.GL_STATIC_DRAW);
		GL20.glVertexAttribPointer(0, 3, GL11.GL_FLOAT, false, 0, 0);
		GL20.glEnableVertexAttribArray(0);
		inx = BufferUtils.createByteBuffer(indices.length);
      
        GL30.glBindVertexArray(0);
        
	}
	public void render()
	{
	
		GL30.glBindVertexArray(vaoID);
		GL20.glEnableVertexAttribArray(0);
	
		GL11.glDrawArrays(GL11.GL_QUADS, 0, 36);
		
		GL20.glDisableVertexAttribArray(0);
        GL30.glBindVertexArray(0);
        //GL11.glDrawElements(GL11.GL_QUADS, inx);
    	
		
	}
	public void cleanMemory()
	{
		GL20.glDisableVertexAttribArray(0);
		
		GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
		GL15.glDeleteBuffers(vboID);
		
		GL30.glBindVertexArray(0);
		GL30.glDeleteVertexArrays(vaoID);
	}
}

If you need anything from “main” just tell me :slight_smile:
Any help is appreciated :slight_smile:
Thanks in advance :slight_smile: