Skip to main content
gamedev.net
🔒 Locked

Beginner's texture map problem

Started by uldaman 1 reply 650+ views
Original Post
uldaman
uldaman
I'm trying to learn to do some basic texture mapping, from several different books, but my texture keeps appearing as just white pixels. Here is my relevant code: void init() { glClearColor(0.0, 0.0, 0.0, 0.0); gluOrtho2D(0.0, 400.0, 0.0, 400.0); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); compText(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_CLAMP); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, texArray); } void window() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBegin(GL_QUADS); glTexCoord3f(10.0, 10.0, 0.0); glVertex3f(10.0, 10.0, 0.0); glTexCoord3f(11.0, 10.0, 0.0); glVertex3f(42.0, 10.0, 0.0); glTexCoord3f(11.0, 11.0, 0.0); glVertex3f(42.0, 42.0, 0.0); glTexCoord3f(10.0, 11.0, 0.0); glVertex3f(10.0, 42.0, 0.0); glEnd(); glFlush(); glDisable(GL_TEXTURE_2D); } This is pretty simple, obviously, and I've copied almost exactly from an example in a book, just to get a feel for the functions. compText() just initializes texArray (my texture) to all red pixels, i.e. texArray is a GLubyte array [32][32][4]. I know the glBindTexture isnt really doing anything with texArray but it's not the problem, as far as I checked. Oh and the window is 400x400 so the square is 32x32 hovering over the bottom left corner, but it shows up as just white. I originally copied a function from a book which was supposed to make the texture a simple grayscale checkerboard, but after these results I just made it red, with still the same results. Anyone spot a problem? Thanks in advance
Brother Bob
Brother Bob
Check your books again. GL_CLAMP is a wrapping mode, not a texture mini-/magnification filter.
uldaman
uldaman
That wasn't the problem, but after checking that I found my own mistake. And it's an embarassingly simple one, haha. In my haste to try the simpler color when the checkerboard pattern didnt work, I rewrote my array-fill function using the the rgb 0.0-1.0 instead of Glubyte 0-255. the alpha value being 1.0 was probably why there was no color.

*smack*
thanks for the help though

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.