Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7827989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:07:19+00:00 2026-06-02T10:07:19+00:00

Im learning OpenGL (on the Android), in my code i specify 4 triangles that

  • 0

Im learning OpenGL (on the Android), in my code i specify 4 triangles that form a tetrahedron, but for some reason 2 of the sides appear to be missing, and i dont understand why. I’ve tweaked it in almost any way i could think of and still no luck.

Here is my code, please tell me if im doing something wrong.

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;

import javax.microedition.khronos.opengles.GL10;

public class Tetrahedron {

    private IntBuffer ver;
    private IntBuffer nor;
    private ByteBuffer ind;
    private float[] mat_ambient;
    private float[] mat_diffuse;
    private float[] mat_specular;
    private float[] mat_emission;

    public Tetrahedron() {

        int one = toInt(1.0f);
        int vertices[] = {
                //face 1
                -one, -one,  one,  //point 1
                  0 ,  one,   0 ,  //point 2
                 one, -one,  one,  //point 3

                //face 2
                  0 ,  one,   0 ,  //point 2
                 one, -one,  one,  //point 3
                  0 ,   0 , -one,  //point 4

                //face 3
                 one, -one,  one,  //point 3
                  0 ,   0 , -one,  //point 4
                -one, -one,  one,  //point 1

                //face 4
                  0 ,   0 , -one,  //point 4
                -one, -one,  one,  //point 1
                  0 ,  one,   0    //point 2

        };
        int normals[] = {
                -one, -one,  one,
                  0 ,  one,  one,
                 one, -one,  one,

                 one,  one, -one,
                 one,   0 ,   0 ,
                 one,  one, -one,

                 one, -one,  one,
                  0 , -one, -one,
                -one, -one,  one,

                -one,  one, -one,
                -one,   0 ,   0 ,
                -one,  one, -one 
        };

        byte indices[] = {
                0, 1, 2,
                3, 4, 5,
                6, 7, 8,
                9,10,11

        };

        ver=getIntBuffer(vertices);
        nor=getIntBuffer(normals);
        ind=getByteBuffer(indices);

        mat_ambient = new float[4];
        mat_ambient[0] = 0.3f;
        mat_ambient[1] = 0.3f;
        mat_ambient[2] = 0.3f;
        mat_ambient[3] = 1.0f;

        mat_diffuse = new float[4];
        mat_diffuse[0] = 0.9f;
        mat_diffuse[1] = 0.9f;
        mat_diffuse[2] = 0.9f;
        mat_diffuse[3] = 1.0f;

        mat_specular = new float[4];
        mat_specular[0] = 0.1f;
        mat_specular[1] = 0.1f;
        mat_specular[2] = 0.1f;
        mat_specular[3] = 1.0f;

        mat_emission = new float[4];
        mat_emission[0] = 0.0f;
        mat_emission[1] = 1.0f;
        mat_emission[2] = 0.0f;
        mat_emission[3] = 1.0f; 

    }
    private IntBuffer getIntBuffer(int[] data){
        ByteBuffer byteBuf = ByteBuffer.allocateDirect(data.length * 4);
        byteBuf.order(ByteOrder.nativeOrder());
        IntBuffer buf = byteBuf.asIntBuffer();
        buf.put(data);
        buf.position(0);
        return buf;
    }
    private ByteBuffer getByteBuffer(byte[] data){
        ByteBuffer buf = ByteBuffer.allocateDirect(data.length);
        buf.put(data);
        buf.position(0);
        return buf;
    }
    private int toInt(float num){
        return (int)(num*65536);
    }

    public void draw(GL10 gl){
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);


        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mat_ambient, 0);
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mat_diffuse, 0);
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, mat_specular, 0);
        gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_EMISSION, mat_emission, 0);
        gl.glMaterialf(GL10.GL_FRONT, GL10.GL_SHININESS, 56);

        gl.glFrontFace(GL10.GL_CW);
        gl.glVertexPointer(3, GL10.GL_FIXED, 0, ver);
        gl.glNormalPointer(GL10.GL_FIXED, 0, nor);
        gl.glDrawElements(GL10.GL_TRIANGLES, ind.capacity(), GL10.GL_UNSIGNED_BYTE, ind);

        gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
        gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T10:07:21+00:00Added an answer on June 2, 2026 at 10:07 am

    You can try to disable face culling just to make sure you don’t have those faces backwards:

    gl.glDisable(GL10.GL_CULL_FACE);
    //You should also comment out this: gl.glFrontFace(GL10.GL_CW);
    

    If this fixes the problem, reverse the winding of the problematic triangles (switch point 1 and 3) and then restore face culling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning OpenGL on Android. I've written an app where the GlSurfaceView is declared
I'm currently learning OpenGL ES programming on Android (2.1). I started with the obligatory
I want to start learning OpenGL but I don't really want to have to
I am learning OpenGL these days, and I tried to compile the example code
I need to visualize 3D point clouds using C++, I started learning OpenGL but
I am learning OpenGL with an aim to build OpenGL ES application for Android
I am just learning OpenGL, and I'm realizing that for more complex shader effects,
What are some good resources for learning OpenGL 4.1 aimed at someone relatively new
I'm looking into learning OpenGL ES for making a little graphics engine in Android
I'm new to opengl. As a learning exercise I started manually building some basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.