I'm new to OpenGL. I'm playing around with JOGL.
I have a .obj model that I'm drawing as polygons. It looks ok, except that most of it gets clipped. So I think that I need to increase the draw distance.
I'm not really sure how to do it. Here is my render code:
private void render(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
GLUgl2 glu = new GLUgl2();
gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
// Position the camera
glu.gluLookAt(cameraPos.x, cameraPos.y, cameraPos.z, cameraPos.x
+ cameraForward.x, cameraPos.y + cameraForward.y, cameraPos.z
+ cameraForward.z, cameraUp.x, cameraUp.y, cameraUp.z);
// uncommenting out this line will make everything disappear.
// glu.gluPerspective(2, 1, 10, 1000);
// ****** Start of example code ******
gl.glCallList(axes); // Show X, Y, Z axes
gl.glCallList(secondLines);
gl.glCallList(triangle);
gazebo.render(gl);
// ...
It's possible that my problem is something else entirely. gazebo
is of type ObjModel
, a class that reads and represents .obj
files. Here are its render and build draw list methods:
private int drawID = 0;
public ObjModel(String fn, GL2 gl) {
// ...
readFile(fn);
drawID = buildDrawList(gl);
}
public void render(GL2 gl) {
gl.glCallList(drawID);
}
private int buildDrawList(GL2 gl) {
int result = gl.glGenLists(1);
gl.glNewList(result, GL2.GL_COMPILE);
gl.glPushMatrix();
gl.glBegin(GL2.GL_POLYGON);
for (Point3f vert : vertices) {
gl.glVertex3f(vert.x, vert.y, vert.z);
}
gl.glEnd();
gl.glPopMatrix();
gl.glEndList();
return result;
}
private void readFile(String filename) {
try {
BufferedReader input = new BufferedReader(new FileReader(fileName));
try {
String newLine = null;
while ((newLine = input.readLine()) != null) {
int indVn = newLine.indexOf("vn ");
if (indVn != -1) {
readNormal(newLine);
continue;
}
int indV = newLine.indexOf("v ");
if (indV != -1) {
readVertex(newLine);
continue;
}
int indF = newLine.indexOf("f ");
if (indF != -1) {
readPolygon(newLine);
continue;
}
int indVt = newLine.indexOf("vt ");
if (indVt != -1) {
readTexture(newLine);
continue;
}
}
} finally {
input.close();
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
I can post screenshots if more information is needed.
Any advice? Thanks.