Trying to tile texture mapped quadrilateral polygons, and failing.

Started by
7 comments, last by MrLeap 18 years, 10 months ago
Trying to go a little past Nehe's texturemapping tutorial, I tried to tile a texturemapped quadrilateral. I'm not very .. uhhmm.. good at C++, so I'm wondering if I called my function in the wrong place or something stupid like that. It's also possible that my logic is wrong, but I've gone over it a few times to no avail.

//------------------nasty tile code 
 void tile(int x, int y)  
 {  
      int xloc = 0;     
      int yloc = 0;     
      int start; 
      int count; 
  
      for (count = 1;count <= y;count++) { 
           for (start = 1; start < x;start++) {  
                glTranslatef((0.0f + xloc),(0.0f + yloc),0.0f);      
                glBindTexture(GL_TEXTURE_2D, texture[0]); 
                glBegin(GL_QUADS);// Draw A Quad 
                glVertex3f(-1.0f, 1.0f, 0.0f);                    // Top Left 
                glVertex3f( 1.0f, 1.0f, 0.0f);                    // Top Right 
                glVertex3f( 1.0f,-1.0f, 0.0f);                    // Bottom Right 
                glVertex3f(-1.0f,-1.0f, 0.0f);                    // Bottom Left 
                glEnd();           
            
                xloc += 256;            
           } 
           yloc += 256; 
      } 
 } 
 //---------------------------------end
and I'm calling this function within the glDrawscene bit. It compiles, it just acts like the function isnt being acknowledged. By the way, hi i'm new to the forum *laugh*
Advertisement
Check out this article: Tiling in OpenGL

-DavidR-
In this world gone mad, we won't spank the monkey; the monkey will spank us.
First you don't call glTexCoord2f before glVertex3f so unless you use automaticly genereated normals ther will be a problem. Second, glTranslatef is relative to all previous translations. So if you glTranslate the first tile by x and the second by 2*x it will be located at 3x. You have to call glLoadIdentity (or glPushMatrix/glPopMatrix) to make translation relative to the origin.

It might also be a problem that you use 0.0f for the z cordinate depending on how you have setup your sceen.

Hope this helps, if you still have questions ask.

see also:

glTexCoord
glTranslate
glLoadIdenty
glPushMatix/glPopMatrix
hm, I used the tutorial you gave me noixtirdoe, and I got it to compile with out any errors or warnings (yay.) But I try to run it, and it crashes, saying that the memory could not "read". I debug the crash, and it puts a break by the line that has the following statement:


   GL_UNSIGNED_BYTE, TextureImage[0]->data);


saying that the memory could not "read" leads me to believe the problem is with the code that grabs textures.

I feel kind of ashamed putting my debugging on you people, i'll keep trying things. :p

Thanks again, all of you :D

I just thought about it, and I wonder if the reason it's crashing is the textures themselves. I mean, I copy+pasted the code that grabs the texture, so I dont think it would be a syntax error (laugh).

I'm wondering if my bmp's are the wrong depth or something. I'm going to go through a couple different depths and modes that photoshop has to offer (X1 R5 G5 B5, R5 G6 B5, X4, R4 G4 B4... not sure what any of that means, but it's worth a shot I suppose :D)


If this doesn't work after a little bit more work I think i'm going to look at nehe's tga code, bmp's are yucky :D


EURIKA!

I realized that I had done a foolish thing. I was using the texture grabbing code from the tutorial, and the file structure from nehe's tutorial, so they were trying to find the textures that were actually in the /data/ folder. (I'm an idiot, sorry)

This didn't fix it however, just changed the error .. *laugh* Now I get the following error: "unknown DIB file format" followed by a cannot read memory type crash error. heh, I'm making progress.
Sounds like you are trying to load an invalid bitmap file. Post the code that you're using to actually load a texture. It might give an indication to what you're doing.

-DavidR-
In this world gone mad, we won't spank the monkey; the monkey will spank us.
David, without seeing my code or anything, you've managed to fix my problem! :p I was using 16 bit bmp's... So now it runs! But alas, it's a black screen :p I think that has something to do with perhaps lighting, or camera position, i'll work on that now.

Is there any way to do something like.. Fullbright? or something similar? I dont know how better to describe it.
Make sure that after you're done drawing your textured polygons, you disable texturing: glDisable(GL_TEXTURE_2D);

-DavidR-
In this world gone mad, we won't spank the monkey; the monkey will spank us.
the camera position was the problem.. Oh god this is the first thing that has ever worked! *dies*


This topic is closed to new replies.

Advertisement