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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:23:25+00:00 2026-06-09T03:23:25+00:00

OK so here is the code, it runs great, I just don’t see a

  • 0

OK so here is the code, it runs great, I just don’t see a texture. I see A White Square exactly the size I specified, just not the texture.

    public class MeshRect {

MyRect rect;
final int VERTEX_SIZE = (2 + 4 + 2) * 4;
FloatBuffer vertices;
ShortBuffer indices;
long MyID;

public MeshRect(MyRect rect, long ID) {
    super();
    this.rect = rect;
    MyID = ID;

    Assemble();

}

private void Assemble() {
    ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * VERTEX_SIZE);
    byteBuffer.order(ByteOrder.nativeOrder());
    vertices = byteBuffer.asFloatBuffer();

    float x1 = (float) rect.BottomLeftCorner.x;
    float x2 = (float) rect.BottomRightCorner.x;
    float x3 = (float) rect.TopRightCorner.x;
    float x4 = (float) rect.TopLeftCorner.x;

    float y1 = (float) rect.BottomLeftCorner.y;
    float y2 = (float) rect.BottomRightCorner.y;
    float y3 = (float) rect.TopRightCorner.y;
    float y4 = (float) rect.TopLeftCorner.y;

    vertices.put(new float[] { x1, y1, 1, 1, 1, 1, 0.0f, 1.0f,
                                x2, y2, 1, 1, 1, 1, 1.0f, 1.0f,
                                x3, y3, 1, 1, 1, 1, 1.0f, 0.0f,
                                x4, y4, 1, 1, 1, 1, 0.0f, 0.0f });
                            //  x   y   r  g  b  A   u|s  v|t
    vertices.flip();

    byteBuffer = ByteBuffer.allocateDirect(6 * 2);
    byteBuffer.order(ByteOrder.nativeOrder());
    indices = byteBuffer.asShortBuffer();
    indices.put(new short[] { 0, 1, 2,
                                2, 3, 0 });
    indices.flip();
}

public FloatBuffer getVertices() {
    return vertices;
}

public ShortBuffer getIndices() {
    return indices;
}


public long getMyID() {
    return MyID;
}

public void Draw(int primitiveType, GL10 gl) {
    int numVertices = 6;

    //set vertex array
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    vertices.position(0);
    gl.glVertexPointer(2, GL10.GL_FLOAT, VERTEX_SIZE, vertices);

    //set color
    gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    vertices.position(2);
    gl.glColorPointer(4, GL10.GL_FLOAT, VERTEX_SIZE, vertices);

    // set texture coords
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    vertices.position(6);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, VERTEX_SIZE, vertices);

    //set indices
    indices.position(0);
    gl.glDrawElements(primitiveType, numVertices, GL10.GL_UNSIGNED_SHORT, indices);

    //reset
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

}

}

and the render

    public void Render(GL10 gl, long deltaTime) {
    //render all
    Log.d("Game", "Render");

    gl.glViewport(0, 0, Screen.SCREEN_WIDTH, Screen.SCREEN_HEIGHT);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glOrthof(0, Screen.WIDTH_SCALE, 0, Screen.HEIGHT_SCALE, 1, -1);

    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);

    /**
     * so psuedo would look something like this
     * 
     * *.Update();
     * gl.glEnable(GL10.GL_TEXTURE_2D);
     * Textures.BindTexture(*.getCurrentTextureFileID);
     * MeshRects.draw((*.getMyRect) ,GL10.GL_TRIANGLES, gl);
     * 
     * update();
     * bind texture;
     * draw rect;
     */

    ball.Update(deltaTime);
    gl.glEnable(GL10.GL_TEXTURE_2D);
    texture.bind(gl);
    MeshRect mRect = new MeshRect(ball.getMyRect(), 1);
    mRect.Draw(GL10.GL_TRIANGLES, gl);

}

and the texture bind method

    public void bind(GL10 gl) {
    Log.d("Texture", "Bind");
    gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureID);
}

I cant help but think I am missing something. This is my first dive into the world of OPEN GL, and this all this I created today from reading and testing code from all over the internet. There was no easy set resource on how to, so I have been making my own 2D engine as I learn so that I can re-use it for a long time to come.

  • 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-09T03:23:26+00:00Added an answer on June 9, 2026 at 3:23 am

    I don’t see any texture setup code.

    Where is glTexImage2D? Also I don’t see calls to set up filtering etc.

    Here is a snippet that sets up texture (it’s in C, but you need something similar):

        GLubyte tex[] = {255, 0, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 255, 0, 0, 255};
        glActiveTexture(GL_TEXTURE0);
        glGenTextures(1, &texId);
        glBindTexture(GL_TEXTURE_2D, texId);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex);
        glBindTexture(GL_TEXTURE_2D, 0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is code from MSDN . I don't understand why the work isn't just
Got this code from here http://www.irunmywebsite.com/raphael/drawtool2.php . Runs great in IE when I tested
This is a follow-up question from here . The code is working great, it
The script is on jsfiddle here : CODE What it does at the moment
Ok the error is showing up somewhere in this here code if($error==false) { $query
Here is code my jqgrid editing through form. $(#DataEnergy).jqGrid('navGrid', '#pagergrid', {}, //options {editdata: {
Here my code, I need to insert into mysql database I have mysql,php,android 1)
Here a code to demonstrate an annoying problem: class A { public: A(): m_b(1),
here is code for regular expression matching #include<iostream> #include<stdio.h> #include<string.h> using namespace std; int
Here is code example class A{ int i; public: A(int i) : i(i) {}

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.