Note that there are some explanatory texts on larger screens.

plurals
  1. POBlank Screen in OpenGL and Glut
    primarykey
    data
    text
    <p>When attempting to draw a cube, I get, instead, a blank screen. It is a screen with the background of my <code>glClearColor</code>.</p> <p>My code is in so many files that I can't really post it all here, so I've placed it <a href="http://github.com/CosineGaming/CodeIndigo" rel="nofollow noreferrer">on Github</a>. You'll want to look at it. It's a visual studio 2012 file but all the source is there for any IDE. Though very incomplete, here are some snippets:</p> <p><strong>EDIT:</strong> I am now able to see my shapes, but they are completely lightless. Even when I use the already made normals in <code>glutSolidTeapot</code>, it looks flat. Also, even though I specify far cutting plane to be 1000, my shapes disappear far before that. I've updated my code to be more recent.</p> <p>CodeIndigo.cpp</p> <pre><code>// Entry point! // Code indigo is a 3d mystery game. Readme for more information. #include "CodeIndigo.h" #include &lt;iostream&gt; void box_update (const int&amp; frame, const Object&amp; 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 &lt;&lt; "Error: " &lt;&lt; glGetError () &lt;&lt; std::endl; } if (Indigo::keys ['3']) { Camera camera = Indigo::Current_World.camera; std::cout &lt;&lt; camera.X &lt;&lt; ", " &lt;&lt; camera.Y &lt;&lt; ", " &lt;&lt; camera.Z &lt;&lt; " looking at " &lt;&lt; camera.eye.Get_X () &lt;&lt; ", " &lt;&lt; camera.eye.Get_Y () &lt;&lt; ", " &lt;&lt; camera.eye.Get_Z () &lt;&lt; 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 &lt;&lt; x &lt;&lt; ", " &lt;&lt; y &lt;&lt; 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); } </code></pre> <p>Indigo::Initialize</p> <pre><code>// Initializes window and rendering matrices. void Initialize (int argc, char ** argv, const char * window_name, const int&amp; window_width, const int&amp; window_height, const bool&amp; fullscreen, int field_of_view, float * background, int max_framerate) { glutInit (&amp;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; } </code></pre> <p>Indigo::Reshape</p> <pre><code>// Acts for when the 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); } </code></pre> <p>World::Render</p> <pre><code>void World::Render (void) const { // Renders every object in the world glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_PROJECTION); Indigo::Reshape (); glMatrixMode (GL_MODELVIEW); camera.Look (); lighting.Position_Lights (); // &lt;DELETE&gt; 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); // &lt;/DELETE&gt; for (int Object_ID=0; Object_ID&lt;objects.size (); ++Object_ID) { const_cast &lt;Object&amp;&gt; (objects [Object_ID]).Render (); } glutSwapBuffers (); return; } </code></pre> <p>Object::Render</p> <pre><code>// Renders the 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 &lt;Vertex&gt; points = Data.Get_Vertices (); glBegin (Render_Types [Data.Group_Size]); for (int Point=0; Point&lt;points.size (); Point++) { // When each polygon is finished, calculate a light normal if ((Point + 1) % (Data.Group_Size == 0 ? 3 : Data.Group_Size) == 0) { Vertex two = points [Point - 1] - points [Point - 2]; Vertex three = 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; } </code></pre> <p>Sorry for too much code!</p> <p>The difficulty is that I don't know whether the problem lies in my:</p> <ul> <li>Setting up of the projection matrix with <code>gluPerspective</code></li> <li>Some Glut thing I don't know about</li> <li>Drawing the shape</li> <li>Anything else</li> </ul>
    singulars
    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.
 

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