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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:32:56+00:00 2026-05-27T10:32:56+00:00

I’m Pulling my hair out. I’ve been trying for 5 hours to get a

  • 0

I’m Pulling my hair out. I’ve been trying for 5 hours to get a freakin texture on this square can’t seem to make it happen. At this point i’ve butchered this code moving stuff around trying to get it to work, but here’s what I have…

It creates a spinning square, that spins a certain speed depending on coordinates touched.
That all works fine, but for the life of me I can’t get it to draw the texture. What do I need to change?

Here’s the entire Renderer class

public class VortexRenderer implements GLSurfaceView.Renderer {
    private static final String LOG_TAG = VortexRenderer.class.getSimpleName();

    private float _red = 0.9f;
    private float _green = 0.2f;
    private float _blue = 0.2f;
    public Bitmap bitmap;

    public VortexRenderer(Context context) {
        // TODO Auto-generated constructor stub
        bitmap = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.texturetest);

    }


    private FloatBuffer mTextureBuffer;
    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
        int[] textures = new int[1];
     // Tell OpenGL to generate textures.
        gl.glGenTextures(1, textures, 0);
        gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,
                GL10.GL_TEXTURE_MAG_FILTER,
                GL10.GL_LINEAR);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,
                GL10.GL_TEXTURE_MIN_FILTER,
                GL10.GL_LINEAR);
        float textureCoordinates[] = {0.0f, 1.0f,
                1.0f, 1.0f,
                0.0f, 0.0f,
                1.0f, 0.0f };
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,
                GL10.GL_TEXTURE_WRAP_S,
                GL10.GL_REPEAT);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D,
                GL10.GL_TEXTURE_WRAP_T,
                GL10.GL_REPEAT);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

        ByteBuffer byteBuf = ByteBuffer.allocateDirect(textureCoordinates.length * 4);
        byteBuf.order(ByteOrder.nativeOrder());
        mTextureBuffer = byteBuf.asFloatBuffer();
        mTextureBuffer.put(textureCoordinates);
        mTextureBuffer.position(0);

            gl.glEnable(GL10.GL_TEXTURE_2D);
         // Tell OpenGL where our texture is located.
         gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
         // Tell OpenGL to enable the use of UV coordinates.
         gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
         // Telling OpenGL where our UV coordinates are.
         gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);

        initTriangle();

    }

    @Override
    public void onSurfaceChanged(GL10 gl, int w, int h) {
        gl.glViewport(0, 0, w, h);
    }

    @Override
    public void onDrawFrame(GL10 gl) {
         // define the color we want to be displayed as the "clipping wall"
        gl.glClearColor(_red, _green, _blue, 1.0f);

        // clear the color buffer to show the ClearColor we called above...
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);

        gl.glRotatef(_angle, 0f, 1f, 0f);
        // set the color of our element
        gl.glColor4f(0.5f, 0f, 0f, 0.5f);

        // define the vertices we want to draw
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);
        gl.glEnable(GL10.GL_TEXTURE_2D);
        // Enable the texture state
        gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

        // Point to our buffers
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);



        // finally draw the vertices
        gl.glDrawElements(GL10.GL_TRIANGLE_FAN, _nrOfVertices, GL10.GL_UNSIGNED_SHORT, _indexBuffer);




   }


    private float _angle;

    public void setAngle(float angle) {
        _angle = angle;
    }


    public void setColor(float r, float g, float b) {
        _red = r;
        _green = g;
        _blue = b;
    } 

     // new object variables we need
     // a raw buffer to hold indices
     private ShortBuffer _indexBuffer;

     // a raw buffer to hold the vertices
     private FloatBuffer _vertexBuffer;

     private short[] _indicesArray = {0, 1 ,2,3};
     private int _nrOfVertices = 4;



     private void initTriangle() {

         // float has 4 bytes
         ByteBuffer vbb = ByteBuffer.allocateDirect(_nrOfVertices * 4 * 4);
         vbb.order(ByteOrder.nativeOrder());
         _vertexBuffer = vbb.asFloatBuffer();

         // short has 2 bytes
         ByteBuffer ibb = ByteBuffer.allocateDirect(_nrOfVertices * 2);
         ibb.order(ByteOrder.nativeOrder());
         _indexBuffer = ibb.asShortBuffer();

         float[] coords = {
            -0.5f, -0.5f, 0f, // (x1, y1, z1)
             0.5f, -0.5f, 0f, // (x2, y2, z2)
             0.5f, 0.5f, 0f, // (x3, y3, z3)
             -0.5f, 0.5f, 0f
         };

         _vertexBuffer.put(coords);
         _indexBuffer.put(_indicesArray);

         _vertexBuffer.position(0);
         _indexBuffer.position(0);
     }
}

I know allot of stuff is put in weird places, I’ve literally spent hours just moving stuff around trying to make it work lol.

OpenGL ES sure better be worth this learning curve.

  • 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-27T10:32:57+00:00Added an answer on May 27, 2026 at 10:32 am

    Try calling

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);
    

    After you have set your texture parameters.
    Also, it is usually a good idea to make sure your texture dimensions are multiples of 2 (e.g. 32×32, 64×64, 128×128…) when working in openGL.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.