PDA

View Full Version : easy second texture



07-02-2004, 09:54 AM
Hallo,
is there a way to define and use a second texture like as easy as the first:

def LoadTexture():
import Image
im = Image.open("textures/abc.bmp")
image = im.tostring("raw", "RGBX", 0, -1)
glBindTexture(GL_TEXTURE_2D, glGenTextures(1))
glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 128, 128, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
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_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)Of course I start the function in the init-part ...

this is the object in my DisplayFunction:
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0); glVertex3f(-0.064, 0.064, 0.0)
glTexCoord2f(1.0, 0.0); glVertex3f( 0.064, 0.064, 0.0)
glTexCoord2f(1.0, 1.0); glVertex3f( 0.064, -0.064, 0.0)
glTexCoord2f(0.0, 1.0); glVertex3f(-0.064, -0.064, 0.0)
glEnd()How to define and use a second texture mapped on another object in the DisplayFunction ?

ZbuffeR
07-02-2004, 10:51 AM
>> glBindTexture(GL_TEXTURE_2D, glGenTextures(1))

You will have to actually store the result of glGenTextures.
Ex in C :
GLuint texid[2]; // defined as global
glGenTextures(1, texid);

then:
glBindTexture(GL_TEXTURE_2D, texid[0]);
<upload first texture and tweak texparms>
glBindTexture(GL_TEXTURE_2D, texid[1]);
<upload first texture and tweak texparms>

glBindTexture(GL_TEXTURE_2D, texid[0]);
<draw with first texture>
glBindTexture(GL_TEXTURE_2D, texid[1]);
<draw with second texture>

Just adapt to your language (is that python ?).

07-02-2004, 01:26 PM
OK, thanks, I know what you mean but I do not know the correct Syntax of the first two lines:

GLuint texid[2]; // defined as global
glGenTextures(1, texid);

You guess right; I use PyOpenGL (running on LINUX) and in my opinion the lines must be:

GLuint texid[2] #global because of not beeing in a function
glGenTextures(1, texid)

I found no command named "GLuint" in a documentation and it wrote an error by using it.
When I define "texid" as a list ("texid=[]") the second line did not run !?

CrazyButcher
07-03-2004, 01:39 AM
GLuint is just a typedef for unsigned int,
when you include the gl.h you should get all those types like GLfloat, GLbyte...

ZbuffeR
07-03-2004, 04:52 AM
So in Python you would not have to worry about C types.

The Pyopengl doc seems very good, so read the first example here (bottom) :
http://pyopengl.sourceforge.net/documentation/manual/glGenTextures.3G.xml

homeruniverse
07-03-2004, 04:54 AM
How to include the gl.h with Python ?
I only find a way to include with C ("#include <gl\gl.h>") ...

homeruniverse
07-03-2004, 05:23 AM
thanks, now it runs :D