Paladin_VB
asked on
Texturing an OpenGl Quad with a bitmap stored in a GluByte Array
Alright how can I texture an opengl Quad with a bitmap which is stored in a glubyte array ?
(Im making a 2d game with destrutable terrain ) I would use glDrawPixels() however when the point 0,0 goes off the screen the drawpixels image disappears :P .
Thanks Mark
(Im making a 2d game with destrutable terrain ) I would use glDrawPixels() however when the point 0,0 goes off the screen the drawpixels image disappears :P .
Thanks Mark
ASKER
emm thats not quite what I wanted . I have a bitmap which is already loaded into a glubyte[] array . I can draw it using drawpixels , but i would like specifically whats stored in the glubyte array x to be loaded into a texture. I could do with the code to loading a glubyte array storing a bitmap into a way it can be standardly used as a texture ie. an Unsigned int rather than loading the orginall bitmap file to be used as a texture. emm i hope that makes sense
So you are asking how to write you own texturing engine? o.o;
You don't want to use standard openGL 2D textures from a glubyte array, then loading it into a texture and using the 2D quad hook to apply the texture to it? o.o;
I guess now I'm confused. You can do a precompiled display with a *.dll file to include a already read in byte file stored in an array and applied to the texture. But otherwise you are going to need to read in the bmp files at program initialization and apply it to a texture to use throughout your program.
~Aqua
PS: Maybe I missed the boat here but you'd get a lot more help if this thread if it was in Gamedev... because I'm totally missing what you want to do right now.
You don't want to use standard openGL 2D textures from a glubyte array, then loading it into a texture and using the 2D quad hook to apply the texture to it? o.o;
I guess now I'm confused. You can do a precompiled display with a *.dll file to include a already read in byte file stored in an array and applied to the texture. But otherwise you are going to need to read in the bmp files at program initialization and apply it to a texture to use throughout your program.
~Aqua
PS: Maybe I missed the boat here but you'd get a lot more help if this thread if it was in Gamedev... because I'm totally missing what you want to do right now.
ASKER
lol I don't know : S . Sorry I proably explained what i want to do very poorley. Ill try again :D .
I have stored a bitmap image in
GLubyte* ab;
I can use
glDrawPixels(map_width,map _height,GL _RGB, GL_UNSIGNED_BYTE ,ab)
To draw it . But instead I would like to get whats stored in GLubyte* ab onto a GL_QUADS
ie. it'd like to bind GLubyte* ab; onto the thing below
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5.0f, -5.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 5.0f, -5.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 5.0f, 5.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-5.0f, 5.0f, 0.0f);
glEnd();
How do I do it ?
hehe I hope that makes more sense. (Sorry im a total newbie)
Mark
I have stored a bitmap image in
GLubyte* ab;
I can use
glDrawPixels(map_width,map
To draw it . But instead I would like to get whats stored in GLubyte* ab onto a GL_QUADS
ie. it'd like to bind GLubyte* ab; onto the thing below
glBegin(GL_QUADS);
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-5.0f, -5.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 5.0f, -5.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 5.0f, 5.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-5.0f, 5.0f, 0.0f);
glEnd();
How do I do it ?
hehe I hope that makes more sense. (Sorry im a total newbie)
Mark
ASKER
owh and GLubyte* ab; is a 1 dimensional array .
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok , hehe sorry
Here's what I use. It's probably derived from the nehe tutorial, but I've forgotten. imgbuf is just a struct with ints datawidth and dataheight, and a byte array data[]. checkErrors() just checks the GL error state.
int loadTexture(imgbuf img)
{
int debug = 0;
GLuint texid;
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2 D, texid);
// The next commands sets the texture parameters
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_MIPMAP_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
checkErrors();
if (debug) printf("glTexImage2D\n");
// Finally we define the 2d texture
glTexImage2D(GL_TEXTURE_2D , 0, 3, img.datawidth, img.dataheight,
0, GL_RGB, GL_UNSIGNED_BYTE, img.data);
checkErrors();
if (debug) printf("gluBuild2DMipmaps\ n");
// And create 2d mipmaps for the minifying function
if (debug) {
printf("imgwidth=%d, imgheight=%d, datawidth=%d, dataheight=%d, "
"comps=%d, data=%p\n",
img.imgwidth, img.imgheight, img.datawidth, img.dataheight,
img.comps, img.data);
}
gluBuild2DMipmaps(GL_TEXTU RE_2D, 3, img.datawidth, img.dataheight,
GL_RGB, GL_UNSIGNED_BYTE, img.data);
checkErrors();
return texid;
}
int loadTexture(imgbuf img)
{
int debug = 0;
GLuint texid;
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2
// The next commands sets the texture parameters
glTexParameterf(GL_TEXTURE
glTexParameterf(GL_TEXTURE
glTexParameterf(GL_TEXTURE
glTexParameterf(GL_TEXTURE
GL_LINEAR_MIPMAP_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
checkErrors();
if (debug) printf("glTexImage2D\n");
// Finally we define the 2d texture
glTexImage2D(GL_TEXTURE_2D
0, GL_RGB, GL_UNSIGNED_BYTE, img.data);
checkErrors();
if (debug) printf("gluBuild2DMipmaps\
// And create 2d mipmaps for the minifying function
if (debug) {
printf("imgwidth=%d, imgheight=%d, datawidth=%d, dataheight=%d, "
"comps=%d, data=%p\n",
img.imgwidth, img.imgheight, img.datawidth, img.dataheight,
img.comps, img.data);
}
gluBuild2DMipmaps(GL_TEXTU
GL_RGB, GL_UNSIGNED_BYTE, img.data);
checkErrors();
return texid;
}
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06
If you need further assistance on explination of that code feel free to ask but everything you need to hook a texture to a quad is there with more than ample explination.
~Aqua
*****ATTN: jkr *****
Could this please be moved to Gamedev where it belongs.
******************