Created
November 19, 2011 00:40
-
-
Save davidwparker/1378211 to your computer and use it in GitHub Desktop.
OpenGL Screencast 15: Textures part 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int main(int argc,char* argv[]) | |
| { | |
| initializeGlobals(); | |
| /* screencast specific variables */ | |
| windowName = "OpenGL screenscasts 15: Textures part 2"; | |
| screencastID = 15; | |
| dim = 4; | |
| fov = 50; | |
| th = -25; | |
| ph = 15; | |
| ecX = -1.0; | |
| ecZ = -1.0; | |
| distance = 2; | |
| toggleLight = 0; | |
| toggleAxes = 0; | |
| glutInit(&argc,argv); | |
| glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); | |
| glutInitWindowSize(windowWidth,windowHeight); | |
| glutInitWindowPosition(450,350); | |
| glutCreateWindow(windowName); | |
| glutDisplayFunc(display); | |
| glutReshapeFunc(displayReshape); | |
| glutKeyboardFunc(windowKey); | |
| glutSpecialFunc(windowSpecial); | |
| initializeTextures(); | |
| redisplayAll(); | |
| glutMainLoop(); | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void drawScreencast15(void) | |
| { | |
| GLenum minfilter = GL_NEAREST; | |
| GLenum magfilter = GL_NEAREST; | |
| GLenum env = GL_MODULATE; | |
| //GLenum env = GL_REPLACE; | |
| GLenum wraps = GL_CLAMP; | |
| GLenum wrapt = GL_REPEAT; | |
| // GLenum wrapt = GL_MIRRORED_REPEAT; | |
| if (toggleLight) | |
| drawLight(); | |
| /* | |
| currentTexture = textures[TEX_CRATE]; | |
| cube(0,0,0, 1,1,1, 0); | |
| currentTexture = textures[TEX_FIRE]; | |
| cone(2,0,0, 1,1, 5); | |
| currentTexture = textures[TEX_VENUS]; | |
| sphere(0,1,1.5, 0.5,0); | |
| */ | |
| //currentTexture = textures[TEX_FIRE]; | |
| //currentTexture = textures[TEX_EARTH]; | |
| //currentTexture = textures[TEX_ICE]; | |
| //currentTexture = textures[TEX_DEFAULT]; | |
| //cylinder(-2,0,0, 1,1); | |
| //currentTexture = textures[TEX_DEFAULT]; | |
| /* | |
| * Other Texture functions/Parameters | |
| */ | |
| glEnable(GL_TEXTURE_2D); | |
| currentTexture = textures[TEX_ICE]; | |
| glBindTexture(GL_TEXTURE_2D,currentTexture); | |
| // Minification and Magnification Filters | |
| // Used to perform calculations as to how a texel corresponds to | |
| // a pixel on the screen | |
| // GLenum minfilter = GL_NEAREST | |
| // GLenum magfilter = GL_NEAREST | |
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minfilter); | |
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, magfilter); | |
| // Clamp or Repeat texture outside of [0,1] | |
| // GLenum wraps|wrapt = GL_REPEAT, GL_CLAMP, GL_CLAMP_TO_BORDER, | |
| // GL_CLAMP_TO_EDGE, GL_MIRRORED_REPEAT | |
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wraps); | |
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapt); | |
| // Specifies how texture values are combined with the color values of | |
| // the fragment being processed | |
| // GLenum env = GL_REPLACE, GL_BLEND, GL_MODULATE, GL_DECAL, | |
| // GL_COMBINE, GL_ADD | |
| glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env); | |
| // Determine the color to be used for GL_BLEND operations | |
| //glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, env_color); | |
| // | |
| //glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, border_color); | |
| glBegin(GL_QUADS); | |
| glNormal3f(0,0,1); | |
| glTexCoord2f(0,0); glVertex3f(0,0,0); | |
| glTexCoord2f(2,0); glVertex3f(1,0,0); | |
| glTexCoord2f(2,2); glVertex3f(1,1,0); | |
| glTexCoord2f(0,2); glVertex3f(0,1,0); | |
| glTexCoord2f(0,0); glVertex3f(-1,1,0); | |
| glTexCoord2f(2,0); glVertex3f(1,1,0); | |
| glTexCoord2f(2,2); glVertex3f(1,3,0); | |
| glTexCoord2f(0,2); glVertex3f(-1,3,0); | |
| glEnd(); | |
| glDisable(GL_TEXTURE_2D); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment