T H E O P E N G H I N E - Sezione Di Informatica E Automazione

Transcription

EnableClientStateThe OpenGL tControlDrawElementsDrawArraysMapEvaluationThe OpenGL! graphics system diagram, Version 1.1. Copyright " 1996 Silicon Graphics, Inc. All rights OBJECT LINEARbTexGenEYE kTexGenCurrentTextureCoordinatesA*bATexGenSPHERE MAPVerticesEvaluators&Vertex rialRGBARGBA to erialLight ModelParametersParametersTexture egin/EndCurrentColorConvertindex to floatEnable/DisableLightingClamp CurrentNormalnormal coordsto floatz0w1M*b[0,1]Color Index Lighting EquationMask ontFaceMRasterPos4RectbPrimitiveRGBA Lighting EquationClipping, Perspective,andViewport lectionPer!Fragment OperationsTexturing,Fog,andAntialiasingFrame Buffer&Frame Buffer ControlPixelsRectangleGenerationPrimitivesModel ViewMatrixStackFragmentsKey to OpenGL nM TSRASTER POS.LineClippingbPointCullingbM*bPolygonView VolumeLineView Volume(VertexClippingOnly)PointView LoadMatrixFrustumPolygonModeCullFaceb!TM BA RGBA only)Enable/DisableLogicOpDitheringLogic OpPositionRenderModeNotes:1. Commands (and constants) are shown without thegl (or GL ) prefix.2. The following commands do not appear in thisdiagram: glAccum, glClearAccum, glHint,display list commands, texture object commands,commands for obtaining OpenGL state(glGet commands and glIsEnabled), andglPushAttrib and glPopAttrib. Utility libraryroutines are not shown.3. After their exectution, glDrawArrays andglDrawElements leave affected current valuesindeterminate.4. This diagram is schematic; it may not directlycorrespond to any actual OpenGL a Tre, DIA, Informatica Grafica AA tureMemoryLoadNameClearIndexClearColorMaskingFrame BufferControlFrame one bImageReadBufferPortuesi Simone

Menu del giornoImmagini e TexturesImmagini metriTexture Coordinates

Pixel Data xelOperationsTextureMemoryFigure 1. Block diagram of OpenGL.Per!FragmentOperationsFramebuffer

BitmapArray di bit (0 o 1) che ser ve damaschera di disegno per una porzione difinestraSe vi è un 1 nella bitmap ilcorresponding pixel è disegnato aseconda del colore corrente modalita didisegnoBitmap 1 bit per pixelImage Data più bit per pixel

