0

Hi I'm working to create a space environment with a ship inside.But after the creation of the skybox (no errors) I put my ship inside but it hasnt colour. It's something like white-black Here is the project

I did(modeled) the ship with OPENSCAD and after with MESHLAB I exported it into .OBJ format. I load it inside the source code but he hasn't the texture/colour . That my ship in Meshlab : Ship Meshlab

I need to know only I have to add something about color in the code or it's error in input. What this?

If you need I post the code, but if is somthing normal this error explain me, anyway I'm a little newbie in opengl, so be patient, thank you

EDIT :

Look my .obj file in windows: SHip meshlab

And the same project in ubuntu : ship meshlab ubuntu

What's this difference?

Anyway the openscad code :

module navicella(){
  $fn=100;  
    rotate([0,180,270]){
    union(){
         rotate([270,180,0]){   
              rotate([90,0,0])
                cylinder(50,7,10,center=true);

              intersection(){
               translate([0,-25,0])    
                sphere(10);  
               translate([0,-25,0])
                cube(19,center=true);    
              } 
              difference(){
               translate([0,35,0])
                cube([10,15,15],center=true);    
               translate([0,40,0])    
                sphere(13);
              }  

              translate([5,-10,0])rotate([90,0,70])  
                cube([35,1,15],center=true);
              translate([-2,0,0])rotate([90,0,95])  
                cube([50,1,10],center=true);

              translate([0,3,6])rotate([0,-15,90])  
                cube([40,1,20],center=true); 
              translate([0,3,-6])rotate([0,15,90])  
                cube([40,1,20],center=true); 

              translate([0,-35,0])rotate([90,0,0])
                cylinder(10,5,0,center=true);
              translate([0,20,0])rotate([0,90,0])  
                cube([45,1,2],center=true);
              translate([0,25,0]) rotate([90,0,0])
                cylinder(5,4,7,center=true); 
        }    
    }
}
}
navicella();
Teshtek
  • 1,212
  • 1
  • 12
  • 20
  • Does your OBJ model contain normals? You need normals (not only vertices and faces) to shade the OBJ. Also, how are you rendering the OBJ? Place paste the relevant code. – Dan Jun 04 '16 at 19:53
  • From the looks of your Meshlab screenshot the mesh seems quite messed up. Just look at the dorsal fin, the edges. Either there's some serious Z fighting going on, or the winding corrupt, or indices mixed between backside and front side faces. Can you also post your OPENSCAD sources? The OBJ is probably too much to paste (sensibly) but having the SCAD files we can at least try to reproduce. – datenwolf Jun 05 '16 at 14:06
  • I edited the post. Look up – Teshtek Jun 05 '16 at 17:57

1 Answers1

4

Looks like you have forgot to disable all used textures that are not used by your model. That is very common mistake (I do it all the time still today).

What is probably happening?

  1. You rendered skybox or any object with textures

    So for example GL_CUBE_MAP and or GL_TEXTURE_2D are enabled. Now when you start rendering your mesh that does not contain texture the textures are still enabled. So for every fragment/pixel GL will always sample the last set texture coordinate from last binded texture in all of the enabled texture targets and combine color according to GL settings.

    So if you model does not contain texture coordinates GL will use the last set one. That is usually in corner area where black border is ... or you are just in some dark region of texture. Also if you unbind textures that only means you bind default texture 0 which is usually black.

    To test/remedy this just callglDisable(GL_....); for all previously used texture targets. If it helps you know where the problem is.

    Also if your object contains texture coordinates and texture is not loaded properly (like wrong file name/path) then the result is usually black.

  2. Missing or negative normals while rendering with lighting enabled

    Does not looks like it but it could be also the reason. If your model has wrong or no normals then the lighting computation result in wrong lighting. If the object is always dark even if you rotate it the the normals are negated (facing the other way) and you should change the front face for lighting/material or negate the normals.

    If the color intensity is changing with rotation then your object has probably no normal and again the last set normal is used (from previous rendering). In such case either compute normals for the object (via cross product) or disable lighting for that object.

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Give me a moment I'm checking, anyway I added other information about the .obj file, look up . – Teshtek Jun 05 '16 at 18:01
  • @Teshtek we need also to see the obj file ... look inside it in a notepad or something and find what kind of lines it has. Starting characters tells you what kind of data it is so see if it has lines starting with `v`,`vn`,`vt`,`f` and copyat least 1 line of each kind here (important is how many numbers and `/` are per line. If the behavior is different between OS then it may be related to some different settings or even gfx driver issue. The views does not look like your App from the first image of yours so I assume it is some tool instead perhaps with custom GLSL code of yours? – Spektre Jun 06 '16 at 06:37
  • @Teshtek so if you use your own GLSL shaders copy their source here and also add info about your GFX card and drivers used for win and linux (in case of a driver issue). – Spektre Jun 06 '16 at 06:40
  • I solve it, it was about the material in .obj file. I add the .mtl file with some colors, then i call it in .obj file. Now it works. ANd olso in meshlab colored by face – Teshtek Jun 06 '16 at 15:28