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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:04:51+00:00 2026-05-27T22:04:51+00:00

I am writing an open-source game engine for Android ( here ), and I

  • 0

I am writing an open-source game engine for Android (here), and I am having a bit of trouble rendering textured triangles. OpenGL doesn’t report any errors, but nothing renders. I can render vertex-colored triangles just fine, so I know my VBO- and shader-loading functions work. I have a feeling that I’m just missing some little detail. Here’s the relevant code:

// loaded is a boolean field 
if(!loaded ){
    int[] tex = { 0 };
    GLES20.glGenTextures(1, tex, 0);
    int handle = tex[0];

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, handle);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
            GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
            GLES20.GL_CLAMP_TO_EDGE);
    if (useMipmaps) {
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER,
                GLES20.GL_LINEAR_MIPMAP_NEAREST);
    } else {
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
                GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    }
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
            GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);

    // bmp is an android.graphics.Bitmap object
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bmp, 0);
    if (useMipmaps)
        GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    loaded = true;
}

GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + glTexture);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, handle);
GLES20.glUniform1i(GLES20.glGetUniformLocation(programHandle,
                "s_baseMap"), glTexture);

GLES20.glDrawElements(GLES20.GL_TRIANGLES,
                    indexCount, GLES20.GL_UNSIGNED_SHORT, 0);

The vertex shader:

precision mediump float;

uniform mat4 u_viewProj;
uniform vec3 u_lightColor;

attribute mat4 a_model;
attribute vec4 a_pos;
attribute vec2 a_mtl; // Stores UV coords

varying vec2 v_tc;

void main() {
    gl_Position = (u_viewProj * a_model) * a_pos;
    v_tc = a_mtl;
}

And the fragment shader:

precision mediump float;

varying vec2 v_tc;

uniform sampler2D s_baseMap;

void main() {
    vec4 black = vec4(0.0, 0.0, 0.0, 1.0);
    gl_FragColor = black + texture2D(s_baseMap, v_tc);
}
  • 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-27T22:04:52+00:00Added an answer on May 27, 2026 at 10:04 pm

    I solved it. The problem was not in the texturing or frag shader at all. It was in the way the model matrix attribute was loaded to the vertex shader. My matrix loading code was this:

    GLES20.glDisableVertexAttribArray(a_model);
    GLES20.glVertexAttrib4fv(a_model, matrix, matrixOffset * 16);
    GLES20.glVertexAttrib4fv(a_model, matrix, (matrixOffset * 16) + 4);
    GLES20.glVertexAttrib4fv(a_model, matrix, (matrixOffset * 16) + 8);
    GLES20.glVertexAttrib4fv(a_model, matrix, (matrixOffset * 16) + 12);
    

    Yup, this was part of the “unnecessary” code that I removed in my second edit. *facepalm*

    Turns out, a_model is the location of the first row of the model matrix. Because I was only loading data to the first row, the last three rows of the matrix were empty, so the vertex positions were messed up and the triangles were made degenerate. I fixed this by adding 1 to a_model for each successive row, like so:

    GLES20.glDisableVertexAttribArray(a_model);
    GLES20.glDisableVertexAttribArray(a_model + 1);
    GLES20.glDisableVertexAttribArray(a_model + 2);
    GLES20.glDisableVertexAttribArray(a_model + 3);
    GLES20.glVertexAttrib4fv(a_model, matrix, matrixIndex * 16);
    GLES20.glVertexAttrib4fv(a_model + 1, matrix, (matrixIndex * 16) + 4);
    GLES20.glVertexAttrib4fv(a_model + 2, matrix, (matrixIndex * 16) + 8);
    GLES20.glVertexAttrib4fv(a_model + 3, matrix, (matrixIndex * 16) + 12);
    

    Now it works perfectly!

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

Sidebar

Related Questions

im writing first open source Backbone.js app. The repository is here https://github.com/defrag/Backbone-Invoices Im having
I'm using Löve2D for writing a small game. Löve2D is an open source game
I am writing an application that uses OpenNETCF.IO.Serial (open source, see serial code here
I'm writing a JavaScript for an open source browser available for Android to replace
I am currently writing an open source wrapper for a COM object. I have
I'm writing a Python open-source app. My app uses some open source Python libraries.
For an open source project I have I am writing an abstraction layer on
I am tasked with writing an authentication component for an open source JAVA app.
May be some body already used some open source component, writing on jquery. And
I'm writing an open source application uses some Symfony components, and using Symfony Console

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.