void glBitmap( GLsizei width, GLsizei height,GLfloat xorig, GLfloat yorig,GLfloat xmove, GLfloat ymove,const GLubyte *bitmap )width, height- Specify the pixel width and height of thebitmap image.xorig, yorig- Specify the location of the origin in thebitmap image. From current raster position.xmove, ymove - Specify the x and y offsets to be added to thecurrent raster position after the bitmap is drawn.bitmap- Specifies the address of the bitmap image.(modified by glPixelStore(.)

If the current raster position is invalid, glBitmap is ignored. Otherwise, thelower left corner of the bitmap image is positioned at the windowcoordinateswhere ( xr , yr ) is the raster position and ( xo , yo ) is the bitmap origin.Fragments are then generated for each pixel corresponding to a one in thebitmap image. These fragments are generated using the current raster zcoordinate, color or color index, and current raster texture coordinates.They are then treated just as if they had been generated by a point, line, orpolygon, including texture mapping, fogging, and all per-fragmentoperations such as alpha and depth testing.

Device Coordinates: DC [1,1] [HW,WW] N NYDC(1, HW)(width, height)(XR, YR)(X0, Y0)(1,1)(WW, 1)XDC

void glRasterPos{234}{sifd}( TYPE x, TYPE y, TYPE z, TYPE w )x, y, z, w - Specify the x, y, z, and w object coordinates (if present) for the rasterposition.void glRasterPos{234}{sifd}v( TYPE *coors )v - Specifies a pointer to an array of two, three, or four elements, specifying x, y, z,and w coordinates.The GL maintains a 3-D position in window coordinates. This position, called the rasterposition, is maintained with subpixel accuracy. It is used to position pixel and bitmap writeoperations. See "glBitmap" , "glDrawPixels" , and "glCopyPixels" .The current raster position consists of three window coordinates (x, y, z), a clip coordinate wvalue, an eye coordinate distance, a valid bit, and associated color data and texture coordinates.The w coordinate is a clip coordinate, because w is not projected to window coordinates.The object coordinates presented by glRasterPos are treated just like those of a glVertexcommand: They are transformed by the current modelview and projection matrices and passedto the clipping stage. It is projected and scaled to window coordinates, which become the newcurrent raster position, and the GL CURRENT RASTER POSITION VALID flag is set.

void glWindowPos{234}{sifd}( TYPE x, TYPE y, TYPE z)void glWindowPos{234}{sifd}v( TYPE *coords)Sets the current raster position using the x,y arguments as window coordinates.The z value is eventually clamped by near and far values set by glDepthRange(),void glGetBooleanv( GLenum pname, GLboolean *params )void glGetDoublev( GLenum pname, GLdouble *params )void glGetFloatv( GLenum pname, GLfloat *params )void glGetIntegerv( GLenum pname, GLint *params )GL CURRENT RASTER COLORGL CURRENT RASTER DISTANCEGL CURRENT RASTER INDEXGL CURRENT RASTER POSITIONGL CURRENT RASTER TEXTURE COORDSGL CURRENT RASTER POSITION VALID

ImagesPiù bit per pixel, possono rappresentarecolore, trasparenza, luminanza,profondità, stencilOpenGL non fornisce supporto perscrivere e leggere file immaginiPossono essere usate per le texture .

void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,GLenum format, GLenum type, GLvoid *pixels )x, y - Specify the window coordinates of the first pixel from the frame buffer.This location is the lower left corner of a rectangular block of pixels.width, height - Specify the dimensions of the pixel rectangle,width and height of one correspond to a single pixel.format- Specifies the format of the pixel data:GL COLOR INDEX, GL STENCIL INDEX,GL DEPTH COMPONENT,GL RED, GL GREEN, GL BLUE, GL ALPHA,GL RGB, GL RGBA, (GL BGR, GL BGRA),GL LUMINANCE, GL LUMINANCE ALPHA.type- Specifies the data type of the pixel data:GL UNSIGNED BYTE, GL BYTE, GL BITMAP,GL UNSIGNED SHORT, GL SHORTGL UNSIGNED INT, GL INT GL FLOAT.pixels- Pointer to location where pixel data is written.

void glDrawPixels( GLsizei width, GLsizei height,GLenum format, GLenum type,const GLvoid *pixels )width, height - Specify the dimensions of the pixel rectanglethat will be written into the frame buffer.format- Specifies the format of the pixel data.type- Specifies the data type for pixels.pixels- Specifies a pointer to the pixel data.void glCopyPixels( GLint x, GLint y, GLsizei width, GLsizei height,GLenum type )x, y- Specify the window coordinates of the lower left cornerof the region of pixels to be copied.width, height - Specify the dimensions of the rectangular region of pixelsto be copied.type- Specifies whether color values, depth values, or stencil:GL COLOR, GL DEPTH, and GL STENCIL

void glDrawBuffer( GLenum mode )mode -Specifies up to four color buffers to be drawn into.GL NONE, GL FRONT LEFT, GL FRONT RIGHT,GL BACK LEFT, GL BACK RIGHT, GL FRONT, GL BACK,GL LEFT, GL RIGHT, GL FRONT AND BACK,GL AUXi, where i is between 0 and GL AUX BUFFERS -1(use glGet to query the number of available aux buffers.)The default value is GL FRONT for single-buffered contexts,and GL BACK for double-buffered contexts.void glLogicOp( GLenum opcode )opcode - Specifies a symbolic constant that selects a logical operation.GL CLEAR, GL SET, GL COPY, GL COPY INVERTED,GL NOOP, GL INVERT, GL AND, GL NAND, GL OR,GL NOR, GL XOR, GL EQUIV, GL AND REVERSE,GL AND INVERTED, GL OR REVERSE, and GL OR INVERTED.glEnable(GL COLOR LOGIC OP)

void glBlendFunc( GLenum sfactor, GLenum dfactor )sfactor - Specifies how the red, green, blue, and alpha source-blendingfactors are computed.Nine symbolic constants are accepted:GL ZERO, GL ONE, GL DST COLOR,GL ONE MINUS DST COLOR, GL SRC ALPHA,GL ONE MINUS SRC ALPHA, GL DST ALPHA,GL ONE MINUS DST ALPHA, GL SRC ALPHA SATURATE.dfactor - Specifies how the red, green, blue, and alpha destination blendingfactors are computed.Eight symbolic constants are accepted:GL ZERO, GL ONE, GL SRC COLOR,GL ONE MINUS SRC COLOR, GL SRC ALPHA,GL ONE MINUS SRC ALPHA, GL DST ALPHA,GL ONE MINUS DST ALPHA.glEnable(GL BLEND)

void glPixelStoref( GLenum pname, GLfloat param )void glPixelStorei( GLenum pname, GLint param )pname - Specifies the symbolic name of the parameter to be set.Six values affect the packing of pixel data into memory:GL PACK SWAP BYTES, GL PACK LSB FIRST,GL PACK ROW LENGTH, GL PACK SKIP PIXELS,GL PACK SKIP ROWS, and GL PACK ALIGNMENT.Six more affect the unpacking of pixel data from memory:GL UNPACK SWAP BYTES, GL UNPACK LSB FIRST,GL UNPACK ROW LENGTH, GL UNPACK SKIP PIXELS,GL UNPACK SKIP ROWS, and GL UNPACK ALIGNMENT.param - Specifies the value that pname is set to.void glPixelZoom( GLfloat xfactor, GLfloat yfactor )xfactor, yfactor - Specify the x and y zoom factors for pixel write operations.

void glPixelTransferf( GLenum pname, GLfloat param )void glPixelTransferi( GLenum pname, GLint param )pname - Specifies the symbolic name of the pixel transfer parameter to be set.GL MAP COLOR, GL MAP STENCIL, GL INDEX SHIFT,GL INDEX OFFSET,GL RED SCALE, GL RED BIAS, GL GREEN SCALE,GL GREEN BIAS, GL BLUE SCALE, GL BLUE BIAS,GL ALPHA SCALE, GL ALPHA BIAS, GL DEPTH SCALE, orGL DEPTH BIAS.param - Specifies the value that pname is set to.void glPixelMapfv( GLenum map, GLint mapsize, const GLfloat *values )void glPixelMapuiv( GLenum map, GLint mapsize, const GLuint *values )void glPixelMapusv( GLenum map, GLint mapsize, const GLushort *valuesmap - Specifies a symbolic map name.GL PIXEL MAP I TO I, GL PIXEL MAP S TO S, GL PIXEL MAP I TO R,GL PIXEL MAP I TO G, GL PIXEL MAP I TO B, GL PIXEL MAP I TO A,GL PIXEL MAP R TO R,GL PIXEL MAP G TO G,GL PIXEL MAP B TO B,GL PIXEL MAP A TO A.mapsize - Specifies the size of the map being defined.values - Specifies an array of mapsize values.

ConvolutionHistogramMinmaxColor Matrix

Textures MappingCombinare le capacità dellaVertex Pipeline e Pixel PipelineDisegnare imagini di altodettaglio e realismo senzacomplicare le geometrieUna Texture 2D è come una pelleattaccata ad una superficeEsistono texture 1D e 3D

Texture Coordinates (S,T)(anche S,T,U,Q)S(1, 1)(1, 0)1/height(0,0)1/width(0, 1)T

Mappatura dallo spazio 3D (x,y,z) in (s,t)s f(x,y,z)t f(x,y,z)Sui poligoni vengono specificate lecoordinate (s,t) per ogni verticeIl resto è per interpolazione

Applicare una textureSpecificare i dati della textureSpecificare come viene applicata aisingoli pixelAttivare texturingFornire coordinate di texture per ognivertice

void init model() {GLubyte* checkImage;int checkImageWidth 64;int checkImageHeight 64;/* unpack: memory - opengl single byte align */glPixelStorei(GL UNPACK ALIGNMENT, 1);/* make texture */checkImage make2DCheckImage(checkImageWidth, checkImageHeight, 8);/* Set texture parameters */glTexParameteri(GL TEXTURE 2D,glTexParameteri(GL TEXTURE 2D,glTexParameteri(GL TEXTURE 2D,glTexParameteri(GL TEXTURE 2D,GL TEXTURE WRAP S, GL REPEAT);GL TEXTURE WRAP T, GL REPEAT);GL TEXTURE MAG FILTER, GL NEAREST);GL TEXTURE MIN FILTER, GL NEAREST);/* load texture */glTexImage2D(GL TEXTURE 2D, 0, GL RGBA,checkImageWidth, checkImageHeight,0, GL RGBA, GL UNSIGNED BYTE, checkImage);}

void display model() {/* enagle texture, and texture draw mode */glEnable(GL TEXTURE 2D);glTexEnvf(GL TEXTURE ENV, GL TEXTURE ENV MODE, GL REPLACE);/* Draw geometry with texture coords */glBegin(GL QUADS);glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0.0);glTexCoord2f(0.0, 1.0); glVertex3f(1.0, -1.0, 0.0);glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, 0.0);glTexCoord2f(1.0, 0.0); glVertex3f(-1.0, 1.0, ;glVertex3f(-0.7071, -1, 0.7071);glVertex3f(0.7071, -1, -0.7071);glVertex3f(0.7071, 1, -0.7071);glVertex3f(-0.7071, 1, 0.7071);/* Disable texture */glDisable(GL TEXTURE 2D);}

GLubyte* make2DCheckImage(int w, int h, int step) {GLubyte fgcolor[4] { 255, 255, 0, 255 };GLubyte bgcolor[4] { 255, 0, 0 ,255};int i,j;int clen 4;GLubyte* image;/* Allocate memory */image (unsigned char*)malloc(sizeof(GLubyte)*w*h*clen);if(!image) {fprintf(stderr, "Memory Allocation Error\n");return NULL;}/* Make checkboard pattern */for(i 0;i w;i ) {for(j 0;j h;j ) {if(((i / step) % 2) ((j / step) % 2))memcpy(image (i*w j)*clen,fgcolor,clen);else memcpy(image (i*w j)*clen,bgcolor,clen);}}return image;}

Specificare Texture 2Dvoid glTexImage2D( GLenum target, GLint level, GLint components,GLsizei width, GLsizei height, GLint border,GLenum format, GLenum type, const GLvoid *pixels )target - Specifies the target texture.GL TEXTURE 2D, GL PROXY TEXTURE 2D, GL TEXTURE CUBE.level - Specifies the level-of-detail number. Level 0 is the base image level.Level n is the nth mipmap reduction image.components - Specifies the number of color components in the texture.Must be 1, 2, 3, or 4. (OpenGL 1.1 Internal Format)LUMINANCE, LUMINANCE ALPHA, RGB, RGBA, .width - Specifies the width of the texture image.Must be 2n 2 ( border ) for some integer n.height - Specifies the height of the texture image.Must be 2m 2 ( border ) for some integer m.border - Specifies the width of the border. Must be either 0 or 1.format - Specifies the format of the pixel data.GL COLOR INDEX, GL RED, GL GREEN .type - Specifies the data type of the pixel data.GL UNSIGNED BYTE, GL BYTE, GL BITMAP, .pixels - Specifies a pointer to the image data in memory.

Specificare Texturevoid glTexImage3D( enum target, int level, int internalformat,sizei width, sizei height, sizei depth, int border,enum format, enum type, void *data );void glTexImage1D( enum target, int level,int internalformat, sizei width, int border,enum format, enum type, void *data );Specificare Texture da buffer videovoid CopyTexImage2D( enum target, int level,enum internalformat, int x, int y, sizei width,sizei height, int border );void CopyTexImage1D( enum target, int level,enum internalformat, int x, int y, sizei width,int border );

Aggiornare una parte di una texturevoid TexSubImage3D( enum target, int level, int xoffset,int yoffset, int zoffset, sizei width, sizei height,sizei depth, enum format, enum type, void *data );void TexSubImage2D( enum target, int level, int xoffset,int yoffset, sizei width, sizei height, enum format,enum type, void *data );void TexSubImage1D( enum target, int level, int xoffset,sizei width, enum format, enum type, void *data );void CopyTexSubImage3D( enum target, int level,int xoffset, int yoffset, int zoffset, int x, int y,sizei width, sizei height );void CopyTexSubImage2D( enum target, int level,int xoffset, int yoffset, int x, int y, sizei width,sizei height );void CopyTexSubImage1D( enum target, int level,int xoffset, int x, int y, sizei width );

