c++ - Blank Screen in OpenGL and Glut -


when attempting draw cube, get, instead, blank screen. screen background of glclearcolor.

my code in many files can't post here, i've placed on github. you'll want @ it. it's visual studio 2012 file source there ide. though incomplete, here snippets:

edit: able see me shapes, lightless. when use made normals in glutsolidteapot, looks flat. also, though specify far cutting plane 1000, shapes disappear far before that. i've updated code more recent.

codeindigo.cpp

// entry point! // code indigo 3d mystery game. readme more information.  #include "codeindigo.h" #include <iostream>   void box_update (const int& frame, const object& self) {     return; }  void update (int frame) {     if (indigo::keys ['w'])     {         indigo::current_world.camera.move (0.05);     }     if (indigo::keys ['s'])     {         indigo::current_world.camera.move (-0.05);     }     if (indigo::keys ['a'])     {         indigo::current_world.camera.move (0.0, -0.05);     }     if (indigo::keys ['d'])     {         indigo::current_world.camera.move (0.0, 0.05);     }     if (gl_no_error != glgeterror ())     {         std::cout << "error: " << glgeterror () << std::endl;     }     if (indigo::keys ['3'])     {         camera camera = indigo::current_world.camera;         std::cout << camera.x << ", " << camera.y << ", " << camera.z << " looking @ "             << camera.eye.get_x () << ", " << camera.eye.get_y () << ", " << camera.eye.get_z () << std::endl;     } }  void mouse_moved (int x, int y) {     static const float sensitivity = 0.5;     indigo::current_world.camera.eye.add_direction (0.0, x * sensitivity,         y * -1 * sensitivity);     std::cout << x << ", " << y << std::endl; }  int main(int argc, char ** argv) {     indigo::initialize (argc, argv, " ~ code indigo",         800, 600, true, 60, indigo::sky_color, 60);     mesh box = mesh::sphere (0.5);     object add = object(0.0, 0.0, -1.0, box, indigo::white_color, 40.0f, box_update);     int object = indigo::current_world.add_object (add);     indigo::update_function = update;     indigo::relative_mouse_moved_function = mouse_moved;     indigo::current_world.lighting.add_light (0.0, 2.0, 0.0);     indigo::current_world.camera.place (0.0, 0.0, 0.0);     indigo::current_world.camera.eye.set_direction (1.0, 90.0, -2.8);     indigo::run ();     return (0); } 

indigo::initialize

// initializes window , rendering matrices. void initialize (int argc, char ** argv, const char * window_name,     const int& window_width, const int& window_height, const bool& fullscreen,     int field_of_view, float * background, int max_framerate) {     glutinit (&argc, argv);     glutinitdisplaymode (glut_rgba | glut_double | glut_depth);     glutinitwindowsize (window_width, window_height);     glutcreatewindow (window_name);     if (fullscreen)     {         glutfullscreen ();     }     if (background)     {         glclearcolor (background [0], background [1], background [2], 1.0);     }     else     {         glclearcolor (sky_color [0], sky_color [1], sky_color [2], 1.0);     }     frame_length_minimum = 1000 / max_framerate;     glutsetkeyrepeat (glut_key_repeat_off);     glutdisplayfunc (render);     gluttimerfunc (10, update, 0);     glutreshapefunc (reshape);     glutpassivemotionfunc (mouse_moved);     glutmousefunc (mouse_button);     glutkeyboardfunc (key_pressed);     glutkeyboardupfunc (key_released);     glmatrixmode (gl_projection);     reshape ();     glmatrixmode (gl_modelview);     glloadidentity ();     glshademodel (gl_smooth);     glenable (gl_depth_test);     return; } 

indigo::reshape

// acts when window reshapes void reshape (int width, int height) {     bool viewport = true;     if (0 == width)     {         width = glutget (glut_window_width);         viewport = false;     }     if (0 == height)     {         height = glutget (glut_window_height);         viewport = false;     }     if (viewport)     {         glviewport (0, 0, width, height);     }     glloadidentity ();     gluperspective (field_of_view,         (float) width / (float) height,         0.5, 1000.0); } 

world::render

void world::render (void) const {     // renders every object in world     glclear (gl_color_buffer_bit | gl_depth_buffer_bit);     glmatrixmode (gl_projection);     indigo::reshape ();     glmatrixmode (gl_modelview);     camera.look ();     lighting.position_lights ();     // <delete>     float full_array [] = {1.0, 1.0, 1.0, 1.0};     glmaterialfv (gl_front_and_back, gl_ambient_and_diffuse, full_array);     glmaterialfv (gl_front_and_back, gl_specular, full_array);     glmaterialf (gl_front_and_back, gl_shininess, 60.0);     glutsolidteapot (0.3);     // </delete>     (int object_id=0; object_id<objects.size (); ++object_id)     {         const_cast <object&> (objects [object_id]).render ();     }     glutswapbuffers ();     return; } 

object::render

// renders object void object::render (void) const {     float full_array [] = {1.0, 1.0, 1.0, 1.0};     glmaterialfv (gl_front_and_back, gl_ambient_and_diffuse, object_color ? object_color : full_array);     glmaterialfv (gl_front_and_back, gl_specular, full_array);     glmaterialf (gl_front_and_back, gl_shininess, object_shine);     glpushmatrix ();     gltranslatef (x, y, z);     std::vector <vertex> points = data.get_vertices ();     glbegin (render_types [data.group_size]);     (int point=0; point<points.size (); point++)     {         // when each polygon finished, calculate light normal         if ((point + 1) % (data.group_size == 0 ? 3 : data.group_size) == 0)         {             vertex 2 = points [point - 1] - points [point - 2];             vertex 3 = points [point] - points [point - 2];             glnormal3f (two.z * three.y - two.y * three.z,                 two.x * three.z - two.z * three.x,                 two.y * three.x - two.x * three.y);         }         vertex cursor = points [point];         glvertex3f (cursor.x, cursor.y, cursor.z);     }     glend ();     glpopmatrix ();     return; } 

sorry much!

the difficulty don't know whether problem lies in my:

  • setting of projection matrix `gluperspective`
  • glut thing don't know
  • drawing shape
  • else

edit: able see me shapes, lightless. when use made normals in glutsolidteapot, looks flat. also, though specify far cutting plane 1000, shapes disappear far before that. i've updated code more recent.

i agree pwny. untested code. usual causes:

  1. bad camera/object position
  2. wrong frustrum/perspective (bad znear or zfar)
  3. enabled textures without using them
  4. improper lighting/material parameters
  5. forgotten set glcolor

to check wrong

  1. disable cull_face,depth_test,gl_texture_1d,2d,...lighting,material,blend
  2. set camera , modelview defined state (unit matrix example)
  3. try render quad without cull_face @ right position , size visible
  4. after success set projection matrix perspective
    • tweak znear,zfar , quad position match scene
  5. replace quad cube
  6. after success re-enable need incrementally

p.s. idea check glerrors (may wrong entirely else)


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -