Different rendering behavior from cmd interface or ide interface

I have been trying the tutorials in: OpenGL Step by Step - OpenGL Development (ogldev.org) and all of them worked fine until tutorial 31 about point normal tessellations, it compiles and links fine but give a black screen with nothing in it, this behavior is observed from msys/mingw64 and windows power shell. Same code from Visual studio 16 community edition it displays 2 monkey heads as expected. I have noticed that before reaching tutorial 31 a couple of tutorials(can’t remember which since my main emphasis is on developing with msys/mingw) gave a black screen when run from within visual studio and the expected display from msys/mingw console.
Cannot think of any rational reason for this behavior and would appreciate any enlightening ideas…

Well to be more accurate upon closer examination some of the tutorials prior to the 31st didn’t build (27) or assertion failed(25).

Well I experimented with several .obj files as input to the mesh, some works and others not. Could it be a memory problem when the obj file is big, but still why it works in the visual studio and not from the power shell.

Well this may help getting explanation. I commented out all the texturing code associated with the materials in the .obj file and voila the 2 monkey heads appear untextured from the console as well as from VS.

Without any more information, did you check your fragment shaders to se if your textures are correctly initiated? or the material importer can be flawed.

Side note, change the background to different color to see if there are black objects there or none at all.

can you give us a little more information?

Yes I checked the fragment shader, and here it is:

#version 420 core                                                                           
const int MAX_POINT_LIGHTS = 2;                                                             
const int MAX_SPOT_LIGHTS = 2;                                                              
in vec2 TexCoord_FS_in;                                                                     
in vec3 Normal_FS_in;                                                                       
in vec3 WorldPos_FS_in;                                                                     
out vec4 FragColor;                                                                         
struct BaseLight                                                                            
    vec3 Color;                                                                             
    float AmbientIntensity;                                                                 
    float DiffuseIntensity;                                                                 
struct DirectionalLight                                                                     
    BaseLight Base;                                                                  
    vec3 Direction;                                                                         
struct Attenuation                                                                          
    float Constant;                                                                         
    float Linear;                                                                           
    float Exp;                                                                              
struct PointLight                                                                           
    BaseLight Base;                                                                  
    vec3 Position;                                                                          
    Attenuation Atten;                                                                      
struct SpotLight                                                                            
    PointLight Base;                                                                 
    vec3 Direction;                                                                         
    float Cutoff;                                                                           
uniform int gNumPointLights;                                                                
uniform int gNumSpotLights;                                                                 
uniform DirectionalLight gDirectionalLight;                                                 
uniform PointLight gPointLights[MAX_POINT_LIGHTS];                                          
uniform SpotLight gSpotLights[MAX_SPOT_LIGHTS];                                             
uniform sampler2D gColorMap;                                                                
uniform vec3 gEyeWorldPos;                                                                  
uniform float gMatSpecularIntensity;                                                        
uniform float gSpecularPower;                                                               
vec4 CalcLightInternal(BaseLight Light, vec3 LightDirection, vec3 Normal)            
    vec4 AmbientColor = vec4(Light.Color * Light.AmbientIntensity, 1.0f);
    float DiffuseFactor = dot(Normal, -LightDirection);                                     
    vec4 DiffuseColor  = vec4(0, 0, 0, 0);                                                  
    vec4 SpecularColor = vec4(0, 0, 0, 0);                                                  
    if (DiffuseFactor > 0) {                                                                
        DiffuseColor = vec4(Light.Color * Light.DiffuseIntensity * DiffuseFactor, 1.0f);
        vec3 VertexToEye = normalize(gEyeWorldPos - WorldPos_FS_in);                        
        vec3 LightReflect = normalize(reflect(LightDirection, Normal));                     
        float SpecularFactor = dot(VertexToEye, LightReflect);                                      
        if (SpecularFactor > 0) {                                                           
            SpecularFactor = pow(SpecularFactor, gSpecularPower);                               
            SpecularColor = vec4(Light.Color * gMatSpecularIntensity * SpecularFactor, 1.0f);
    return (AmbientColor + DiffuseColor + SpecularColor);                                   
vec4 CalcDirectionalLight(vec3 Normal)                                                      
    return CalcLightInternal(gDirectionalLight.Base, gDirectionalLight.Direction, Normal);  
vec4 CalcPointLight(PointLight l, vec3 Normal)                                       
    vec3 LightDirection = WorldPos_FS_in - l.Position;                                      
    float Distance = length(LightDirection);                                                
    LightDirection = normalize(LightDirection);                                             
    vec4 Color = CalcLightInternal(l.Base, LightDirection, Normal);                         
    float Attenuation =  l.Atten.Constant +                                                 
                         l.Atten.Linear * Distance +                                        
                         l.Atten.Exp * Distance * Distance;                                 
    return Color / Attenuation;                                                             
vec4 CalcSpotLight(SpotLight l, vec3 Normal)                                         
    vec3 LightToPixel = normalize(WorldPos_FS_in - l.Base.Position);                        
    float SpotFactor = dot(LightToPixel, l.Direction);                                      
    if (SpotFactor > l.Cutoff) {                                                            
        vec4 Color = CalcPointLight(l.Base, Normal);                                        
        return Color * (1.0 - (1.0 - SpotFactor) * 1.0/(1.0 - l.Cutoff));                   
    else {                                                                                  
        return vec4(0,0,0,0);                                                               
void main()                                                                                 
    vec3 Normal = normalize(Normal_FS_in);                                                  
    vec4 TotalLight = CalcDirectionalLight(Normal);                                         
    for (int i = 0 ; i < gNumPointLights ; i++) {                                           
        TotalLight += CalcPointLight(gPointLights[i], Normal);                              
    for (int i = 0 ; i < gNumSpotLights ; i++) {                                            
        TotalLight += CalcSpotLight(gSpotLights[i], Normal);                                
    FragColor = texture(gColorMap, TexCoord_FS_in.xy) * TotalLight;                         

As I said in my first message it works fine when built and run from visual studio. But try to run the same exe generated from VS in the power shell gives a black screen. Also msys/mingw64 gives the same black screen silently and no error is generated. The background color of the window is black.
I noticed that in VS the project was set for x86. I have the x64 power shell and mingw64 of course generates code for x64. Does that help bringing up an explanation.

Well the texture is a 1x1 image with data 377 377 377 that is white.
Well to correct myself the program ran fine from power shell, so it is only mingw64. Will try to make texture bigger see if this changes anything

Resizing the 1x1 texture did not change anything as expected. Next thing is to change the last line in the fragment shader

FragColor = texture(gColorMap, TexCoord_FS_in.xy) * TotalLight;                         


still the same black screen. While ignoring all texture code and setting FragColor = TotalLight yiels the 2 monkey heads…

sorry in my last message it was vec2(0.0,0.0) not vec2(1.0,1.0)

I did a little experiment with the fragment shader
1-Set FragColor = TotalLight; and comment out in the shader and in the code all statements that deal with the uniform gColorMap.
I get image 1

2- Set FragColor = vec4(1.0,1.0,1.0,1.0); and comment out in the shaders and code all statements that deal with light uniforms. I get image 2.

3- Set FragColor = texture(gColorMap, TexCoord_FS_in.xy); and reintroduce all statements in the shader and code that deal with the uniform gColorMap. I get a black screen just like the complete program, while I was hoping for same output as 2 since the texture is plain white image. Any explanation for this?

I had the normal attribute messed up. When I fixed it. Case 1 in previous post is actually as in image 3

Similarly for case 2.

Are you absolutely certain that you’re doing the same build in both cases?

A possible explanation may be that you’re doing a release build from the command line but a debug build from VS. If you have uninitialized memory, it will contain random garbage in the release build, but the debug allocator will initialize it to specific values, and that can be enough to cause this kind of difference.

Otherwise the behaviour you’re describing makes no sense at all to me.

I checked the Texture coordinates and they are all zeros. I do not have an explanation why the texture function returns a zero vector(black). I even tried to set FragColor to the complement of what is returned from the texture function as (1.0- tempColor.r, 1.0-tempColor.g, 1.0-tempColor.b, 1.0 ) where tempColor=texture(…).Still got the black screen. I then changed the monkey.obj to box.obj which is basically a cube but has different material bricks and things went fine and got image4:

Then I changed the material of the box in the mtl file to white.png the 1x1 white pixel and got something showing troubles, the boxes are drawn but not white as in image5:

Can this gives an idea about is the trouble with white.png?

Because the box.obj produced an output but not quite the right one, the bricks don’t show up and in the second the color is not white. I did the same from visual studio box with bricks texture and then white texture and got the expected results as shown in image6 and image7.

So there is a problem with either mingw64 or since I have 2 graphics card intel and nvidia and the switching between them is done by windows not the user, I cannot choose which one to use and one of them the one used with mingw64 has a driver bug while the other one used by windows is fine. Is this a plausible explanation?

Sorry for the record the graphics cards are intel and AMD not nvidia, my old laptop had an nvidia graphics card.

Thanks Hagain for your reply, indeed the visual studio build was a 32 bit debug, but when I tried a -g in mingw32 I got the same result as the release build. Not sure that this flag initializes memory to 0, I tried with the -Wuninitialized flag and got no warnings. Will try a visual studio release build, but that will take time since I have to rebuild some 3rd party libraries and will tell you what happened…

gcc’s -g flag simply enables the generation of debug information. The difference between VS “debug” and “release” builds is more substantial; in particular, release builds have optimisation enabled, debug builds don’t. That will completely change the code.

You should normally compile with all warnings enabled (-Wall -Wextra) and address any warnings that arise. For type mismatches, don’t just add casts to make the warning go away; ensure that your code doesn’t have actual aliasing bugs (these usually don’t matter when optimisation is disabled but matter when optimisation is enabled).

I compiled with -Wall -Wextra and got lots of warning but searching for alias in the output produces nothing.
Interesting to know I was able to build an x86 release build in visual studio (as opposed to the x86 debug build which runs fine) and it gave a black window for both the monkey and box .obj which is worth than mingw64 which gives a distorted bricks texture on the box and colored box for white.png texture but still a black window for monkey.obj

Well I tried the final suggestion made earlier by Goucha about changing the background color which I did not try earlier since nothing is drawn besides the 2 objects, but it turned out not to be a good idea. All the time the objects had been drawn but in black as in image 8.

So it seems that in the case of monkey the texture function in the fragment shader returns a zero vec2 but in the case of the box with white.png it makes the box colorful and with the bricks material it gets distorted??Still befuddled and need enlightening suggestions about the cause…

I forgot to add that for the visual studio release build the black windows for both box and monkey.obj gave the objects in black yes both the monkey and the box when I set the background color to red…