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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:01:46+00:00 2026-05-21T03:01:46+00:00

The reason I’m asking this is that our app (The Elements) runs fine on

  • 0

The reason I’m asking this is that our app (The Elements) runs fine on a Droid and a Nexus One, our two test phones, but not correctly on our recently acquired Atrix 4G. What draws is a skewed version of what should draw, with all the colors being replaced with alternating lines of cyan, magenta, and yellow (approximately), which leads us to believe that one of the primary colors for the sand particles that should show up is missing based on which line it’s on. I’m sorry for the unclear description, we had images but since this account doesn’t have 10 reputation we couldn’t post them.

Here is the code of our gl.c file, which does the texturing and rendering:

/*
 * gl.c
 * --------------------------
 * Defines the gl rendering and initialization
 * functions appInit, appDeinit, and appRender.
 */

#include "gl.h"
#include <android/log.h>

unsigned int textureID;

float vertices[] =
{0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f};
float texture[] =
{0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f};
unsigned char indices[] =
{0, 1, 3, 0, 3, 2};
int texWidth = 1, texHeight = 1;


void glInit()
{
    //Set some properties
    glShadeModel(GL_FLAT);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);

    //Generate the new texture
    glGenTextures(1, &textureID);
    //Bind the texture
    glBindTexture(GL_TEXTURE_2D, textureID);

    //Enable 2D texturing
    glEnable(GL_TEXTURE_2D);
    //Disable depth testing
    glDisable(GL_DEPTH_TEST);

    //Enable the vertex and coord arrays
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);


    //Set tex params
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    //Set up texWidth and texHeight texHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, emptyPixels);
    //Free the dummy array
    free(emptyPixels);

    //Set the pointers
    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, texture);
}

void glRender()
{
    //Check for changes in screen dimensions or work dimensions and handle them
    if(dimensionsChanged)
    {
        vertices[2] = (float) screenWidth;
        vertices[5] = (float) screenHeight;
        vertices[6] = (float) screenWidth;
        vertices[7] = (float) screenHeight;

        texture[2] = (float) workWidth/texWidth;
        texture[5] = (float) workHeight/texHeight;
        texture[6] = (float) workWidth/texWidth;
        texture[7] = (float) workHeight/texHeight;

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        if (!flipped)
        {
            glOrthof(0, screenWidth, screenHeight, 0, -1, 1); //--Device
        }
        else
        {
            glOrthof(0, screenWidth, 0, -screenHeight, -1, 1); //--Emulator
        }

        dimensionsChanged = FALSE;
        zoomChanged = FALSE;
    }
    else if(zoomChanged)
    {
        texture[2] = (float) workWidth/texWidth;
        texture[5] = (float) workHeight/texHeight;
        texture[6] = (float) workWidth/texWidth;
        texture[7] = (float) workHeight/texHeight;

        zoomChanged = FALSE;
    }
    //__android_log_write(ANDROID_LOG_INFO, "TheElements", "updateview begin");
    UpdateView();
    //__android_log_write(ANDROID_LOG_INFO, "TheElements", "updateview end");

    //Clear the screen
    glClear(GL_COLOR_BUFFER_BIT);

    //Sub the work portion of the tex
    glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, workWidth, workHeight, GL_RGB, GL_UNSIGNED_BYTE, colors);

    //Actually draw the rectangle with the text on it
    glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, indices);
}

Any ideas as to what the difference is between the Atrix 4G and other phones in terms of OpenGL or why our app is doing what it is in general are much appreciated! Thanks in advance.

Here is an example of what it looks like: https://i.stack.imgur.com/noX4z.jpg

  • 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-21T03:01:47+00:00Added an answer on May 21, 2026 at 3:01 am

    I know it’s a bit late to reply, but the real reason you’re seeing the mixed colors is due to OpenGL’s scanline packing alignment — not due to any driver bug or power-of-two sized texture issue.

    Your glTexSubImage2D call is sending data in GL_RGB format, so I’m guessing your colors buffer is 3 bytes per pixel. Odds are the Droid and Nexus One phones have a default pack alignment of 1, but the Tegra 2 defaults to an alignment of 4. This means your 3 byte array can become misaligned with what the driver expects after every scanline, and a byte or two will be skipped for the next scanline, resulting in the colors you see. The reason why this works with a power-of-two sized texture is because your buffer just happens to be aligned properly for the next scanline. Basically this is the same issue as loading BMPs, where each scanline has to be padded to 4 bytes, regardless of the bit depth of the image.

    You can explicitly disable any alignment packing by calling glPixelStorei(GL_PACK_ALIGNMENT, 1);. Note that changing this only affects the way OpenGL interprets your texture data, so there is no rendering performance penalty for changing this value. When the texture is sent to the graphics subsystem, the scanlines are stored in whatever format is optimal for the hardware, but the driver still has to know how to unpack your data properly. However, since you are changing the texture data every frame, instead of the driver being able to do one memcpy() to upload the entire texture, it will have to do TextureHeight *memcpy()s in order to upload it. This is not likely to be a major bottleneck, but if you are looking for the best performance, you may want to query the driver’s default pack alignment on startup using glGetIntegerv(GL_PACK_ALIGNMENT, &align); and adjust your buffer accordingly at runtime.

    Here’s the specification on glPixelStore() for reference.

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

Sidebar

Related Questions

The reason I am asking this is due to my observation that frameworks like
The reason I'm asking is that I want to test something, that I expect
The reason for me asking this question is:- I get a real buzz out
For whatever reason, our company has a coding guideline that states: Each class shall
One reason we currently use UpdatePanels for doing our AJAX is because our BL
The reason why I am asking this is because I was recommended by @Greg
The reason why I'm asking this, is because I'm coding in C++, in putty/ssh
The reason I am asking this, is because extending the Similarity class or using
The reason I ask is that Stack Overflow has been Slashdotted , and Redditted
For some reason I never see this done. Is there a reason why not?

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.