Note that there are some explanatory texts on larger screens.

plurals
  1. POnormalising vertex and normal coordinates Open GL ES 2.0
    primarykey
    data
    text
    <p>I have a model created in blender and exported to an .obj file. I have written a parser that reads in the co ordinates for of the vertices textures and normals. I have been dividing all the co-ordinats by a constant applicable to the program to reduce the size of the mode so that it fits the screen(this is a temporary measure). This works fine except for the lighting which doesn't work, Im left with a black 3D object when it should be coloured. After researching it on the web, I think this could be because the normals aren't of length one? If this is true how can I scale my co-ordinates so that they fit the screen and get the lighting to work?</p> <p>Vertex Shader</p> <pre><code>// // Created by Jake Cunningham on 13/10/2012. // Copyright (c) 2012 Jake Cunningham. All rights reserved. // attribute vec4 position; attribute vec3 normal; varying lowp vec4 colorVarying; uniform mat4 modelViewProjectionMatrix; uniform mat3 normalMatrix; attribute vec2 TextCo; varying vec2 textCoOut; void main() { vec3 eyeNormal = normalize(normalMatrix * normal); vec3 lightPosition = vec3(0.0, 0.0, 1.0); vec4 diffuseColor = vec4(0.4, 0.4, 1.0, 1.0); float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition))); colorVarying = diffuseColor * nDotVP; gl_Position = modelViewProjectionMatrix * position; textCoOut = TextCo; } </code></pre> <p>Fragment Shader:</p> <pre><code>// Created by Jake Cunningham on 13/10/2012. // Copyright (c) 2012 Jake Cunningham. All rights reserved. // varying lowp vec4 colorVarying; varying lowp vec2 textCoOut; uniform sampler2D texture; void main() { gl_FragColor = colorVarying * texture2D(texture, textCoOut); } </code></pre> <p>code from view controller.</p> <pre><code>glEnable(GL_DEPTH_TEST); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glGenVertexArraysOES(1, &amp;_vertexArray); glBindVertexArrayOES(_vertexArray); glGenBuffers(1, &amp;_vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer); glBufferData(GL_ARRAY_BUFFER, loader.currentCountOfVerticies * sizeof(GLfloat) * 3, arrayOfVerticies, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 12, BUFFER_OFFSET(0)); glGenVertexArraysOES(1, &amp;_normalArray); glBindVertexArrayOES(_normalArray); glGenBuffers(1, &amp;_normalBuffer); glBindBuffer(GL_ARRAY_BUFFER, _normalBuffer); glBufferData(GLKVertexAttribNormal, loader.currentCountOfNormals * sizeof(GLfloat) * 3,loader.arrayOfNormals , GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribNormal); glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 12, BUFFER_OFFSET(0)); glGenVertexArraysOES(1, &amp;_textureArray); glBindVertexArrayOES(_textureArray); glGenBuffers(1, &amp;_textureBuffer); glBindBuffer(GL_ARRAY_BUFFER, _textureBuffer); glBufferData(GL_ARRAY_BUFFER, loader.currentCountOfTextureCoordinates * sizeof(GLfloat) * 2, loader.arrayOftextureCoOrdinates, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribTexCoord0); glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, 8, BUFFER_OFFSET(0)); glBindVertexArrayOES(0); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload