Results 1 to 2 of 2

Thread: Applying textures

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    8

    Applying textures

    Hi, I want to apply a texture to a triangle strip. Don't know if this is possible, but anyway it doesn't work. I'd appreciate it if someone could help me. Here's my drawing code, with the texture loaded in _textureId1:

    Code :
    glEnable(GL_TEXTURE_2D);
    	glBindTexture(GL_TEXTURE_2D, _textureId1);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
    	glColor3f(0.9f, 0.7f, 0.0f);
    	for(int z = 0; z < _terrain->length() - 1; z++) {
    		//Makes OpenGL draw a triangle at every three consecutive vertices
    		glBegin(GL_TRIANGLE_STRIP);
    		for(int x = 0; x < _terrain->width(); x++) {
    			Vec3f normal = _terrain->getNormal(x, z);
    			glTexCoord2f(z/(_terrain->length()-1),x/(_terrain->width()-1));
    			glNormal3f(normal[0], normal[1], normal[2]);
    			glVertex3f(_terrain->getXPos(x,z),_terrain->getYPos(x,z),_terrain->getZPos(x,z));
     
    			normal = _terrain->getNormal(x, z + 1);
    			glTexCoord2f((z+1)/(_terrain->length()-1),x/(_terrain->width()-1));
    			glNormal3f(normal[0], normal[1], normal[2]);
    			glVertex3f(_terrain->getXPos(x,z+1),_terrain->getYPos(x,z+1),_terrain->getZPos(x,z+1));
    		}
    		glEnd();
    	}
    	glDisable(GL_TEXTURE_2D);

    Thank you for help

  2. #2
    Junior Member Newbie
    Join Date
    Jun 2009
    Posts
    8

    Re: Applying textures

    Ok, forgot to cast the integers to floats...

Similar Threads

  1. Applying textures to a sphere. I know nothing about textures.
    By ElFlautas in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-28-2018, 03:47 AM
  2. Applying textures in a fast manner?
    By posixoptions in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 05-03-2010, 09:00 AM
  3. glsl help - applying textures to use with fshaders?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-18-2005, 02:52 AM
  4. loading textures and applying to cylinder
    By pmr2004pmr in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-14-2004, 01:12 PM
  5. Applying textures on NURBS
    By ksanim in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 04-05-2001, 05:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean