PDA

View Full Version : open gl texturing question



02-11-2004, 11:34 AM
what does it mean if the object on to which I attatch a texture is white instead of showing the texture? has the texture not loaded correctly or is a matter of how I've drawn it on an object? (I have been drawing the texture on an object of the same size) . The texture is of resolution 270x390 and I want to use a unit of the opengl coordinate system to represent a pixel.(ie the coordinates of the object would range from -270/2,390/2 (TOP LEFT) to 270/2,-390/2 (BOTTOM RIGHT)) am I right to draw the object with such large coordinates as I dont seem to be able to draw it far enough into the screen to be able to see it all? I use glTranslatef(0,0,-100) and its still too large to see all of the object, but any value smaller than -100 (even -100.1) and the object disappears completely?

mithun_daa
02-11-2004, 11:36 AM
Originally posted by Mr.JT:
what does it mean if the object on to which I attatch a texture is white instead of showing the texture? has the texture not loaded correctly or is a matter of how I've drawn it on an object? (I have been drawing the texture on an object of the same size) . The texture is of resolution 270x390 and I want to use a unit of the opengl coordinate system to represent a pixel.(ie the coordinates of the object would range from -270/2,390/2 (TOP LEFT) to 270/2,-390/2 (BOTTOM RIGHT)) am I right to draw the object with such large coordinates as I dont seem to be able to draw it far enough into the screen to be able to see it all? I use glTranslatef(0,0,-100) and its still too large to see all of the object, but any value smaller than -100 (even -100.1) and the object disappears completely?


texture size needs to be a power of 2. read the red book.

02-11-2004, 11:47 AM
yes but I have heard there are ways round it eg. only texturing a part of an object thats size is a power of two?

roffe
02-11-2004, 12:00 PM
You can generate a texture object with power of two size by "filling out" part of the texture to make it a power of two texture. When rendering you have to adjust your texture coordinates.

You can also use GL_NV_texture_rectangle or GL_ARB_texture_non_power_of_two.

02-11-2004, 12:34 PM
ok thanks. currently using a power of two texture now just to try and get it working, but the square that the texture should be displayed in is still white. Is this a specific problem caused by the texture not loading correctly, or a problem displaying the texture?

SuperFreq
02-11-2004, 12:52 PM
If the object is disappearing completely if you translate back further than -100 you should adjust your far clipping plane to accomidate the size.

Some code would help people understand what you are trying to do.

02-11-2004, 01:47 PM
bitmap loaded into resource file as in NeHe tutorial lesson 38. The code below is the relevant C++ class that is using OPENGL. From the main function (not included below) the function drawBackground() is called as the glut display (and also idle) function. Bitmap is 256x256. For non C++ people the constructor (ie Graphics::Graphics() is called once at the start of the program to inialise things. Im very new to opengl and glut so have mainly pulled bits a pieces from tutorials etc and therefore struggle when my adaptions havent worked! Hope it makes sense!

#include <gl\glut.h>
#include "resource.h"

class Graphics{
private:
struct object // Create A Structure Called Object
{
int tex; // Integer Used To Select Texture
float x; // X Position
float y; // Y Position
float z; // Z Position
};

GLuint texture[1]; // Storage For 1 Texture
object background; //create object 'background that will hold' background BMP

public:
Graphics(){}; //default - currently does nothing
Graphics(int argc,char* argv[]); //overloaded constructor
~Graphics() {}; //destructor - currently does nothing

void loadBackgroundTexture(void);
void drawBackground(void);
};


Graphics::Graphics(int argc,char* argv[]){
glutInit(&argc,argv); //start glut
loadBackgroundTexture();
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); //double buffered for animation. RGB colour mode
glutInitWindowSize(270,390); //window size
glutInitWindowPosition(300,150); //window position
glutCreateWindow("PicassoTalk! J.Trevan : 2k4"); //create window
glClearColor(0.0f ,0.0f ,0.0f ,0.0f); //clear colour = black
glMatrixMode(GL_PROJECTION); //select projection mode
glLoadIdentity(); //reset projection view
gluPerspective(45.0f,(GLfloat)270/(GLfloat)390,0.1f,100.0f); //perspective
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glDisable(GL_DEPTH_TEST); // Disable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glBlendFunc(GL_ONE,GL_SRC_ALPHA); // Set Blending Mode (Cheap / Quick)
glEnable(GL_BLEND); // Enable Blending
}


void Graphics::loadBackgroundTexture(void){
background.tex = 0; //define texture ie. which bitmap
background.x = 0; //set background position in window
background.y = 0;
background.z = 0;

HBITMAP hBMP; // Handle Of The Bitmap
BITMAP BMP; // Bitmap Structure

byte Texture[]={ IDB_BACKGROUND1 }; // The ID of background bitmap to load

glGenTextures(sizeof(Texture), &texture[0]); // Generate Texture (sizeof(Texture)=1 ID)

//The following loads the bitmap image. MAKEINTRESOURCE converts int to resource number
//ie. which bitmap to load. IMAGE_BITMAP defines that image being loaded is a bitmap. The
//next 2 zero's are the required size of the image, x and y. Want to use the default image
//size so leave as zero. The last parameter (LR_CREATEDIBSECTION) returns a DIB section bitmap,
//which is a bitmap without all the color information stored in the data.
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL),MAKE INTRESOURCE(Texture[0]), IMAGE_BITMAP, 0,
0, LR_CREATEDIBSECTION);
//hBMP now points to the bitmap data that is loaded by LoadImage( ).

if (hBMP) { // Does The Bitmap Exist?
GetObject(hBMP,sizeof(BMP), &BMP); // Get The Object
// hBMP: Handle To Graphics Object
// sizeof(BMP): Size Of Buffer For Object Information
// Buffer For Object Information
glPixelStorei(GL_UNPACK_ALIGNMENT,4); // Pixel Storage Mode (Word Alignment / 4 Bytes)
glBindTexture(GL_TEXTURE_2D, texture[0]); // Bind Our Texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_LINEAR); // Mipmap Linear Filtering
// Generate Mipmapped Texture (3 Bytes, Width, Height And Data From The BMP)
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BMP.bmWidth, BMP.bmHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE,
BMP.bmBits);
DeleteObject(hBMP); // Delete The Bitmap Object
}

else
cerr << "hBMP doesn't point to anything!! Error loading background bitmap!" << endl;

}

void Graphics::drawBackground(void){
glLoadIdentity(); //Reset modelview matrix
glTranslatef(0.0f,0.0f,-10.0f); //into screen
glBindTexture(GL_TEXTURE_2D, texture[background.tex]); // Bind background texture

glBegin(GL_QUADS);
glTexCoord2f(-1.0f, 1.0f); glVertex2f(-1.0f, 1.0f); //map texture to an object
glTexCoord2f( 1.0f, 1.0f); glVertex2f( 1.0f, 1.0f);
glTexCoord2f( 1.0f,-1.0f); glVertex2f( 1.0f,-1.0f);
glTexCoord2f(-1.0f,-1.0f); glVertex2f(-1.0f,-1.0f);
glEnd();
glLoadIdentity();
glutSwapBuffers();
}

02-11-2004, 01:49 PM
ps. there may be the odd unrequired line in there as I havent streamlined the code yet!!

02-11-2004, 02:00 PM
the texture coordinates are obviously wrong...but correcting them still doesnt help

roffe
02-11-2004, 03:12 PM
I don't see you setting the wrapping mode for the texture anywhere.

Try adding:
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,.. .);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,.. .);

Maybe that would help.

02-11-2004, 03:44 PM
where would it be best to add it?

roffe
02-11-2004, 03:50 PM
Where you specify the other texture parameters(MIN/MAG filter).

02-11-2004, 04:18 PM
thanks but didnt work! arghhh...!

Relic
02-12-2004, 03:06 AM
Look sharper! It's really simple.
glutInitDisplayMode() initializes the pixelformat and rendering context! (You have no depth specified, in case you need that in the future.)
The function loadBackgroundTexture() uses OpenGL functions before the rendering context has been created. All these will be ingored if there is no rendering context current.


[This message has been edited by Relic (edited 02-12-2004).]

02-12-2004, 06:43 AM
thank you...that has loaded the texture! nice one! Unfortunately the texture appears to be corrupt...all i get is a load of noise at the top and a bit of a windows folder at the bottom?!?will work on that, but any ideas based on the code would be apprieciated. (moved the loadBachgroundTexture() function to the end of the constructor)

02-12-2004, 07:19 AM
For reference code is now as follows (texture does not appear to load correctly)

#include <gl\glut.h>
#include "resource.h"

class Graphics{
private:
struct object // Create A Structure Called Object
{
int tex; // Integer Used To Select Texture
float x; // X Position
float y; // Y Position
float z; // Z Position
};

GLuint texture[1]; // Storage For 1 Texture
object background; //create object 'background that will hold' background BMP

HBITMAP hBMP; // Handle Of The Bitmap
BITMAP BMP; // Bitmap Structure

public:
Graphics(){}; //default - currently does nothing
Graphics(int argc,char* argv[]); //overloaded constructor
~Graphics() {}; //destructor - currently does nothing

void loadBackgroundTexture(void);
void drawBackground(void);
};


Graphics::Graphics(int argc,char* argv[]){
glutInit(&argc,argv); //start glut
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); //double buffered for animation. RGB colour mode
glutInitWindowSize(300,300); //window size
glutInitWindowPosition(300,150); //window position
glutCreateWindow("PicassoTalk! J.Trevan : 2k4"); //create window
glClearColor(0.0f ,0.0f ,0.0f ,0.0f); //clear colour = black
glMatrixMode(GL_PROJECTION); //select projection mode
glLoadIdentity(); //reset projection view
gluPerspective(45.0f,(GLfloat)300/(GLfloat)300,0.1f,100.0f); //perspective
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glDisable(GL_DEPTH_TEST); // Disable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
loadBackgroundTexture();
}


void Graphics::loadBackgroundTexture(void){
background.tex = 0; //define texture ie. which bitmap
background.x = 0; //set background position in window
background.y = 0;
background.z = 0;

byte Texture[]={ IDB_BACKGROUND2 }; // The ID of background bitmap to load

glGenTextures(1, texture); // Generate Texture (sizeof(Texture)=1 ID)

//The following loads the bitmap image. MAKEINTRESOURCE converts int to resource number
//ie. which bitmap to load. IMAGE_BITMAP defines that image being loaded is a bitmap. The
//next 2 zero's are the default size of the image, x and y.
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL),MAKE INTRESOURCE(Texture[0]), IMAGE_BITMAP, 0,
0, LR_DEFAULTCOLOR);
//hBMP now points to the bitmap data that is loaded by LoadImage( ).

if (hBMP) { // Does The Bitmap Exist?
GetObject(hBMP,sizeof(BMP), &BMP); // Get The Object
// hBMP: Handle To Graphics Object
// sizeof(BMP): Size Of Buffer For Object Information
// Buffer For Object Information
glPixelStorei(GL_UNPACK_ALIGNMENT,4); // Pixel Storage Mode (Word Alignment / 4 Bytes)
glBindTexture(GL_TEXTURE_2D, texture[0]); // Bind Our Texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
DeleteObject(hBMP); // Delete The Bitmap Object
}

else
cerr << "hBMP doesn't point to anything!! Error loading background bitmap!" << endl;

}

void Graphics::drawBackground(void){
glLoadIdentity(); //Reset modelview matrix
glTranslatef(0.0f,0.0f,-3.0f); //into screen
glBindTexture(GL_TEXTURE_2D, texture[0]); // Bind background texture

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,256,256,0,GL_ RGBA,GL_UNSIGNED_BYTE,BMP.bmBits);
//glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0); glVertex3f(-1.0,-1.0,0.0);
glTexCoord2f(0.0,1.0); glVertex3f(-1.0, 1.0,0.0);
glTexCoord2f(1.0,1.0); glVertex3f( 1.0, 1.0,0.0);
glTexCoord2f(1.0,0.0); glVertex3f( 1.0,-1.0,0.0);
glEnd();
glLoadIdentity();
glutSwapBuffers();
}

Relic
02-12-2004, 08:35 AM
Man, one step at a time!
Now you changed the loadBackgroundFunction() from working to non-working.
The GetObject() on a bitmap gives you a pointer to the bitmap data. But you DeleteObject() on the hBMP before you access the data and expect the pointer to be still valid. That doesn't look ok.

Change it back to the old style and it should get better, but I'm not sure if you have the alignment and everything right afterwards. Probably for a 256*256, but try this with something which has no 4 byte alignement like 2x2...

dvm
02-13-2004, 03:53 AM
I also remember having the same problem with my textures. Try experimenting with the posible types of GL_RGBA (GL_RED, GL_RGB, GL_BGR and stuff), in glTexImage2D. Also I think sometimes the GL_UNSIGNED_BYTE needed experimenting. I'm almost sure that among other things this should be the solution. Can anyone ellaborate on how we can read a bitmap properly so we set the correct type of GL_RGB, BGR etc.?

Nychold
02-13-2004, 05:14 AM
Originally posted by moucard:
I also remember having the same problem with my textures. Try experimenting with the posible types of GL_RGBA (GL_RED, GL_RGB, GL_BGR and stuff), in glTexImage2D. Also I think sometimes the GL_UNSIGNED_BYTE needed experimenting. I'm almost sure that among other things this should be the solution. Can anyone ellaborate on how we can read a bitmap properly so we set the correct type of GL_RGB, BGR etc.?

Windows bitmap files are always stored in BGR format. Further more, if I remember correctly, the files are stored upside down after Windows loads them! Then the other question is how many bpp does the picture have? The best option is to simply write your own bitmap loader (not particularly difficult to do) and have it convert all the file types you want to load into some specific format. This reduces a lot of unnecessary computations by OpenGL, and gives you a lot more control over the situation.

02-13-2004, 05:46 AM
Relic: You said i delete hBMP to early...but i dont use that pointer after I've deleted it, as GetObject transfers the bitmap data to the bitmap structure BMP, and subsequently I use this to access the bitmap data. Surely this is ok as all the data has been transfered to the BMP structure and then i delete hBMP?

02-13-2004, 05:48 AM
to make myself clearer...i call BMP.bmBits when i want to access the bitmap data, not a reference to hBMP which i have deleted...

Nychold
02-13-2004, 06:06 AM
Originally posted by Mr.JT:
Relic: You said i delete hBMP to early...but i dont use that pointer after I've deleted it, as GetObject transfers the bitmap data to the bitmap structure BMP, and subsequently I use this to access the bitmap data. Surely this is ok as all the data has been transfered to the BMP structure and then i delete hBMP?

Actually, I think I said that, and yes it can still cause problems. BMP.bmBits is just a pointer to memory. If you tell Windows to delete that memory, yes the image might be there, BUT if you allocate memory after you delete the bitmap, you could accidently overwrite your texture. This may not cause a problem immediately either, because I think OpenGL will copy texture data to the video card, but if something happens, and the video memory gets wiped (say with an Alt-Tab or a screen saver kicks in), OpenGL will go back to find that image and, surprise surprise, will pull up the garbage data. It's usually a good idea to keep the textures in memory until you're sure they're not needed anymore (or at least for a while), and reload them if they become necessary.

[This message has been edited by Nychold (edited 02-13-2004).]

02-13-2004, 06:15 AM
i understand...have changed it... but still not working. Time to play around with different GL_BGR/GL_RGB etc! Thanks to everyone so far with the help...sorry its turned out to be such a long one...but no doubt it'll get longer!

Relic
02-13-2004, 10:53 AM
Just to throw in another choice to do things, my choice of accessing bitmap bits is GetDIBits() which actually copies the bits to your desired memory location.
Hey this is all basic GDI stuff, go grab some working code from somewhere and just plug it in.
I don't use BMP files normally, I load uncompressed TGA files which are so simple to handle or use a PNG-lib if images start to get big. Where the heck did I put this 16k*16k terrain texture... http://www.opengl.org/discussion_boards/ubb/wink.gif

mithun_daa
02-13-2004, 10:58 AM
u have a loadidentity just before swapping the buffers. might cause some probs.

