10. Texture mapping

Brock University
COSC 3P98 Computer Graphics
Instructor: Brian J. Ross



Texture mapping


Texture maps


Mapping 2D textures


OpenGL: Texture maps


OpenGL: specifying texture

glTexImage2D(GL_TEXTURE_2D, GLint level, GLint components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels)


OpenGL: more texture control commands

glTexEnv{if}{v}(GL_TEXTURE_ENV, GLenum pname, TYPE param);

glTexParameter{if}{v}(GL_TEXTURE_2D, GLenum pname, TYPE param);


OpenGL: assigning texture coordinates

glBegin(GL_POLYGON);
   glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
   glTexCoord2f(0.0, 3.0); glVertex3f(1.0, 1.0, 0.0);
   glTexCoord2f(3.0, 3.0); glVertex3f(2.41, 1.0, -1.41);
   glTexCoord2f(3.0, 0.0); glVertex3f(2.41, -1.0, -1.41);
glEnd();


Procedural textures


3D texture mapping

eg. Code from [Watt & Watt 1992], Program 7.1, p. 248 :

wood_grain(u,v,w:real; var r,g,b:real);
   var radius, angle: real;
   grain:integer;

   radius := sqrt(u*u+v*v);
   if w=0 then angle := pi / 2
          else angle := arctan(u,w);
   /* arctan evaluates arctan(u,w), but uses ingo to return
      a value betwen 0 and 2*pi */
   radius := radius + 2*sin(20*angle+v/150);
   grain := round(radius) mod 60;
   if grain < 40 then
      r := R_LIGHT; g := G_LIGHT; b := B_LIGHT;
   else
      r := R_DARK; g := G_DARK; b := B_DARK;
end;


3D texture mapping


Some examples of turbulence (via Strata StudioPro 1.75 Macintosh)


Complex 3D textures: Daz3D Bryce

Example Bryce images: One Two. Three. Four.


Complex editor features (Bryce 1)


(from Bryce 1.0 user manual)


References



Back to COSC 3P98 index

COSC 3P98 Computer Graphics
Brock University
Dept of Computer Science
Copyright © 2023 Brian J. Ross (Except noted figures).
http://www.cosc.brocku.ca/Offerings/3P98/course/lectures/texture/
Last updated: November 22, 2023