quote:Original post by Subotron
I believe the LUMINANCE is for 8 bits... (black & white)
So I guess that''s the problem indeed
No, I changed the GL_TexImage_2D line from
glTexImage2D (GL_TEXTURE_2D, 0, GL_INTENSITY, BITMAP_COLS, BITMAP_ROWS, 0, GL_LUMINANCE, GL_BITMAP, BITMAP_DATA);
to
glTexImage2D (GL_TEXTURE_2D, 0, GL_INTENSITY, BITMAP_COLS, BITMAP_ROWS, 0, GL_BITMAP, GL_UNSIGNED_BYTE, BITMAP_DATA);
but end up with the same, blank quad.
Here is a complete listing of the code. Perhaps the problem lies somewhere else (for example, maybe I''m forgetting to initialize something).
#include <stdio.h>#ifdef WIN32# include <windows.h>#endif#include <GL/gl.h>#include <SDL/SDL.h>#if 0const unsigned char BITMAP_DATA [] = { 0x41, 0x00, 0x41, 0x00, 0x42, 0x00, 0x22, 0x00, 0x22, 0x00, 0x14, 0x00, 0x14, 0x00, 0x1C, 0x00, 0x0C, 0x00, 0x08, 0x00, 0x08, 0x00, 0x30, 0x00,};#endif//#if 0const unsigned char BITMAP_DATA [] = { 0x41, 0x41, 0x42, 0x22, 0x22, 0x14, 0x14, 0x1C, 0x0C, 0x08, 0x08, 0x30};//#endifconst int BITMAP_PITCH = 1;const int BITMAP_ROWS = 12;const int BITMAP_COLS = 8;const int NUM_PIXELS = BITMAP_PITCH * 8 * BITMAP_ROWS;const int SCREEN_WIDTH = 900;const int SCREEN_HEIGHT = 750;int main () { // Init SDL SDL_Init (SDL_INIT_VIDEO); SDL_Surface *screen = SDL_SetVideoMode (SCREEN_WIDTH, SCREEN_HEIGHT, 32, SDL_OPENGL | SDL_HWSURFACE | SDL_DOUBLEBUF); if (screen == NULL){ return 0; } SDL_WM_SetCaption ("Test Bitmap OpenGL Texture Program", NULL); // Init OpenGL glViewport (0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); glMatrixMode (GL_PROJECTION); glLoadIdentity (); glOrtho (0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, -1, 1); glMatrixMode (GL_MODELVIEW); glClearColor (0.0, 0.0, 0.0, 0.0); glClearDepth (1.0); glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL); glPolygonMode (GL_FRONT, GL_FILL); glPolygonMode (GL_BACK, GL_LINE); glEnable (GL_TEXTURE_2D); // Create texture unsigned int texObj; glGenTextures (1, &texObj); if (texObj == 0){ fprintf (stderr, "Unable to create an OpenGL texture object\n"); SDL_Quit(); return 1; } glBindTexture (GL_TEXTURE_2D, texObj); glTexImage2D ( /*target*/ GL_TEXTURE_2D, /*level*/ 0, /*internalFormat*/ GL_INTENSITY, /*width*/ BITMAP_COLS, /*height*/ BITMAP_ROWS, /*border*/ 0, /*format*/ GL_BITMAP, /*type*/ GL_UNSIGNED_BYTE, /*texels*/ BITMAP_DATA ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Show a quad with the texture glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity (); glTranslatef (200.0f, 150.0f, 0.0f); //glBindTexture (GL_TEXTURE_2D, texObj); glBegin (GL_QUADS); glColor3f (1.0, 0.0, 0.0); glTexCoord2f (0.0, 1.0); glVertex3f ( 0.0f, 0.0f, 0.0f); glTexCoord2f (1.0, 1.0); glVertex3f (100.0f, 0.0f, 0.0f); glTexCoord2f (1.0, 0.0); glVertex3f (100.0f, 150.0f, 0.0f); glTexCoord2f (0.0, 0.0); glVertex3f ( 0.0f, 150.0f, 0.0f); glEnd (); SDL_GL_SwapBuffers (); SDL_Event event; bool done = false; while (!done){ SDL_PollEvent (&event); if (event.type == SDL_QUIT){ done = true; }else if (event.type == SDL_KEYUP){ if (event.key.keysym.sym == SDLK_ESCAPE) done = true; } } SDL_Quit (); glDeleteTextures (1, &texObj); return 0;}
It is a very simple program that uses SDL as the window manager. It starts, creates the texture, displays the texture, and waits for the user to exit the program. It should compile on Windows and Linux (although it has only been tested on Linux).
Here is a Makefile that will compile the above program (assuming you have SDL and OpenGL libs installed in the same place
):
CC=g++LIBS= -lSDL -L/usr/X11R6/lib -lGLopengl_test_program: main.o $(CC) $(LIBS) main.o -o opengl_test_program
Thank you for your help.