Jump to content
  • Advertisement
Sign in to follow this  

My object isn't entirely drawn

This topic is 2443 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am doing simple experiments with GL on Android. I want to draw a Monkey (it's a Blender's primitive), without colors, lighting, etc only the triangles. Here is what I get


catturafp.jpg
Uploaded with ImageShack.us

I turned backface culling off, but nothing changes. If I draw a cylinder, only the two faces are drawn - actually not entirely, they seem Pacman head
Can somebody explain this? I can give the code, even if it's very simple and it's Android specific

Share this post


Link to post
Share on other sites
Advertisement
Hidden

This happens if I draw a cube or a cylinder. Please help me


Short anwser : backface culling.
Try to add this before rendering : "glDisable(GL_CULL_FACE);"

Share this post


Link to post

This happens if I draw a cube or a cylinder. Please help me


Ok, I replied a bit to quickly, didn't see that you already disabled backface culling ^^'
If you post the piece of code which renders your models, I think it'll be easier for people to spot what might go wrong.

Share this post


Link to post
Share on other sites
[color=#666666][font=Arial, Helvetica, sans-serif]Here is the whole Eclipse project[/font]

This is the renderer code. Quite basic. Obviusly this is specific to Java language and Android development



public class TwoRobotsRenderer implements Renderer {
ShortBuffer mIndexBuffer;
FloatBuffer mVertexBuffer;
int triangleCount;
float seek;

public TwoRobotsRenderer(Context ctx) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(ctx.getAssets().open("two_robots.txt")));
int vertsLines = Integer.parseInt(in.readLine());
int indicesLines = Integer.parseInt(in.readLine());
triangleCount = indicesLines;
float[] vertsArray = new float[vertsLines * 3];
for (int i = 0; i < vertsLines; i++) {
String[] lines = in.readLine().split("\\s+");
vertsArray[i * 3] = Float.parseFloat(lines[0]);
vertsArray[i * 3 + 1] = Float.parseFloat(lines[1]);
vertsArray[i * 3 + 2] = Float.parseFloat(lines[2]);
}
/*
ByteBuffer bb = ByteBuffer.allocateDirect(vertsArray.length * 4);
bb.order(ByteOrder.nativeOrder());
mVertexBuffer = bb.asFloatBuffer();
mVertexBuffer.put(vertsArray);
mVertexBuffer.position(0);
*/
mVertexBuffer = FloatBuffer.wrap(vertsArray);
short[] indicesArray = new short[indicesLines * 3];
for (int i = 0; i < indicesLines; i++){
String[] lines = in.readLine().split("\\s+");
indicesArray[i * 3] = Short.parseShort(lines[0]);
indicesArray[i * 3 + 1] = Short.parseShort(lines[1]);
indicesArray[i * 3 + 2] = Short.parseShort(lines[2]);
}
/*
bb = ByteBuffer.allocateDirect(indicesArray.length * 2);
mIndexBuffer = bb.asShortBuffer();
mIndexBuffer.put(indicesArray);
mIndexBuffer.position(0);
*/
mIndexBuffer = ShortBuffer.wrap(indicesArray);
in.close();
}

float mAngle = 0.0f;
float mAngleX = 0.0f;
float mAngleY = 0.0f;
float mAngleZ = 0.0f;
@Override
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, seek);
gl.glRotatef(mAngle += 6, mAngleX += 5, mAngleY +=7, mAngleZ += 10);

gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

// Draw calls
//gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, triangleCount, GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
}

public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);

/*
* Set our projection matrix. This doesn't have to be done
* each time we draw, but usually a new projection needs to
* be set when the viewport is resized.
*/

float ratio = (float) width / height;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
/*
* By default, OpenGL enables features that improve quality
* but reduce performance. One might want to tweak that
* especially on software renderer.
*/
gl.glDisable(GL10.GL_DITHER);

/*
* Some one-time OpenGL initialization can be made here
* probably based on features of this particular context
*/
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
GL10.GL_FASTEST);

gl.glClearColor(0,0,0,0);
//gl.glDisable(GL10.GL_CULL_FACE);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
}

}


Attached is the same Eclipse project if someone has problems accessing Filefactory

Share this post


Link to post
Share on other sites
In the code pasted cull facing isn't disabled, but I can assure I played with it and nothing changes. Obviously there could be something wrong with my Blender exporter or my model importer; but actually how can one test it?

The code is GL ES 1.x (fixed pipeline)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!