roffe
02-13-2004, 12:29 PM
Originally posted by mithun_daa:
u have a loadidentity just before swapping the buffers. might cause some probs.

Why?

02-15-2004, 02:41 AM
I cant find GL_BGR as an option for glTexImage2D?? It is an undeclared identifier when compiling? How do I define that?

chowe6685
02-15-2004, 06:03 AM
its an extension, download glext.h and use GL_BGR_EXT, or just try GL_RGB it may look weird (ie blue and red reversed) but at least you'll know your texturing is working

02-15-2004, 07:40 AM
ok well none of these things are working...and the texture seems to be a mixture of noise and warped windows icons from the desktop...and its different each time i run the program...could this be an error in me creating the resource file for visual studio? Although I exactly followed nehe tutorial...may be i'll try loading the picture directly from file.

mikeman
02-15-2004, 08:50 AM
The bmBits pointer is invalid after you have deleted the bitmap object.Remember,it is not YOUR application that supplies a pointer to which the bitmap data will be copied,but GDI allocates the pointer and frees memory when you destroy the bitmap object.
The solution is very simple:Why do you keep your glTexImage2D inside the drawbackground procedure?The texture need to be loaded only once.
glTexImage2D must be placed immediately after glBindTexture,where bmBits is still valid and the bitmap can be loaded into video memory.After calling glTexImage2D,you can delete the bitmap object.
Also,the first instance of your code(the one that had gluBuildMipmaps) had a call like glBindTexture(GL_TEXTURE_2D,background.tex).You initialize background.tex to 0 and then you put it inside glBindTexture without assigning to it any value at all!What did you expect to happen?
And use GL_BGR or GL_RGB.

[This message has been edited by mikeman (edited 02-15-2004).]

[This message has been edited by mikeman (edited 02-15-2004).]

02-15-2004, 02:01 PM
If I dont sort it this time i promise to stop posts!! I've changed it so many times and read so many different styles of achieving it that i think I have probably just made it worse. I still get a weird jumble of rubbish which definately isnt my texture, and the most obvious indication that something is wrong is the line in drawBackground() cout << BMP.bmWidth << endl; returns the value 0 (zero). so nothing is actually in the structure BMP. And I have no idea why. Could be that I'm just getting dillusional but the following code should work now shouldnt it....?

#include <gl\glut.h>
#include "resource.h"

class Graphics{
private:
struct object // Create A Structure Called Object
{
int tex; // Integer Used To Select Texture
float x; // X Position
float y; // Y Position
float z; // Z Position
};

GLuint texture[1]; // Storage For 1 Texture
object background; //create object 'background' that will hold background BMP

HBITMAP hBMP; // Handle Of The Bitmap
BITMAP BMP; // Bitmap Structure

public:
Graphics(){}; //default - currently does nothing
Graphics(int argc,char* argv[]); //overloaded constructor
~Graphics() { DeleteObject(hBMP);} // Delete The Bitmap Object //destructor - currently does nothing

void loadBackgroundTexture(void);
void drawBackground(void);
};


Graphics::Graphics(int argc,char* argv[]){
glutInit(&argc,argv); //start glut
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB); //double buffered for animation. RGB colour mode
glutInitWindowSize(300,300); //window size
glutInitWindowPosition(300,150); //window position
glutCreateWindow("PicassoTalk! J.Trevan : 2k4"); //create window
glClearColor(0.0f ,0.0f ,0.0f ,0.0f); //clear colour = black
glMatrixMode(GL_PROJECTION); //select projection mode
glLoadIdentity(); //reset projection view
gluPerspective(45.0f,(GLfloat)300/(GLfloat)300,0.1f,100.0f); //perspective
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
glClearDepth (1.0f); // Depth Buffer Setup
glDepthFunc (GL_LEQUAL); // The Type Of Depth Testing (Less Or Equal)
glDisable(GL_DEPTH_TEST); // Disable Depth Testing
glShadeModel (GL_SMOOTH); // Select Smooth Shading
glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Set Perspective Calculations To Most Accurate
glEnable(GL_TEXTURE_2D);
loadBackgroundTexture();
}


void Graphics::loadBackgroundTexture(void){

byte Texture[]={ IDB_BACKGROUND2 }; // The ID of background bitmap to load
glGenTextures(1,texture);

//The following loads the bitmap image. MAKEINTRESOURCE converts int to resource number
//ie. which bitmap to load. IMAGE_BITMAP defines that image being loaded is a bitmap. The
//next 2 zero's are the required size of the image, x and y. Want to use the default image
//size so leave as zero. The last parameter (LR_CREATEDIBSECTION) ???!!!!
hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL),MAKE INTRESOURCE(Texture[0]), IMAGE_BITMAP, 0,
0, LR_DEFAULTCOLOR);
//hBMP now points to the bitmap data that is loaded by LoadImage( ).


if (hBMP) { // Does The Bitmap Exist?
GetObject(hBMP,sizeof(BMP), &BMP); // Get The Object
// hBMP: Handle To Graphics Object
// sizeof(BMP): Size Of Buffer For Object Information
// Buffer For Object Information
glPixelStorei(GL_UNPACK_ALIGNMENT,4); // Pixel Storage Mode (Word Alignment / 4 Bytes)
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, BMP.bmWidth, BMP.bmHeight,
0, GL_RGB, GL_UNSIGNED_BYTE, BMP.bmBits);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}

else
cerr << "hBMP doesn't point to anything!! Error loading background bitmap!" << endl;

}

void Graphics::drawBackground(void){
glLoadIdentity(); //Reset modelview matrix
glTranslatef(0.0f,0.0f,-3.0f); //into screen
cout << BMP.bmWidth << endl;
//glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0); glVertex3f(-1.0,-1.0,0.0);
glTexCoord2f(0.0,1.0); glVertex3f(-1.0, 1.0,0.0);
glTexCoord2f(1.0,1.0); glVertex3f( 1.0, 1.0,0.0);
glTexCoord2f(1.0,0.0); glVertex3f( 1.0,-1.0,0.0);
glEnd();

glutSwapBuffers();
glLoadIdentity();
}

02-15-2004, 02:25 PM
also what is glGenTextures(1,texture); doing? It doesnt seem as though this is in the right place/is actually doing anything...what is actually put in texture[0]?

Nychold
02-15-2004, 02:41 PM
void glGenTextures(GLsizei n,GLuint *textureNames);

Returns n currently unused names for texture objects in the array textureNames. The names returned in textureNames do not have to be a contiguous set of integers.

The names in textureNames are marked as used, but they acquire texture state and dimensionality (1D or 2D) only when they are first bound.

Zero is a reserved texture name and is never returned as a texture name by glGenTextures()

This is a direct quote from the OpenGL reference book. Basically, glGenTextures() allocates the texture objects from OpenGL for you to use. It's almost required if you use multiple textures, but I make it habit to use it even for one texture. ^_^

dorbie
02-15-2004, 11:34 PM
No, it's not required unless you have software you didn't write that also uses texture handles in the same context that you never created.

It doesn't actually allocate anything, it merely spits out and reserves texture names (integers) that have not been used before.

The business of using gentextures can be dispensed with entirely. Just using unique non zero integers for each texture works just fine. GenTextures is a way of obtaining unique names that isn't essential at all.

02-16-2004, 09:37 AM
Finally!!

Found the answer! It was to do with the line hBMP=(HBITMAP)LoadImage(GetModuleHandle(NULL),MAKE INTRESOURCE(Texture[0]), IMAGE_BITMAP, 0,
0, LR_DEFAULTCOLOR); When reading through tutorials I read that the last parameter which was originally LR_CREATEDIBSECTION meant that bitmap information was stored without the colour information (nehe lesson 38. I obviously wanted colour in my bitmap so changed this to LR_DEFAULTCOLOR as this was detailed in the manual as using standard colours. I just got confused between the meaning of these parameters, and although i still dont actually understand the meaning of LR_CREATEBIBSECTION it doesnt matter as it works!! Once id done this i had to switch the colour modes round to BGR as someone mentioned before. This link dies here!!!!