Oggetti Texturevoid glGenTextures( sizei n, uint *textures );Chiedi “n” identificatori di oggetti texture dal render.Gli identificatori verranno messi nell’array puntato da “textures”.void glBindTexture( enum target, uint texture );Rendi corrente la “texture”void glDeleteTextures( sizei n, uint *textures );Assegna i “n” identificatori puntati da “textures” come liberi.Altre funzioni:void GetTexEnv{if}v( enum env, enum value, T data );void GetTexGen {ifd}v( enum coord, enum value, T data );void GetTexParameter{if}v( enum target, enum value, T data );void GetTexLevelParameter {if}v( enum target,int lod,enum value, T data );boolean AreTexturesResident( sizei n, uint *textures, boolean*residences );void PrioritizeTextures( sizei n, uint *textures, clampf *priorities );

Parametri Texturevoid glTexParameterf( GLenum target, GLenum pname, GLfloat param )void glTexParameteri( GLenum target, GLenum pname, GLint param )void glTexParameterfv( GLenum target, GLenum pname,const GLfloat *params )void glTexParameteriv( GLenum target, GLenum pname,const GLint *params )target - Specifies the target texture:GL TEXTURE 1D GL TEXTURE 2D GL TEXTURE 3Dpname - Specifies the symbolic name of a single-valued texture parameter:GL TEXTURE MIN FILTER, GL TEXTURE MAG FILTER,GL TEXTURE WRAP S GL TEXTURE WRAP TGL TEXTURE BORDER COLORparam(s) - Specifies the value of pname

Minification and MagnificationMipMapping

Scaling a mipmap automaticheint gluBuild2DMipmaps( GLenum target, GLint components,GLint width, GLint height,GLenum format, GLenum type, void *data )target - target texture. Must be GL TEXTURE 2D.components - color components in the texture. Must be 1, 2, 3, or 4.width, height - width and height, respectively, of the texture image.format - format of the pixel data:GL COLOR INDEX, GL RED, GL GREEN, . GL RGB, GL RGBA, .type - data type for data:GL UNSIGNED BYTE, GL BYTE, .data - pointer to the image data in memoryint gluScaleImage( GLenum format, GLint widthin, GLint heightin,GLenum typein, const void *datain,GLint widthout, GLint heightout,GLenum typeout, void *dataout )

Altri parametri( 1.1 non spiegati)

Modalità disegno Texturevoid glTexEnvf( GLenum target, GLenum pname, GLfloat param )void glTexEnvi( GLenum target, GLenum pname, GLint param )void glTexEnvfv( GLenum target, GLenum pname, const GLfloat *params )void glTexEnviv( GLenum target, GLenum pname, const GLint *params )target - Specifies a texture environment. Must be GL TEXTURE ENV.pname - Specifies the symbolic name of a single-valued texture environment parameter.GL TEXTURE ENV MODE, GL TEXTURE ENV COLORparam - Specifies a single symbolic constant:GL MODULATE, GL DECAL, or GL BLEND.GL REPLACEGL DECALGL BLENDreplace pixel color with texture colorreplace pixel color with texture color, modulated by alphaC Cf(1-Ct) CcCt,Cf is the pixel color, Ct is the texture color,and Cc is Texture Env ColorGL MODULATEC CfCt(altri in OpenGL 1.1 )

Tutor

Trasformazioni/* enter texture matrix mode */glMatrixMode(GL TEXTURE);glRotate(.);/* .other matrix manipulations *//* back to modelview mode */glMatrixMode(GL MODELVIEW);

Assegnazione Coordinate TextureAssegnazione manualeCoordinate di texture del prossimo verticevoid TexCoord {1234}{sifd}( T coords );void TexCoord {1234}{sifd}v( T coords );Da array:void TexCoordPointer( int size, enum type, sizei stride,void *pointer );Si possono usare coordinate superficie(u,v) (s,t)Molto dipendente dall’effetto voluto

Texture “automatiche”Texture per effetti comuniCoordinate (u,v) a seconda della distanzadi un punto rispetto un pianoSia in coordinate modello che eye

void glTexGend( GLenum coord, GLenum pname, GLdouble param )void glTexGenf( GLenum coord, GLenum pname, GLfloat param )void glTexGeni( GLenum coord, GLenum pname, GLint param )coord - texture coordinate:GL S, GL T, GL R, or GL Q.pname - texture-coordinate generation function.GL TEXTURE GEN MODE.param - single-valued texture generation parameter:GL OBJECT LINEAR, GL EYE LINEAR, or GL SPHERE MAP.void glTexGendv( GLenum coord, GLenum pname, const GLdouble *params )void glTexGenfv( GLenum coord, GLenum pname, const GLfloat *params )void glTexGeniv( GLenum coord, GLenum pname, const GLint *params )coord - texture coordinate:GL S, GL T, GL R, or GL Q.pname - texture-coordinate generation function parameter name:GL OBJECT PLANE, or GL EYE PLANE.params - coefficients for the texture-coordinate generation function.Eg: Plane coefficents

struct Texture {GLuint texName;char *filename;int w;int h;};struct Texture textures[] { { 0, "checker.ppm" , 0, 0 },{ 0, "camuflage.ppm", 0, 0 },{ 0, "flatland.ppm", 0, 0 },{ 0, "logo.ppm", 0, 0 },{ 0, "swirl.ppm", 0, 0 },{ 0, "twirl.ppm", 0, 0 },{ 0, "heightmap.ppm", 0, 0 },{ 0, "land.ppm", 0, 0 },{ 0, "tunket.ppm", 0, 0 },{ 0, "marble.ppm", 0, 0 },{ 0, "fishermen.ppm", 0, 0 },{ 0, "marble.ppm", 0, 0 },{ 0, "opengl.ppm", 0, 0 } };int n textures 13;int cur texture 0;

void init model() {int i;GLubyte *image;for(i 0; i n textures; i ) {image (textures[i].h));glGenTextures(1, &(textures[i].texName));glBindTexture(GL TEXTURE 2D, textures[i].texName);glTexParameteri(GL TEXTURE 2D, GL TEXTURE WRAP S, GL REPEAT);glTexParameteri(GL TEXTURE 2D, GL TEXTURE WRAP T, GL REPEAT);glTexParameteri(GL TEXTURE 2D, GL TEXTURE MAG FILTER,GL NEAREST MIPMAP LINEAR);glTexParameteri(GL TEXTURE 2D, GL TEXTURE MIN FILTER,GL NEAREST MIPMAP LINEAR);gluBuild2DMipmaps( GL TEXTURE 2D, 3,textures[i].w, textures[i].h,GL RGB, GL UNSIGNED BYTE, image );}}

void rotateprofile(GLfloat profile[][2], int n profile, int n) {./* For each segment */for(i 0;i n profile-1;i ) {/* For each slice */for(j 0;j n;j ) {/* Calculate angles */./* Calculate normal of profile */./* Enable Textures */glEnable(GL TEXTURE 2D);glBindTexture(GL TEXTURE 2D, textures[cur texture].texName);glTexEnvf(GL TEXTURE ENV, GL TEXTURE ENV MODE, GL MODULATE);select tex mode();/* Draw face, updating the angle */glBegin(GL POLYGON);glPolygonMode(GL FRONT,GL FILL);

/* first point of profile projected on first angle */glTexCoord2f(angle0 / (2 * M PI),1 - ((GLfloat) i)/((GLfloat) n profile));glNormal3f(.);glVertex3f( profile[i][0] * cos(angle0),profile[i][1], profile[i][0] * sin(angle0) );/* second point of profile projected on first angle */glTexCoord2f(angle0 / (2 * M PI),1 - ((GLfloat) (i 1))/((GLfloat) n profile));glNormal3f(.);glVertex3f( profile[i 1][0] * cos(angle0),profile[i 1][1], profile[i 1][0] * sin(angle0) );/* second point of profile projected on second angle */glTexCoord2f(angle1r / (2 * M PI),1 - ((GLfloat) (i 1))/((GLfloat) n profile));glNormal3f(.);glVertex3f( profile[i 1][0] * cos(angle1),profile[i 1][1], profile[i 1][0] * sin(angle1));/* first point of profile projected on second angle */glTexCoord2f(angle1r / (2 * M PI),1 - ((GLfloat) i)/((GLfloat) n profile));glNormal3f( . );glVertex3f( profile[i][0] * cos(angle1),profile[i][1], profile[i][0] * sin(angle1));glEnd();/* Disable textures */deselect tex mode();glDisable(GL TEXTURE 2D);

enum { TxV, LINEAR, LINEAR EYE, LIN S EYE T, EYE S LIN T, SPHERE }tex mode TxV;void select tex mode() {GLfloat xy plane[] { 0, 0, 1, -1 };GLfloat xz plane[] { 0, 1, 0, 1 };switch(tex mode) {case TxV:glDisable(GL TEXTURE GEN S);glDisable(GL TEXTURE GEN T);break;case LINEAR:glEnable(GL TEXTURE GEN S);glEnable(GL TEXTURE GEN T);glTexGeni(GL S,GL TEXTURE GEN MODE,GL OBJECT LINEAR);glTexGeni(GL T,GL TEXTURE GEN MODE,GL OBJECT LINEAR);glTexGenfv(GL S,GL OBJECT PLANE,xz plane);glTexGenfv(GL T,GL OBJECT PLANE,xy plane);break;case LINEAR EYE:glEnable(GL TEXTURE GEN S);glEnable(GL TEXTURE GEN T);glTexGeni(GL S,GL TEXTURE GEN MODE,GL EYE LINEAR);glTexGeni(GL T,GL TEXTURE GEN MODE,GL EYE LINEAR);glTexGenfv(GL S,GL OBJECT PLANE,xz plane);glTexGenfv(GL T,GL OBJECT PLANE,xy plane);break;

case LIN S EYE T:glEnable(GL TEXTURE GEN S);glEnable(GL TEXTURE GEN T);glTexGeni(GL S,GL TEXTURE GEN MODE,GL OBJECT LINEAR);glTexGeni(GL T,GL TEXTURE GEN MODE,GL EYE LINEAR);glTexGenfv(GL S,GL OBJECT PLANE,xz plane);glTexGenfv(GL T,GL OBJECT PLANE,xy plane);break;case EYE S LIN T:glEnable(GL TEXTURE GEN S);glEnable(GL TEXTURE GEN T);glTexGeni(GL S,GL TEXTURE GEN MODE,GL EYE LINEAR);glTexGeni(GL T,GL TEXTURE GEN MODE,GL OBJECT LINEAR);glTexGenfv(GL S,GL OBJECT PLANE,xz plane);glTexGenfv(GL T,GL OBJECT PLANE,xy plane);break;case SPHERE:glEnable(GL TEXTURE GEN S);glEnable(GL TEXTURE GEN T);glTexGeni(GL S,GL TEXTURE GEN MODE,GL SPHERE MAP);glTexGeni(GL T,GL TEXTURE GEN MODE,GL SPHERE MAP);}}void deselect tex mode() {glDisable(GL TEXTURE GEN S);glDisable(GL TEXTURE GEN T);}

GLubyte* glmReadPPM(char* filename, int* width, int* height){FILE* fp;int i, w, h, d;unsigned char* image;char head[70];/* max line 70 in PPM (per spec). */fp fopen(filename, "rb");if (!fp) {perror(filename);return NULL;}/* grab first two chars of the file and make sure that it has thecorrect magic cookie for a raw PPM file. */fgets(head, 70, fp);if (strncmp(head, "P6", 2)) {fprintf(stderr, "%s: Not a raw PPM file\n", filename);fclose(fp);return NULL;}

/* grab the three elements in the header (width, height, maxval). */i 0;while(i 3) {fgets(head, 70, fp);if (head[0] '#')/* skip comments. */continue;if (i 0)i sscanf(head, "%d %d %d", &w, &h, &d);else if (i 1)i sscanf(head, "%d %d", &h, &d);else if (i 2)i sscanf(head, "%d", &d);}/* Allocate memory */image (unsigned char*)malloc(sizeof(unsigned char)*w*h*3);/* grab all the image data in one fell swoop. */fread(image, sizeof(GLubyte), w*h*3, fp);fclose(fp);*width w;*height h;return image;}

Concetti avanzatiCube TexturesMultitextureTexture da rendering su buffer AUXOmbreRiflessiTexture combining functions

Masking b M M*b Normalize Enable/Disable TexGen OBJECT_LINEAR TexGen EYE_LINEAR . Informatica Grafica AA 2006 Esercitazione 23/3/2005 Portuesi Simone. Menu del giorno Immagini e Textures Immagini OpenGL Bitmaps Pixmaps Buffers Textures Definizione Parametri Texture Coordinates. Pixel Data Pipeline Per ! Vertex Operations Primitive Assembly .