Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Could I get some help with my drawing routine.

This topic is 5493 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Could anyone tell me why the drawing routine given below is only drawing 4 tiles. It was intended to draw a 15x12 tile grid. Thanks int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f, 0.0f, -15.0f); glBindTexture(GL_TEXTURE_2D, Texture[0]); for(int i = 0; i < 15; i++){ for(int j = 0; j <12; j++){ glBegin(GL_QUADS); glTexCoord2f(1.0f, -1.0f); glVertex3f(-i*-0.125f, -j*0.125f, 0.0f); glTexCoord2f(-1.0f, -1.0f); glVertex3f(-i*0.125f, -j*0.125f, 0.0f); glTexCoord2f(-1.0f, 1.0f); glVertex3f(-i*0.125f, -j*-0.125f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(-i*-0.125f, -j*-0.125f, 0.0f); glEnd(); } } return TRUE; }

##### Share on other sites
Try reversing the order of the vertices.

Other note: Minimize calls to glBegin. You should put that outside of your loop so you only have to call it once.

##### Share on other sites
Ok thanks for the help. I''ll give it a shot.

##### Share on other sites
Wait, nevermind. I think the problem is you are starting with 0 for your counting variable, so the first set of vertices are all at (0,0,0). If it's rendering anything at all then the order shouldn't matter. Someone hit me on the head with a large object please...

 If that didn't make sense, a simpler way to put it is anything multiplied by zero equals zero.

[edited by - Raloth on July 6, 2003 11:46:43 PM]

##### Share on other sites
I tried both reversing the vertices, and starting the counting variable at 1. When I reversed the vertices it didn''t draw anything at all, and when I started the counting variables at 1 I still only got 4 tiles drawn.
Thanks again for your advice, at least im ruling out some possible sources of error.

##### Share on other sites
Could my problem have anything to do with using 2D texture coordinates on a 3d poly?

##### Share on other sites
Your problem is much more trivial:
You are plotting several squares with a length of 0 ...

EDIT: What I just said is not true. I should have read Your code more carefully, but it´s quite confusing.

Try:

glTexCoord2f(1.0f, -1.0f); glVertex3f(i*0.125f, j*0.125f, 0.0f);
glTexCoord2f(-1.0f, -1.0f); glVertex3f((i+1)*0.125f, j*0.125f, 0.0f);
glTexCoord2f(-1.0f, 1.0f); glVertex3f((i+1)*0.125f, (j+1)*0.125f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(i*0.125f, (j+1)*0.125f, 0.0f);

btw.: I didn´t care for the orientation but as long as backface-culling is off (default) and you don´t want to do computations with your vertices that doesn´t matter.

EDIT: oh ... one more thing: I think texture-coordinates range from 0 to 1, not -1 to +1.

[edited by - Atheist on July 7, 2003 9:11:56 AM]

[edited by - Atheist on July 7, 2003 9:17:59 AM]

##### Share on other sites
looked into Your code again because I was wondering how You got 4 tiles out of it. You are obvoisly drawing rectangles around the origin with increasing size (take a close look at Your code and try to figure out why) so since your last rectangle is the biggest and covering the others you should only get one rectangle (relative size 15*12).

The reason you think that you got 4 might be due to your wrong texture-coordinates. You actually plot one rectangle with your texture 4 times in it.

So if You only want to draw that tile You might as well draw only one Quad with texture-coordinates (0,0) -> (15,12).

It might be interesting to do some benchmarking which way is the faster one (I´d bet it is the one-quad-way). If You check this out, please give me some feedback about your results.

##### Share on other sites
Its working now. Im not exactly sure what was going through my head when I was coding that. Thanks to Atheist for noticing that I had texture coords going from -1 to 1, and also noticing that yes I was just drawing larger and larger rectangles around the origin.

for(float i = 0; i < 15; i++){
for(float j = 0; j < 12; j++){
x = i*0.5f;
y = j*-0.5f;
glTexCoord2f(1.0f, 0.0f);glVertex3f(x, y, 1.0f);
glTexCoord2f(0.0f, 0.0f);glVertex3f(x+0.5f,y , 1.0f);
glTexCoord2f(0.0f, 1.0f);glVertex3f(x+0.5f,y-0.5f,1.0f);
glTexCoord2f(1.0f, 1.0f);glVertex3f(x,y-0.5f , 1.0f);
}
}
glEnd();

1. 1
2. 2
Rutin
26
3. 3
4. 4
JoeJ
18
5. 5
gaxio
11

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631763
• Total Posts
3002197
×