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

  • Home
  • SEARCH
  • 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 6688825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:26:53+00:00 2026-05-26T05:26:53+00:00

How do you apply textures to a vertex buffer object in Android? ANSWER: The

  • 0

How do you apply textures to a vertex buffer object in Android?

ANSWER:


The code works fine, except it is missing a call to

glEnable(GL_TEXTURE_2D);

This and the call of

glEnableClientState(GL_TEXTURE_COORD_ARRAY);

are both required for in order for vertex buffer object to draw texture.


QUESTION:

From what I know, first you must create a NIO Buffer:

ByteBuffer tbb = ByteBuffer.allocateDirect(texCoords.length * 4);
tbb.order(ByteOrder.nativeOrder());
FloatBuffer textureBuffer = tbb.asFloatBuffer();
textureBuffer.put(texCoords);
textureBuffer.position(0);

In this code sample, the array texCoords contains the 2-component (s, t) texture data.

After creating the NIO Buffer, you need to pass it to opengl and create Vertex Buffer Object:

int[] id = new int[1];//stores the generated ID.
gl11.glGenBuffers(1, id, 0);
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, id[0]);
gl11.glBufferData(GL11.GL_ARRAY_BUFFER, texCoords.length * 4, textureBuffer, GL11.GL_STATIC_DRAW);

So that takes care of all the initalization. Next we need to draw it, and we do so like this:

gl11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);//enable for textures
gl11.glActiveTexture(GL11.GL_TEXTURE0);
//lets pretend we created our texture elsewheres and we have an ID to represent it.
gl11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);

//Now we bind the VBO and point to the buffer.
gl11.glBindBuffer(GL11.GL_ARRAY_BUFFER, id[0])//the id generated earlier.
gl11.glTexCoordPointer(2, GL11.GL_FLOAT, 0, 0);//this points to the bound buffer

//Lets also pretend we have our Vertex and Index buffers specified.
//and they are bound/drawn correctly.

So even though this is what I would think would be needed in order for OpenGL to draw the texture, I have an error, and only a red triangle (without my modulated stone texture) renders.

  • 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-26T05:26:54+00:00Added an answer on May 26, 2026 at 5:26 am

    Both functions for VBO’s need to be called to enable textures.

    gl.glEnable(GL11.GL_TEXTURE_2D);
    gl.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY);

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

Sidebar

Related Questions

How do I apply the MarshalAsAttribute to the return type of the code below?
I'm trying to apply a transform to a 3D object in a STL File
i found some examples how to apply texture on 2d object but nothing on
I cannot apply a texture to an object, I don't know why... ( AS3
I'm trying to apply texture to a sprite using opengl as follows: int[] textures=new
How do I apply a repeating texture that always maintains its original scale (1
I want to apply an XSLT Stylesheet to an XML Document using C# and
This question would probably apply equally as well to other languages with C-like multi-line
I am trying to apply styles to HTML tags dynamically by reading in the
How do I apply 'use base' in Perl to inherit subs from some base

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.