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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:40:45+00:00 2026-05-28T02:40:45+00:00

I am loading bitmap file and creating texture this way: LoadBitmapFromFile( img.bmp, &bitmapFile );

  • 0

I am loading bitmap file and creating texture this way:

LoadBitmapFromFile( "img.bmp", &bitmapFile );

glGenTextures(1, &texture[0] );
glBindTexture(GL_TEXTURE_2D, texture[0] );


glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmapFile.width, bitmapFile.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapFile.data);


glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                 GL_LINEAR_MIPMAP_NEAREST );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

Later on, I try to texture triangles:

glEnable( GL_TEXTURE_2D );
        glPushMatrix();
            glBindTexture( GL_TEXTURE_2D, texture[0] );
            glBegin( GL_TRIANGLE_STRIP );
                glTexCoord2f( 0, 0 ); glVertex2f( 0, 768 );
                glTexCoord2f( 1, 0 ); glVertex2f( 1024, 768 );
                glTexCoord2f( 1, 1 ); glVertex2f( 0, 0 );
                glTexCoord2f( 0, 1 ); glVertex2f( 1024, 0 );
            glEnd();
        glPopMatrix();
    glDisable( GL_TEXTURE_2D );

But texture doesn’t show on screen, other coloured primitives do.

It does work with glDrawPixel, but doesn’t texture triangles, what could be wrong?

I have simplified my app just to show the problem:
(also had to include glext, as it didn’t found GL_CLAMP_TO_EDGE)

#include <GL/glfw.h>
#include <fstream>
#include <cstdlib>
#include "glext.h"

typedef struct BitmapFile
{
    int width, height;
    unsigned char* data;
};

BitmapFile bitmapFile;

GLuint texture[1];

void LoadBitmapFromFile( char *filename, BitmapFile *bitmap )
{
    int bitmapSize = 0;
    int i = 0;

    FILE *file;

    file = fopen( filename, "rb" );
    if( !file )
    {
        fclose(file);
        return;
    }

    fseek(file, 18, SEEK_SET);
    fread(&bitmap->width, 4, 1, file);

    fseek(file, 22, SEEK_SET);
    fread(&bitmap->height, 4, 1, file);

    fseek(file, 34, SEEK_SET);
    fread(&bitmapSize, 4, 1, file);

    bitmap->data = (unsigned char*)malloc(bitmapSize);
    fseek(file, 54, SEEK_SET);
    fread(bitmap->data, bitmapSize, 1, file);

    for( i = 0; i < bitmapSize; i+=3 )
    {
        int tempByte = bitmap->data[i];
        bitmap->data[i] = bitmap->data[i+2];
        bitmap->data[i+2] = tempByte;
    }

    fclose(file);
}

int LoadGLTextures()                                  
{
    LoadBitmapFromFile( "img.bmp", &bitmapFile );

    glGenTextures(1, &texture[0] );
    glBindTexture(GL_TEXTURE_2D, texture[0] );


    glTexImage2D(GL_TEXTURE_2D, 0, 3, bitmapFile.width, bitmapFile.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapFile.data);


    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

    /*glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                     GL_LINEAR_MIPMAP_NEAREST );

    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );*/
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);


    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE ); 
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

    return true;
}

int main()
{
    glfwInit();

    glEnable( GL_TEXTURE_2D );
    glShadeModel( GL_SMOOTH );

    LoadGLTextures();

    glfwOpenWindowHint( GLFW_WINDOW_NO_RESIZE, GL_TRUE );
    glfwOpenWindow( 1024, 768, 0, 0, 255, 0, 32, 0, GLFW_WINDOW );


    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1024, 768, 0, -1.0, 1.0); 
    glMatrixMode( GL_MODELVIEW );

    while( !glfwGetKey( GLFW_KEY_ESC ) )
    {
        glClearColor(0.0, 1.0, 1.0, 0.0);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glBindTexture( GL_TEXTURE_2D, texture[0] );
        glPushMatrix();

            glBegin( GL_TRIANGLE_STRIP );
                glTexCoord2f( 0, 0 ); glVertex2f( 0, 768 );
                glTexCoord2f( 1, 0 ); glVertex2f( 1024, 768 );
                glTexCoord2f( 1, 1 ); glVertex2f( 0, 0 );
                glTexCoord2f( 0, 1 ); glVertex2f( 1024, 0 );
            glEnd();
        glPopMatrix();

        glDrawPixels( bitmapFile.width, bitmapFile.height, GL_RGB, GL_UNSIGNED_BYTE, bitmapFile.data);

        glfwSwapBuffers();
        glFlush();
    }

    glfwTerminate();
}

http://imageshack.us/photo/my-images/254/89567090.jpg/


Ok, I’m powerless, after last changes loading function looks like that:

int LoadGLTextures()                                  
{
    LoadBitmapFromFile( "img.bmp", &bitmapFile );

    glGenTextures(1, &texture[0] );
    glBindTexture(GL_TEXTURE_2D, texture[0] );

    //glGenerateMipmap(GL_TEXTURE_2D);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmapFile.width, bitmapFile.height, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapFile.data);

    for( int i = 0 ; i < 8 ; i++ )
    {
        glTexImage2D(GL_TEXTURE_2D, i+1, GL_RGB, bitmapFile.width/(2*(i+1)), bitmapFile.height/(2*(i+1)), 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapFile.data);
    }

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    return true;
}

But on screen there are still no changes.
( bitmap is 256×256 )

  • 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-28T02:40:46+00:00Added an answer on May 28, 2026 at 2:40 am

    You’re loading only one level but enable mipmaping by calling

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    

    If loading only one level you must disable mipmaping with

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    

    or

    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    

    Update due to having seen the code:

    The OP tried to load textures before a OpenGL context was available.

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

Sidebar

Related Questions

Consider this code for loading, modifying and saving a Bitmap image: using (Bitmap bmp
I was loading a Bitmap Image from a File. When I tried to save
Try loading this normal .jpg file in Internet Explorer 6.0. I get an error
How to flip a Bitmap upside down? (I need this for loading an OpenGL
Simply what it says on the tin I'm loading a bitmap from a file
When loading a page for the first time (!IsPostback), I am creating a button
After loading a PHP template (using jQuery's load function), this simple script won't make
I'm displaying a bitmap using GDI+. After loading the bitmap from a DLL resource
I have a large bitmap (say 3888x2592) in a file. Now, I want to
Saving the file: FileOutputStream fo = null; try { fo = this.openFileOutput(test.png, Context.MODE_WORLD_READABLE); }

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.