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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:29:47+00:00 2026-06-06T21:29:47+00:00

I am trying to build a little Open GL2.0 demo application on android but

  • 0

I am trying to build a little Open GL2.0 demo application on android but i am getting the following errors

in log cat

07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context     (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context         (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context     (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context (logged once per thread)
07-02 20:50:40.110: E/libEGL(1252): call to OpenGL ES API with no current context (logged once per thread)

in the Console

[2012-07-02 20:50:44 - Emulator]     development/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetAttribLoc    ation:826 error 0x501
[2012-07-02 20:50:44 - Emulator]     development/tools/emulator/opengl/host/libs/Translator/GLES_V2/GLESv2Imp.cpp:glGetUniformLocation:1383 error 0x501

my code

View

package limitliss.graphics.play;


import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.opengl.GLU;

public class OGLView extends GLSurfaceView implements Renderer {

private int mColorType = 0;

private float rotx = 0.0f;
private float roty = 0.0f;    
Triangle tri = new Triangle();

public OGLView(Context context) {
    super(context);
    setEGLContextClientVersion(2);

    this.setRenderer(this); 
    setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
    // TODO Auto-generated constructor stub
}



public static int loadShader(int type, String shaderCode){

    // create a vertex shader type (GLES20.GL_VERTEX_SHADER)
    // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
    int shader = GLES20.glCreateShader(type);

    // add the source code to the shader and compile it
    GLES20.glShaderSource(shader, shaderCode);
    GLES20.glCompileShader(shader);

    return shader;
}





public void onSurfaceCreated(GL10 unused, EGLConfig config) {
    // Set the background frame color
    GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    tri.draw();
}

public void onDrawFrame(GL10 unused) {
    // Redraw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    tri.draw();
}

public void onSurfaceChanged(GL10 unused, int width, int height) {
    GLES20.glViewport(0, 0, width, height);
}
}


Triangle

package limitliss.graphics.play;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLES20;



public class Triangle {

float color[] = { 0.63671875f, 0.76953125f, 0.22265625f, 1.0f };

private FloatBuffer vertexBuffer;
int mProgram;
int mPositionHandle;
private final String vertexShaderCode =
        "attribute vec4 vPosition;" +
        "void main() {" +
        "  gl_Position = vPosition;" +
        "}";

    private final String fragmentShaderCode =
        "precision mediump float;" +
        "uniform vec4 vColor;" +
        "void main() {" +
        "  gl_FragColor = vColor;" +
        "}";
// number of coordinates per vertex in this array
static final int COORDS_PER_VERTEX = 3;
static float triangleCoords[] = { // in counterclockwise order:
     0.0f,  0.622008459f, 0.0f,   // top
    -0.5f, -0.311004243f, 0.0f,   // bottom left
     0.5f, -0.311004243f, 0.0f};   // bottom right

public Triangle() {
    // initialize vertex byte buffer for shape coordinates
    ByteBuffer bb = ByteBuffer.allocateDirect(
            // (number of coordinate values * 4 bytes per float)
            triangleCoords.length * 4);
    // use the device hardware's native byte order
    bb.order(ByteOrder.nativeOrder());

    // create a floating point buffer from the ByteBuffer
    vertexBuffer = bb.asFloatBuffer();
    // add the coordinates to the FloatBuffer
    vertexBuffer.put(triangleCoords);
    // set the buffer to read the first coordinate
    vertexBuffer.position(0);

    int vertexShader =  OGLView.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
    int fragmentShader =  OGLView.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);

    mProgram = GLES20.glCreateProgram();             // create empty OpenGL ES Program
    GLES20.glAttachShader(mProgram, vertexShader);   // add the vertex shader to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
    GLES20.glLinkProgram(mProgram);    
}

public void draw() {

    // Add program to OpenGL ES environment
    GLES20.glUseProgram(mProgram);

    // get handle to vertex shader's vPosition member
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");

    // Enable a handle to the triangle vertices
    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Prepare the triangle coordinate data
    GLES20.glVertexAttribPointer(mPositionHandle, COORDS_PER_VERTEX,
                                 GLES20.GL_FLOAT, false,
                                 COORDS_PER_VERTEX, vertexBuffer);

    // get handle to fragment shader's vColor member
    int mColorHandle = GLES20.glGetUniformLocation(mProgram, "vColor");

    // Set color for drawing the triangle
    GLES20.glUniform4fv(mColorHandle, 1, color, 0);

    // Draw the triangle
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 3);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
}

public void render(GL10 gl){

    gl.glPushMatrix();
    gl.glColor4f(this.color[0],this.color[1],this.color[2],this.color[3]); 
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, 3);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glPopMatrix();
}
}
  • 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-06T21:29:48+00:00Added an answer on June 6, 2026 at 9:29 pm

    You’re getting call to OpenGL ES API with no current context errors because you’re creating your triangle Triangle tri = new Triangle(); outside of the OpenGL thread (and the triangle constructor is making opengl calls). Only the code inside the OpenGL callbacks (onSurfaceCreated, onDrawFrame, etc) are executed on the opengl thread.

    Put tri = new Triangle() inside of onSurfaceCreated and those errors should go away.

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

Sidebar

Related Questions

I'm trying to build my little app for cydia submission ... but I can't
Maybe my question it's a little weird, but I'm trying to build a not-so-simple
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I am trying to build a local database for android. I am a little
I'm trying to build a little bit advanced users system using Joomla, but I
I was trying to build a native android application. When I tried to run
I am trying to build a little search script, but can't seem to stop
I'm trying to build an application in Android using some codes from Objective-C (IPhone
I'm trying to build a little Google Pagespeed client in Node, but I'm struggling
I'm trying to build a little renaming program to help save me time in

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.