Results 1 to 3 of 3

Thread: Object not showing (c++ )

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2017
    Location
    germany
    Posts
    16

    Object not showing (c++ )

    I am trying to make a lunar lander type game to start off opengl with, but i cant get get the object to show, if anyone could help out to why this isnt showing, it would be greatly appreciated . This is the code i have

    main
    Code :
    #include <iostream>
    #include <GL/glut.h>
    #include "Lander.h"
    #include "random.h"
     
    using namespace std;
    float startx = rnd(100, 600); float starty = rnd(350, 450); int startradius = 10;
     
    Lander lander(startx, starty, startradius);
     
    void display(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT);
    	lander.show();
    	glutSwapBuffers();
    }
     
    void main(int argc, char **argv)
    {
    	glutInit(&argc, argv);
    	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    	glutInitWindowSize(1000, 600);
    	glutInitWindowPosition(100, 100);
    	glutCreateWindow("Animation Example");
    	glClearColor(1.0, 1.0, 1.0, 0.0);
    	glutDisplayFunc(display);
    	glutMainLoop();
     
    }


    Lander.h
    Code :
    #ifndef Lander_H
    #define Lander_H
     
    class Lander
    {
    public:
    	Lander(float ix, float iy, int iradius);
    	void show();
    	void draw();
    private:
    	float x, y, radius;
    };
    #endif

    Lander.cpp

    Code :
    #include "Lander.h"
    #include<gl/glut.h>
    #include <cmath>
     
     
    Lander::Lander(float ix, float iy, int iradius)
    {
    	x = ix; y = iy; radius = iradius;
    }
     
    void Lander::show()
    {
    	glPushMatrix();
    	glTranslatef(x, y, 0);
    	glRotatef(22, 0, 0, 1);
    	glTranslatef(-x, -y, 0);
    	draw();
    	glPopMatrix();
    }
     
    void Lander::draw()
    {
    	glBegin(GL_POLYGON);		
    	const int NPOINTS = 8;
    	const float TWOPI = 2 * 3.1415927;
    	const float STEP = TWOPI / NPOINTS;
    	glColor3f(1.0, 0.0, 0.0);
    	for (float angle = 0; angle<TWOPI; angle += STEP)
    		glVertex2f(x + radius*cos(angle), y + radius*sin(angle));
    	glEnd();
     
    	glBegin(GL_LINE_LOOP);		
    	glColor3f(1.0, 0.0, 0.0);
    	glVertex2f(x - 6, y - 6);
    	glColor3f(1.0, 0.0, 0.0);
    	glVertex2f(x - 12, y - 12);
    	glEnd();
     
    	glBegin(GL_LINE_LOOP);		
    	glColor3f(1.0, 0.0, 0.0);
    	glVertex2f(x, y - 8);
    	glColor3f(1.0, 0.0, 0.0);
    	glVertex2f(x, y - 17);
    	glEnd();
    }

  2. #2
    Newbie Newbie
    Join Date
    Mar 2017
    Posts
    4
    I think you need to clear the depth buffer also:

    glClearColor(color[0], color[1], color[2], color[3]);
    glClearDepth(static_cast<GLclampd>(depth));
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  3. #3
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Try creating a double-buffered context rather than single-buffered; i.e. replace this:
    Code :
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    With this:
    Code :
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    Tutorials that create single-buffered contexts should be mercilessly wiped from the face of the earth. You see - double-buffered is not actually more difficult, it's more compatible, and weird errors like this that might put people off from continuing just won't happen.

Similar Threads

  1. Not showing the lines
    By thames in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-12-2012, 08:44 AM
  2. Texture not showing
    By shawn619 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-25-2012, 11:54 AM
  3. 3d object showing through another
    By DarkOne in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-13-2012, 04:21 PM
  4. Simple object not showing up
    By fx_beginner in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-13-2008, 05:58 PM
  5. Why isn't my cube showing up?
    By Dogcow in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 09-29-2002, 11:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean