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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:50:21+00:00 2026-05-28T19:50:21+00:00

I am trying to display an image using OpenGL ES through android NDK.. What

  • 0

I am trying to display an image using OpenGL ES through android NDK.. What I am trying to do is just reading a binary file of RGB data of size 90×72. and trying to display that image on emulator.. But outpu image is this..enter image description here

while the real image is enter image description here

I don’t know where is the problem in my code… My JNI code is as follows..

#include "com_example_sample_GlBufferView.h"
#include <GLES/gl.h>
#include <GLES/glext.h>
#include <string.h>
#include <pthread.h>
#include <android/log.h>
#include <stdio.h>
#include <time.h>

#define TEXTURE_WIDTH  256
#define TEXTURE_HEIGHT 128
#define MY_SCREEN_WIDTH  90
#define MY_SCREEN_HEIGHT 72

#define SB_PIXELS_SIZE (sizeof(sb_data[0]) * MY_SCREEN_WIDTH * MY_SCREEN_HEIGHT*3)

static int s_w;
static int s_h;
static pthread_cond_t s_vsync_cond;
static pthread_mutex_t s_vsync_mutex;
static GLuint s_texture;

FILE *fp;

static unsigned char *sb_data=0;

static void render_bytes(unsigned char *pixels)
{
    int x, y;
        int idx=0;
         fp=fopen("/data/123","rb");
         if(fp!=NULL)
            {
                fread(pixels,1,19584,fp);
                fclose(fp);
            }

}
static void wait_vsync()
{
       pthread_mutex_lock(&s_vsync_mutex);
       pthread_cond_wait(&s_vsync_cond, &s_vsync_mutex);
       pthread_mutex_unlock(&s_vsync_mutex);
}

JNIEXPORT void JNICALL Java_com_example_sample_GlBufferView_native_1start(JNIEnv * env, jobject obj)
{
       /* init conditions */
       pthread_cond_init(&s_vsync_cond, NULL);
       pthread_mutex_init(&s_vsync_mutex, NULL);
       sb_data=(unsigned char *)malloc(SB_PIXELS_SIZE);
       int incr = 1;
       while (1) {

               /* game code goes here */
               wait_vsync();
       }
}
JNIEXPORT void JNICALL  Java_com_example_sample_GlBufferView_native_1gl_1resize(JNIEnv * env, jobject obj, jint w, jint h)
{
       glEnable(GL_TEXTURE_2D);
       glDisable(GL_BLEND);
       glGenTextures(1, &s_texture);
       glBindTexture(GL_TEXTURE_2D, s_texture);
       glTexParameterf(GL_TEXTURE_2D,
                       GL_TEXTURE_MIN_FILTER, GL_LINEAR);
       glTexParameterf(GL_TEXTURE_2D,
                       GL_TEXTURE_MAG_FILTER, GL_LINEAR);

       glShadeModel(GL_SMOOTH);
       glColor4x(0x10000, 0x10000, 0x10000, 0x10000);

       int rect[4] = {0, TEXTURE_HEIGHT, TEXTURE_WIDTH, -TEXTURE_HEIGHT};
       glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, rect);
       glTexImage2D(GL_TEXTURE_2D,             /* target */
                       0,                      /* level */
                       GL_RGB,                 /* internal format */
                       TEXTURE_WIDTH,          /* width */
                       TEXTURE_HEIGHT,         /* height */
                       0,                      /* border */
                       GL_RGB,                 /* format */
                       GL_UNSIGNED_BYTE,/* type */
                       NULL);                  /* pixels */
       /* store the actual width of the screen */
       s_w = w;
       s_h = h;
}
JNIEXPORT void JNICALL Java_com_example_sample_GlBufferView_native_1gl_1render(JNIEnv * env, jobject obj)
{
       memset(sb_data, 0, SB_PIXELS_SIZE);

       render_bytes(sb_data);
       glClear(GL_COLOR_BUFFER_BIT);

       glTexSubImage2D(GL_TEXTURE_2D,          /* target */
                            0,                      /* level */
                            0,                      /* xoffset */
                            0,                      /* yoffset */
                            MY_SCREEN_WIDTH,        /* width */
                            MY_SCREEN_HEIGHT,       /* height */
                            GL_RGB,                 /* format */
                            GL_UNSIGNED_BYTE, /* type */
                            sb_data);              /* pixels */
       glDrawTexiOES(0, 0, 0, s_w, s_h);
       /* tell the other thread to carry on */
       pthread_cond_signal(&s_vsync_cond);
}

Can anybody please tell me where is the problem in my code..

Thanks in advance

  • 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-28T19:50:21+00:00Added an answer on May 28, 2026 at 7:50 pm

    You are reading 19584 bytes, but your texture is 90*72*3 = 19440 bytes.
    Are your pixels tightly packed between lines? It seems that you two pixel padding for each line or the width is incorrect.

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

Sidebar

Related Questions

I am trying to display an image using ImageView in Android. The image data
I am trying to perform several image manipulations using OpenGL ES 2.0 and display
I'm trying to display an image file from a directory using a PHP echo
I'm trying to display an image using OpenCV. I have the following very basic
i am trying to display an image by using the < img > tag
I am trying to display an image (byte array) using purely JavaScript. How can
i am trying to display an image from net..and i am using ignition library
I'm trying to display an image using a PHP script. Basically so the php
I am trying to display an image from the /webroot/img/ folder using the following
I am writing an Android application where I need to display Image Captured through

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.