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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:08:57+00:00 2026-06-01T23:08:57+00:00

I’ve already used stb_image in some desktop (PC) projects and it worked fine, but

  • 0

I’ve already used stb_image in some desktop (PC) projects and it worked fine, but now I’m trying to use it to load some tags to use them with OpenGL ES and I can’t.
This is the code I use:

void TextureManager::LoadFontTexture(const char *filename,int rows,int columns)
{
    glGenTextures(1,&textures[texNum]);
    texNum++;
    glBindTexture(GL_TEXTURE_2D,textures[texNum-1]);
    int x,y,n;
    GLenum format;
    unsigned char *data=stbi_load(filename,&x,&y,&n,0);
    if (data==NULL)
    {
        NSLog(@"Data loaded incorrectly");
        NSLog(@"Failure reason:%s",stbi_failure_reason());
    }
    else {
        NSLog(@"Width:%d height:%d",x,y);
    }
    if (n==3)
    {
        format=GL_RGB;
    }
    else if (n==4)
    {
        format=GL_RGBA;
    }  
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D,0,n,x,y,0,format,GL_UNSIGNED_BYTE,data);
}

This code worked fine on desktop, but when I try to texturize something with this image I get a black square. The width and height values are correct and always the (n==4) if is called (the image has an alpha channel, so this is correct). I don’t know what is wrong. I’ve also tried changing the format=GL_RGBA with format=GL_BGRA but it doesn’t work

  • 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-01T23:08:58+00:00Added an answer on June 1, 2026 at 11:08 pm

    glTexImage2D call should look like this:

    glTexImage2D(GL_TEXTURE_2D,0,format,x,y,0,format,GL_UNSIGNED_BYTE,data);
    

    3 or 4 are not valid values for internalformat in OpenGL ES. See the documentation here: http://www.khronos.org/opengles/sdk/docs/man/xhtml/glTexImage2D.xml

    EDIT: here’s more info how to dectect OpenGL errors:

    To detect this type of errors use the glGetError function. It will tell which function failed.
    For example – create following macro:

    #define GL_CHECK(x) do {
        x;
        GLenum glerr = glGetError();
        if (glerr != GL_NO_ERROR) {
            NSLog(@"OpenGL error: %d, file: %s, line: %d", glerr, __FILE__, __LINE__);
        }
    } while (0)
    

    Then use it around every OpenGL function like this:

    GL_CHECK( glTexImage2D(GL_TEXTURE_2D,0,n,x,y,0,format,GL_UNSIGNED_BYTE,data) );
    

    This immediately will let you know where is the error, including file name and line number.
    Of course, disable checking in release mode, when you will ship application. Just use different macro:

    #define GL_CHECK(x) x;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

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.