• Advertisement

Archived

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

Textures and Color: why don't we get along?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have two functions, in two separate classes.
  
void BlockDudeEditor::DrawLevel()
{
	glColor3f(1.0f, 1.0f, 1.0f);

	float offset = grid_l / 2.0f;
	float grid_pos_x, grid_pos_y;
	
	// first draw the background

	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, background_tex);
	glBegin(GL_QUADS);
		glTexCoord2f(0.0f, 0.0f);
		glVertex3f(-NUM_TILES_X * grid_l * 0.5f, 
			-NUM_TILES_Y * grid_l * 0.5f, -offset); // -offset to have the background behind the cubes

		
		glTexCoord2f(0.0f, 1.0f);
		glVertex3f(-NUM_TILES_X * grid_l * 0.5f, 
			NUM_TILES_Y * grid_l * 1.5f, -offset);
		
		glTexCoord2f(2.0f, 1.0f);
		glVertex3f(NUM_TILES_X * grid_l * 1.5f, 
			NUM_TILES_Y * grid_l * 1.5f, -offset);
		
		glTexCoord2f(2.0f, 0.0f);
		glVertex3f(NUM_TILES_X * grid_l * 1.5f, 
			-NUM_TILES_Y * grid_l * 0.5f, -offset);
	glEnd();

	for (int x = 0; x < NUM_TILES_X; x++)
	{
		for (int y = 0; y < NUM_TILES_Y; y++)
		{
			if (grid[x][y] == 0)
				continue;

			switch (grid[x][y])
			{
			case 1:
				glBindTexture(GL_TEXTURE_2D, brick_tex);
				break;
			case 2:
				glBindTexture(GL_TEXTURE_2D, block_tex);
				break;
			default: break;
			}
			
			if (x == 0)
				if (y == 9)
					glBindTexture(GL_TEXTURE_2D, brick_tex);

			grid_pos_x = (x) * grid_l + offset;
			grid_pos_y = (y) * grid_l + offset;
				
			glPushMatrix();
				glTranslatef(grid_pos_x, grid_pos_y, 0.0f);
				DrawCube(grid_l, 1.0f, false, GL_QUADS);
			glPopMatrix();
		}
	}
}
  
and...
  
void BlockDudeCursor::Draw(BlockDudeEditor bde)
	{
		glDisable(GL_TEXTURE_2D);
		glPushMatrix();
			glColor3f(0.0f, 0.0f, 1.0f);
			glTranslatef((x + 0.5f) * bde.grid_l, (y + 0.5f) * bde.grid_l, 0.0f);
			DrawCube(bde.grid_l, 1.0f, false, GL_QUADS);
		glPopMatrix();
		glEnable(GL_TEXTURE_2D);
	}
  
whenever I call both of these functions, the texture for the the DrawLevel function does not show up. instead, it''s just the color that I declare in BlockDudeCursor::Draw. When I don''t call BlockDudeCursor::Draw, the texture shows up perfectly. What is the problem?

Share this post


Link to post
Share on other sites
Advertisement
here''s a hint:


glDisable(GL_TEXTURE_2D);
glPushMatrix();
glColor3f(0.0f, 0.0f, 1.0f);
glTranslatef((x + 0.5f) * bde.grid_l, (y + 0.5f) * bde.grid_l, 0.0f);
DrawCube(bde.grid_l, 1.0f, false, GL_QUADS);
glPopMatrix();
glEnable(GL_TEXTURE_2D);


ARGH!!!!!

Share this post


Link to post
Share on other sites

  • Advertisement