17. OpenGL Texture Coordinate Generation
Examples of places you would use texture generation are: environment mapping and reflection mapping.
The very first thing that you need to do, is of course, enable the use of which texture
generation method you would like. There are four different types of textures you can generate, and they are:
GL_TEXTURE_GEN_S
GL_TEXTURE_GEN_R
GL_TEXTURE_GEN_T
GL_TEXTURE_GEN_Q
Also keep in mind that you can use
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
with paramaters such as:
GL_EYE_LINEAR
GL_OBJECT_LINEAR
GL_SPHERE_MAP
GL_REFLECTION_MAP
Each one of these is used for a different method. But I will not mention them at this point in time, I may in the future if I want to explain more in this tutorial. But every method that is used here, can be done in a GLSL shader program.
Anyway, thats it for using texture coordinate generation, if you have any questions please email me at swiftless@gmail.com
Texture coordinate generation is used when you are looking for particular effects in which it would take too long to work out the required texture coordinates all the time.
Examples of places you would use texture generation are: environment mapping and reflection mapping.
The very first thing that you need to do, is of course, enable the use of which texture
generation method you would like. There are four different types of textures you can generate, and they are:
GL_TEXTURE_GEN_S
GL_TEXTURE_GEN_R
GL_TEXTURE_GEN_T
GL_TEXTURE_GEN_Q
Also keep in mind that you can use
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
with paramaters such as:
GL_EYE_LINEAR
GL_OBJECT_LINEAR
GL_SPHERE_MAP
GL_REFLECTION_MAP
Each one of these is used for a different method. But I will not mention them at this point in time, I may in the future if I want to explain more in this tutorial. But every method that is used here, can be done in a GLSL shader program.
Anyway, thats it for using texture coordinate generation, if you have any questions please email me at swiftless@gmail.com
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. |
#include <GL/gl.h> #include <GL/glut.h> #include <windows.h> #include <stdio.h> GLuint texture; //the array for our texture GLfloat angle = 0.0; GLuint LoadTexture( const char * filename, int width, int //The following code will read in our RAW file glGenTextures( 1, &texture ); //generate the texture //here we are setting what textures to use and when. The //The qualities are (in order from worst to best) //And if you go and use extensions, you can use Anisotropic //Here we are setting the parameter to repeat the texture //Generate the texture with mipmaps void FreeTexture( GLuint texture ) void cube (void) { void display (void) { void reshape (int w, int h) { int main (int argc, char **argv) { |
hello there,
Ihave a problem .
this error:
error C2381: ‘exit’ : redefinition; __declspec(noreturn) differs c:\program files\microsoft visual studio 10.0\vc\include\stdlib.h 353 1 tex
dont let to visual stdio to run my project
what do i do???
thank for this post and thank for answering our questions.
Why is this Windows only? Works perfect in Mac OS X. I use Netbeans for C++ applications with a window. The only thing you’ve got to keep in mind is that the working directory is / and not the directory of the compiled binary.
Hi Swiftless
I’ve tried ‘OpenGL Texture Coordinate Generation’ with XCode4 but it is looking for the header file “wndows.h”. Is there anything I can do there?
Hi Reyaad,
It should be a matter of removing windows.h and then including the OpenGL and GLUT libraries in Xcode. I can assure you that this code is portable.
Cheers,
Swiftless
Hi, Swiftless.
First of all, sorry for my English.
I’ve run this code.
But it’s not like tutorial 16.
6 sides of the cube has no texture on it.
It’s like there’s a texture on the background and I see that background through this Cube.
You know like diamond.
anyway thanks for your tutorial.
Shaleh.
I am wondering about this matter too … did you found out why?
In line 79 you load the texture and in line 86 you free it. This progress repeats every frame and it should only be done once. Load when program starts and free when programs quits
Hi Bloodust,
Yes, it would be alot more efficient to load it at the start and release it when the program ends.
The new tutorials are more improved and do this instead of loading and releasing every frame. I just haven’t rewritten this one yet.
Cheers,
Swiftless
Yeah, here it is (again)!
Thank’s for the re-up! 🙂
no tutorial 🙁
btw. your other tutorials are great!
Hey,
Thanks for the heads up, I’ve done a check and the content is up, I have to find out why it has disappeared out here though.
Cheers,
Swiftless