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 6369405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:48:03+00:00 2026-05-25T00:48:03+00:00

I want to display for example an *.obj file. and normal, in OpenGL I

  • 0

I want to display for example an *.obj file.
and normal, in OpenGL I use instruction :

glBegin(Traing..);
glVertex3f(Face[i].VertexIndex);
glTexcoords2f(Face[i].TexcoordIndex);
glNormal(Face[i].NormalIndex);
glEnd();

But in Android OpenGL i don’t have this functions…
i have an DrawElements(…);
but when I want draw face 34/54/3 ( vertex/texcord/normal index of arrays)
it’s drawing linear 34/34/34…

so how I can draw a *.obj file?


I search in the web and I found this topic :
http://www.anddev.org/android-2d-3d-graphics-opengl-problems-f55/obj-import-to-opengl-trouble-t48883.html So.. I writing an Model editor in C# to my game and I wrote something like that for test :

   public void display2()
    {
        GL.EnableClientState(ArrayCap.VertexArray);
        GL.EnableClientState(ArrayCap.TextureCoordArray);
        GL.EnableClientState(ArrayCap.NormalArray);


        double[] vertexBuff = new double[faces.Count * 3 * 3];
        double[] normalBuff = new double[faces.Count * 3 * 3];
        double[] texcorBuff = new double[faces.Count * 3 * 2];


        foreach (face f in faces)
        {
            for (int i = 0; i < f.vector.Length; i++)
            {
                vertexBuff[i_3] = mesh[f.vector[i]].X;
                vertexBuff[i_3 + 1] = mesh[f.vector[i]].Y;
                vertexBuff[i_3 + 2] = mesh[f.vector[i]].Z;

                normalBuff[i_3] = normal[f.normal[i]].X;
                normalBuff[i_3 + 1] = normal[f.normal[i]].Y;
                normalBuff[i_3 + 2] = normal[f.normal[i]].Z;


                texcorBuff[i_2] = texture[f.texCord[i]].X;
                texcorBuff[i_2 + 1] = texture[f.texCord[i]].Y;
                i_3 += 3;
                i_2 += 2;
            }

        }
        GL.VertexPointer<double>(3, VertexPointerType.Double, 0, vertexBuff);
        GL.TexCoordPointer<double>(2, TexCoordPointerType.Double, 0, texcorBuff);
        GL.NormalPointer<double>(NormalPointerType.Double, 0, normalBuff);


        GL.DrawArrays(BeginMode.Triangles, 0, faces.Count * 3);

        GL.DisableClientState(ArrayCap.VertexArray);
        GL.DisableClientState(ArrayCap.TextureCoordArray);
        GL.DisableClientState(ArrayCap.NormalArray);
    }

and it’s working.. but I think that this could be more optimized?…
I don’t want to change my data of model to the arraysbuffer,
because it takes too much space in memory.. any suggestion?

  • 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-05-25T00:48:03+00:00Added an answer on May 25, 2026 at 12:48 am

    I’m not an Android programmer but I assume it uses OpenGL-ES in which these functions are deprecated (and by the way missing).

    Tutorials explaining the good solution are drawn amongst a bunch of others that show how to draw triangles with glVertex3f functions (because it gives easy and fast results but totally pointless). I find it tragic since NOBODY should use those things.

    glBegin/glEnd, glVertex3f, glTexcoords2f, and such functions are now deprecated for performance sake (they are “slow” because we have to limit the number of calls to the graphic library). I won’t expand much on that since you can search for it if interested.
    Instead, make use of Vertex and Indices buffers. I’m sorry because I have no “perfect” link to recommend, but you should easily get what you need on google 🙂


    However, I dug up some come from an ancient C# project:

    • Note: OpenTK binding change functions name but they remain very close to the OGL ones, for example glVertex3f becomes GL.Vertex3.

    The Vertex definition

    A simple struct to store your custom vertex’s informations (position, normal (if needed), color…)

    [System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential, Pack = 1)]
    public struct Vertex
    {
      public Core.Math.Vector3 Position;
      public Core.Math.Vector3 Normal;
      public Core.Math.Vector2 UV;
      public uint Coloring;
    
    
      public Vertex(float x, float y, float z)
      {
        this.Position = new Core.Math.Vector3(x, y, z);
        this.Normal = new Core.Math.Vector3(0, 0, 0);
        this.UV = new Core.Math.Vector2(0, 0);
    
        System.Drawing.Color color = System.Drawing.Color.Gray;
        this.Coloring = (uint)color.A << 24 | (uint)color.B << 16 | (uint)color.G << 8 | (uint)color.R;
      }
    
    }
    

    The Vertex Buffer class

    It’s a wrapper class around an OpenGL buffer object to handle our vertex format.

    public class VertexBuffer
    {
      public uint Id;
      public int Stride;
      public int Count;
    
      public VertexBuffer(Graphics.Objects.Vertex[] vertices)
      {
        int size;
    
        // We create an OpenGL buffer object
        GL.GenBuffers(1, out this.Id); //note: out is like passing an object by reference in C#
        this.Stride = OpenTK.BlittableValueType.StrideOf(vertices); //size in bytes of the VertexType (Vector3 size*2 + Vector2 size + uint size)
        this.Count = vertices.Length;
    
        // Fill the buffer with our vertices data
        GL.BindBuffer(BufferTarget.ArrayBuffer, this.Id);
        GL.BufferData(BufferTarget.ArrayBuffer, (System.IntPtr)(vertices.Length * this.Stride), vertices, BufferUsageHint.StaticDraw);
        GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
    
        if (vertices.Length * this.Stride != size)
          throw new System.ApplicationException("Vertex data not uploaded correctly");
    
      }
    
    }
    

    The Indices Buffer class

    Very similar to the vertex buffer, it stores vertex indices of each face of your model.

    public class IndexBuffer
    {
      public uint Id;
      public int Count;
    
    
      public IndexBuffer(uint[] indices)
      {
        int size;
        this.Count = indices.Length;
    
        GL.GenBuffers(1, out this.Id);
        GL.BindBuffer(BufferTarget.ElementArrayBuffer, this.Id);
        GL.BufferData(BufferTarget.ElementArrayBuffer, (System.IntPtr)(indices.Length * sizeof(uint)), indices,
                      BufferUsageHint.StaticDraw);
        GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
    
        if (indices.Length * sizeof(uint) != size)
            throw new System.ApplicationException("Indices data not uploaded correctly");
      }
    
    }
    

    Drawing buffers

    Then, to render a triangle, you have to create one Vertex Buffer to store vertices’ positions. One Indice buffer containing the indices of the vertices [0, 1, 2] (pay attention to the counter-clockwise rule, but it’s the same with glVertex3f method)
    When done, just call this function with specified buffers. Note you can use multiple sets of indices whith only one vertex buffer to render only some faces each time.

    void DrawBuffer(VertexBuffer vBuffer, IndexBuffer iBuffer)
    {
      // 1) Ensure that the VertexArray client state is enabled.
      GL.EnableClientState(ArrayCap.VertexArray);
      GL.EnableClientState(ArrayCap.NormalArray);
      GL.EnableClientState(ArrayCap.TextureCoordArray);
    
      // 2) Bind the vertex and element (=indices) buffer handles.
      GL.BindBuffer(BufferTarget.ArrayBuffer, vBuffer.Id);
      GL.BindBuffer(BufferTarget.ElementArrayBuffer, iBuffer.Id);
    
      // 3) Set up the data pointers (vertex, normal, color) according to your vertex format.
      GL.VertexPointer(3, VertexPointerType.Float, vBuffer.Stride, new System.IntPtr(0));
      GL.NormalPointer(NormalPointerType.Float, vBuffer.Stride, new System.IntPtr(Vector3.SizeInBytes));
      GL.TexCoordPointer(2, TexCoordPointerType.Float, vBuffer.Stride, new System.IntPtr(Vector3.SizeInBytes * 2));
      GL.ColorPointer(4, ColorPointerType.UnsignedByte, vBuffer.Stride, new System.IntPtr(Vector3.SizeInBytes * 3 + Vector2.SizeInBytes));
    
      // 4) Call DrawElements. (Note: the last parameter is an offset into the element buffer and will usually be IntPtr.Zero).
      GL.DrawElements(BeginMode.Triangles, iBuffer.Count, DrawElementsType.UnsignedInt, System.IntPtr.Zero);
    
      //Disable client state
      GL.DisableClientState(ArrayCap.VertexArray);
      GL.DisableClientState(ArrayCap.NormalArray);
      GL.DisableClientState(ArrayCap.TextureCoordArray);
    }
    

    I hope this can help 😉

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

Sidebar

Related Questions

When using powershell, sometimes I want to only display for example the name or
Take the example classes below. I want to display the customer and two addresses
Fundamentally, what I want to do is within, for example, ViewControllerA display ViewControllerB and
In Silverlight, I want to display progress of, for example, an uploading process as
Hy, I want to display a certain part (a div for example) of my
I want to display a number with commas and decimal point CASE1 : example
hi all i want to display database values in chart. for example a table
I want to display in a HTML page some datas with errors, for example:
I want to display multiple colors in progressbar. for example, Lets say there are
I want to display an Emoji icon using it's decimal value, for example &#xe41e

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.