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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:30:14+00:00 2026-05-20T00:30:14+00:00

I writing an application that draws in openGL es 1.0 in the Android NDK

  • 0

I writing an application that draws in openGL es 1.0 in the Android NDK and renders it on an android phone. So far, I can draw two lines. The problem is that those two lines are rainbow. I was trying to debug where coordinates are on screen (where 0,0 and 1,1 are) so I added color to the two lines I am drawing. One should be drawn in red, the other in green. The code I use to draw them is as follows:

void appInit()
{
    glEnable(GL_CULL_FACE);
}

void appRender(jint width, jint height)
{
    prepareFrame(width, height);

    drawLines();
}

void drawLines()
{
    glLoadIdentity();

    glPushMatrix();
    GLfloat color1[] = {0.0f,1.0f,0.0f,1.0f};
    drawLine( 1.0f,1.0f,2.0f,2.0f,color1);
    glPopMatrix();

    glPushMatrix();
    GLfloat color2[] = {1.0f,0.0f,0.0f,1.0f};
    drawLine(0.0f,0.0f,1.0f,1.0f, color2);
    glPopMatrix();
}

void drawLine(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2, GLfloat * color)
{
    GLfloat vVertices[] =
    {x1, y1,
    x2, y2};

    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);

    //glColor4f(color[0],color[1],color[2],color[3]);
    glColorPointer(4,GL_FLOAT,0,color);
    glVertexPointer(2, GL_FLOAT, 0, vVertices);
    glDrawArrays(GL_LINES, 0, 4);

    glDisableClientState(GL_COLOR_ARRAY);
    glDisableClientState(GL_VERTEX_ARRAY);
}

void prepareFrame(int width, int height)
{
    glViewport(0, 0, width, height);

    glClearColor(0.0,0.0,0.0,0.0);

    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    glLoadIdentity();
}

appInit is called, then appRender is called over and over again with the screen dimensions. The result is this:

https://i.stack.imgur.com/G91oX.png

If anyone knows why they are drawing rainbows instead of the colors I specified, that would be wonderful. Bonus points if you can tell me what the coordinate system is like by default on android (no gluperspective or lookat is used).

  • 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-20T00:30:14+00:00Added an answer on May 20, 2026 at 12:30 am

    Try creating a color array that has a color for each vertex. Right now I think you’re reading off the end of the array into uninitialized memory when you try to render two vertexes, since you don’t specify the color for the second vertex.

    Also, I think the third argument for your glDrawArrays() call should be 2, not 4, since you’re only rendering two vertexes.

    I’m somewhat surprised it didn’t crash with an access violation of some sort, honestly 🙂

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

Sidebar

Related Questions

I'm writing an android application that draws directly to the canvas on the onDraw
I am writing an application that will allow an android phone and java application
I am writing an Android application that does much of a processing in the
I am writing a application that needs to draw a route comprised of lots
I'm writing an application that is looking to draw basic polygons and ellipses on
I'm writing an application (on android) that uses both java code, and native code.
I'm writing a mac application that draws some of its UI on NSOpenGLView using
I'm writing an application that draws certain shapes. Before each shape is drawn, some
Im writing an application that have 1000 objects and around 10 million lines of
Im writing an application that supposed to send coordinates in an SMS, but I've

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.