I've made a .obj reader in c++ and I've tried rendering some models. I've got the whole concept from here: https://www.youtube.com/watch?v=KMWUjNE0fYI&list=PLRIWtICgwaX0u7Rf9zkZhLoLuZVfUksDP&index=9

So I've tried to copy the export settings in blender what the guy used in the video (I'm not experienced in modelling so I had troubles because I have a newer version) and I've split every edge so they staied sharp even with the smooth shader. What my model looks like in blender: enter image description here

I'm not sure if this is a texture or lighting bug. The models that the guy provides in the video work just fine.


My drawing code is this:

shader->SetUniformMat4f("vw_matrix", viewMatrix);
glDrawElements(GL_TRIANGLES, m_Model->GetIBO().GetCount(), GL_UNSIGNED_INT, 0);

Export settings:

  • Write Normals
  • Include UVs
  • Triangulate faces
  • Objects as OBJ objects


I've added a pic how the model looks without edge split (above).

My vertex shader:

#version 400 core

in vec3 position;
in vec2 textureCoords;
in vec3 normal;

out vec2 pass_textureCoords;
out vec3 surfaceNormal;
out vec3 toLightVector;

uniform mat4 pr_matrix = mat4(1.0);
uniform mat4 vw_matrix = mat4(1.0);
uniform mat4 ml_matrix = mat4(1.0);
uniform vec3 lightPosition;

void main(void)
    vec4 worldPosition = ml_matrix * vec4(position, 1.0);
    gl_Position = pr_matrix * vw_matrix * worldPosition;
    pass_textureCoords = textureCoords;

    surfaceNormal = (ml_matrix * vec4(normal, 0.0)).xyz;
    toLightVector = lightPosition - worldPosition.xyz;
  • \$\begingroup\$ So, correct me if I'm wrong, the models that the guy in the video uses render fine with your code, but none of your own models do? \$\endgroup\$
    – Superdoggy
    Commented Aug 20, 2015 at 21:37
  • \$\begingroup\$ @Superdoggy Yes, exactly. \$\endgroup\$ Commented Aug 20, 2015 at 21:38
  • \$\begingroup\$ Okay, in blender, try selecting everything, going to the toolbar (if it's not open, press "T") and going to Shading/UVs and press "Recalculate". Can you tell me if that works? \$\endgroup\$
    – Superdoggy
    Commented Aug 20, 2015 at 21:40
  • \$\begingroup\$ Right, give me a minute please. \$\endgroup\$ Commented Aug 20, 2015 at 21:41
  • 1
    \$\begingroup\$ Okay. Just wondering. It almost looks as if some of your normals are flipped, so I was curious to see if that was the problem. Could you possibly include your drawing code and your Blender export settings into your question? It will be easier to help you if we don't have to guess. :P \$\endgroup\$
    – Superdoggy
    Commented Aug 20, 2015 at 21:51

2 Answers 2

  1. Go to edit mode
  2. Select all vertices (a)
  3. Press Ctrl + n (this recalculates all normals for all faces)

export again and see if it behaves the way you want it

If that did not work, do

  1. Go to edit mode
  2. Select all vertices (b, blender keeps a tab of the hotkeys you use and increment them by 1 for every use)
  3. Press w, select "remove doubles" (or duplicates, something to that effect)

I believe your triangles are not all clockwise (or ccw) this is the cause of the lighting rendering them differently.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .