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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:20:02+00:00 2026-05-24T10:20:02+00:00

Here is the texture I am attempting to load: Here is what I am

  • 0

Here is the texture I am attempting to load:

enter image description here

Here is what I am seeing when I run my code:

enter image description here

Here is the code I am using:

#include "sdl.h"
#include "sdl_opengl.h"
#include <stdio.h>
#include <gl/GL.h>
#include <gl/GLU.h>

Uint32 loadTexture(char* fileName)
{
    Uint32 id;
    SDL_Surface *img = NULL;

    //load into memory using SDL
    img = SDL_LoadBMP(fileName);
    //generate an id for this texture
    glGenTextures(1, &id);
    //use this texture
    glBindTexture(GL_TEXTURE_2D, id);
    //load the texture into video memory via OpenGL
    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGB,
        img->w,
        img->h,
        0,
        GL_RGB,
        GL_UNSIGNED_SHORT_5_6_5,
        img->pixels
        );

    //set mip map settings
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    SDL_FreeSurface(img);

    return id;
}

Uint32 tex;

void init()
{
    glClearColor(0.0, 0.0, 0.0, 1.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1.0, 1.0, 0.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_TEXTURE_2D);

    tex = loadTexture("fireball.bmp");
}
void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    glLoadIdentity();

    glBindTexture(GL_TEXTURE_2D, tex);

    glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0);
    glVertex3f(0.25, 0.25, 0.0);


    glTexCoord2f(1.0, 0.0);
    glVertex3f(0.5, 0.25, 0.0);


    glTexCoord2f(1.0, 1.0);
    glVertex3f(0.5, 0.5, 0.0);


    glTexCoord2f(0.0, 1.0);
    glVertex3f(0.25, 0.5, 0.0);
    glEnd();
}

int main()
{
    INT32 isRunning = 1;
    SDL_Surface *screen = NULL;
    SDL_Event event;
    INT32 start;
    INT32 FPS = 30;

    SDL_Init(SDL_INIT_EVERYTHING);

    screen = SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);

    init();

    while(isRunning)
    {
        start = SDL_GetTicks();

        while(SDL_PollEvent(&event))
        {
            switch(event.type)
            {
                case SDL_QUIT: isRunning = 0; break;
            }
        }

        display();

        SDL_GL_SwapBuffers();

        if(1000 / FPS > SDL_GetTicks() - start)
        {
            SDL_Delay(1000 / FPS - (SDL_GetTicks() - start));
        }
    }

    SDL_Quit();

    return(0);
}
  • 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-24T10:20:02+00:00Added an answer on May 24, 2026 at 10:20 am
    glTexImage2D(
        GL_TEXTURE_2D,
        0,
        GL_RGB,
        img->w,
        img->h,
        0,
        GL_RGB,
        GL_UNSIGNED_SHORT_5_6_5,
        img->pixels
        );
    

    Is this actually the format it is in? Each 2 bytes is a 5/6/5 RGB pixel. I wasn’t aware that Windows BMP files could store 5/6/5 image data, but I never bothered to write image loading code, so I don’t know for certain. I thought BMP data could only be in 8/8/8 BGR format.

    Well, even if it can be 5/6/5, are you sure that this image is in that format?

    Also, what is the row alignment? I don’t see you setting GL_UNPACK_ALIGNMENT using glPixelStorei, so you must expect each row to be aligned to 4 bytes in size. Is this true?

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

Sidebar

Related Questions

Here's the code I use to load a texture. image is a CGImageRef. After
I'm attempting to render a textured quad using the example located here . I
I'm learning OpenGL ES. When I'm using texture for triangle, I meet error. Here
Here is my code. I'm attempting to draw a simple quadrilateral, and place a
I've been attempting to render text onto an openGL window using SDL and the
Here's what I have: I load a texture from disk, say 256x256, say a
Here is my code, which takes two version identifiers in the form 1, 5,
I am rendering a scene to a texture, then using that texture and its
I am trying to render to a texture using openGL ES (for iPhone) and
I am attempting to dynamically generate cube-maps in OpenGL using a multi-pass rendering system.

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.