  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Tell OpenGL the right texture coordinates for the triangles  » android » Tell OpenGL the right texture coordinates for the triangles

By : user2954525
Date : November 22 2020, 10:31 AM
I wish this helpful for you OpenGL considers a single vertex to be the combination of every attribute that describes that vertex. So, in your case, a single unit composed of a position and a texture coordinate is a vertex. They're of dimension five.
A line like: code :
``````f 2/1 3/2 4/3
``````
``````(1.000000 -1.000000 1.000000, -1.918677 2.918677)
(-1.000000 -1.000000 1.000000, -1.918677 -1.918677)
(-1.000000 -1.000000 -1.000000, 2.918677 -1.918677)
`````` ## Texture coordinate mapping how to map coordinates of 4 triangles in a square to 4 triangles in a triangle

By : B.G.
Date : March 29 2020, 07:55 AM
Hope this helps Let's consider first the case of the triangle a.
Assuming that your origin is at point 5, the coordinates of points 1 and 2 are (-x0, y0) and (x0, y0), we should have the following.
code :
``````xnew = A*x + B*y + C
ynew = D*x + E*y + F
``````
``````-x0 = -A*x0 + B*y0 + C   (1)        -x0/2 = A*x0 + B*y0 + C   (3)
y0 = -D*x0 + E*y0 + F   (2)         y0   = D*x0 + E*y0 + F   (4)

0 =  A*0  + B*0  + C   (5)
-y0 =  D*0  + E*0  + F   (6)
``````
``````xnew = 0.25*x - 0.75*(x0/y0)*y
ynew = 2*y - y0
``````
``````xnew = -0.25*x - 0.25*(x0/y0)*y
ynew = -2*y - y0
`````` ## Texture issue with drawing triangles with OpenGL for Android

By : israel ohiofudu
Date : March 29 2020, 07:55 AM
To fix the issue you can do It seems like this would be a fairly simple problem to fix, and I don't believe it's Android specific... Are you defining the UV Texture Coordinates for your object? If you don't, OpenGL will not display the texture properly. You can use either the glTexCoord3f function in immediate mode, or glTexCoordPointer if you're using C arrays. ## Do I need 4D texture coordinates to achieve perspective correct texture mapping in opengl?

By : Viktor
Date : March 29 2020, 07:55 AM
I hope this helps . I was misinformed about what glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); was used for in the fixed function pipeline. I was told that this hint should prevent the error that we're seeing above. I've since tested it myself in the fixed function pipeline and it turns out that the hint just controls the perspective correctness of the vertex transformations.
So to fix the problem above, there isn't any solution other than providing projective texture coordinates, which is the solution that most of the other SO questions I've linked to talk about. ## Opengl - texture mapping to triangles

By : PJB
Date : March 29 2020, 07:55 AM
This might help you To apply an image, as a texture, to a rectangle formed by two triangles, I am following a tutorial in open.gl/textures. , After looking at the image you posted in one of your comments: ## What are the correct texture coordinates for a quad consisting of 2 triangles

Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further I cant figure out why this is happening. I draw a quad (of 2 triangles) with the following vertices , You need two more texture vertices
0,0, 1,0, 1,1, 0,1
code :
``````glGenerateMipmap(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
``````
``````glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
``````
``````this._shaderProgram.activateProgram(camera.vpMatrix);

gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBufferObject);
gl.vertexAttribPointer(this._shaderProgram.vertexAttributeLocation, 3, gl.FLOAT, false, 0, 0);

gl.bindBuffer(gl.ARRAY_BUFFER, this._textureBufferObject); // **missing**
gl.vertexAttribPointer(this._shaderProgram.textureAttributeLocation, 2, gl.FLOAT, false, 0, 0);
`````` 