c++ - Mapping a texture to vertices in OpenGL -
I'm trying to render techread mess with OpenGL. Currently, my main category includes a state:
-
std :: vector & lt; Vec3d & gt; Corner
-
std :: vector & lt; Faces & gt; Trap
-
std :: vector & lt; Vec3d & gt; Color
vec3d
is the implementation of 3D vectors - nothing is special - and faces
point to a class Indicates 3 integers having an upper index of meridian
.
So far, I presented my mesh with the following code (with working fine) without a texture:
Glassehed model (Params.asp? GLCMOHHH: GL_FLAT); GlEnableClientState (GL_VERTEX_ARRAY); GlEnableClientState (GL_NORMAL_ARRAY); / * This is my attempt to add text * if (_colors.size ()! = 0) {* cout & lt; & Lt; "Hello" & lt; & Lt; Endl; * Glimpseal Detectives (GL_charcher 0); * GleneL ClientState (GL_TEXTURE_COORD_ARRAY); * Gltex coder pointer (3, GL_floyet, 0, and _colors [0]. X); } * / GlNormalPointer (GL_FLOAT, 0, and Normal [0]. X); GlVertexPointer (3, GL_FLOAT, 0, & corner [0] .x); GlDrawElements (GL_TRIANGLES, mesh.size () * 3, GL_UNSIGNED_INT, & amp; net [0] .v1); GlDisableClientState (GL_VERTEX_ARRAY); GlDisableClientState (GL_NORMAL_ARRAY); GlDisableClientState (GL_TEXTURE_COORD_ARRAY);
My texture is stored in the color
as a list of floats triples between 0 and 1. However, the colors are not applicable. I read many examples of texture mapping and tried to do this with any luck. Any ideas of what I am doing wrong?
As seen from your comments, you are misusing the Open GL facility What do you want for texting means that you paste a 2D image onto a trap, for example UV-coordinates.
What you're doing to specify a color on each top, so you'll need to enable GL_COLOR_ARRAY instead of GL_TEXTURE_COORD_ARRAY and use the related functions for it.
An additional point: If you are learning scratch from OpenGL then you should consider using only the modern OpenGL (3.2 +)
To answer the last comment:
Well, I have read those colors from a text file, that was what I mean was there any way to use this kind of array to display my mesh in color?
Yes and No: You will not get the most chance when you do this. Normally a texture has several pixels, which should be mapped on face. With the top-colored colors you can apply only one color-value per top which is projected on the triangle. Take a look at how to apply texture in a web, you should be able to find many resources on the internet.
Comments
Post a Comment