Help no display

Hi i am absolutely a beginner in OpenGL. I want to make a spinning cube. Problem is its not showing a display.Please Help.Thanx in advance. A window is coming up but no picture.

How do I display code???

a bit more information would be nice. which OS are you using, are you using glut or glx or win32, maybe you can post some code, but please less than 10000 lines :wink:

#include<glut.h>
#include<iostream.h>
#include<stdlib.h>

struct MyPlate{
	float Points[4][3];
	float Color[3];

};


class MyCube{
private:

	MyPlate Sides[6];

public:

	MyCube(void);
	void EnterValue(void);
	void Spinner(void);

} *myCube;

MyCube::MyCube(void){
	
	Sides[0].Points[0][0]=1;Sides[0].Points[0][1]=1;Sides[0].Points[0][2]=-1;
	Sides[0].Points[1][0]=-1;Sides[0].Points[1][1]=1;Sides[0].Points[1][2]=-1;
	Sides[0].Points[2][0]=-1;Sides[0].Points[2][1]=1;Sides[0].Points[2][2]=1;
	Sides[0].Points[3][0]=1;Sides[0].Points[3][1]=1;Sides[0].Points[3][2]=1;


	Sides[1].Points[0][0]=1;Sides[1].Points[0][1]=-1;Sides[1].Points[0][2]=1;
	Sides[1].Points[1][0]=-1;Sides[1].Points[1][1]=-1;Sides[1].Points[1][2]=1;
	Sides[1].Points[2][0]=-1;Sides[1].Points[2][1]=-1;Sides[1].Points[2][2]=-1;
	Sides[1].Points[3][0]=1;Sides[1].Points[3][1]=-1;Sides[1].Points[3][2]=-1;
	
	
	Sides[2].Points[0][0]=1;Sides[2].Points[0][1]=1;Sides[2].Points[0][2]=1;
	Sides[2].Points[1][0]=-1;Sides[2].Points[1][1]=1;Sides[2].Points[1][2]=1;
	Sides[2].Points[2][0]=-1;Sides[2].Points[2][1]=-1;Sides[2].Points[2][2]=1;
	Sides[2].Points[3][0]=1;Sides[2].Points[3][1]=-1;Sides[2].Points[3][2]=1;


	Sides[3].Points[0][0]=1;Sides[3].Points[0][1]=-1;Sides[3].Points[0][2]=-1;
	Sides[3].Points[1][0]=-1;Sides[3].Points[1][1]=-1;Sides[3].Points[1][2]=-1;
	Sides[3].Points[2][0]=-1;Sides[3].Points[2][1]=1;Sides[3].Points[2][2]=-1;
	Sides[3].Points[3][0]=1;Sides[3].Points[3][1]=1;Sides[3].Points[3][2]=-1;

	
	
	Sides[4].Points[0][0]=-1;Sides[4].Points[0][1]=1;Sides[4].Points[0][2]=1;
	Sides[4].Points[1][0]=-1;Sides[4].Points[1][1]=1;Sides[4].Points[1][2]=-1;
	Sides[4].Points[2][0]=-1;Sides[4].Points[2][1]=-1;Sides[4].Points[2][2]=-1;
	Sides[4].Points[3][0]=-1;Sides[4].Points[3][1]=-1;Sides[4].Points[3][2]=1;

	
	Sides[5].Points[0][0]=1;Sides[5].Points[0][1]=1;Sides[5].Points[0][2]=-1;
	Sides[5].Points[1][0]=1;Sides[5].Points[1][1]=1;Sides[5].Points[1][2]=1;
	Sides[5].Points[2][0]=1;Sides[5].Points[2][1]=-1;Sides[5].Points[2][2]=1;
	Sides[5].Points[3][0]=1;Sides[5].Points[3][1]=-1;Sides[5].Points[3][2]=-1;

	
	for(int i=0;i<6;i++){
		Sides[0].Color[0]=1;
	}
	


	
}

void MyCube::EnterValue(void){

	for(int k=0;k<6;k++){
		for(int i=0;i<4;i++){
			for(int j=0;j<3;j++){
				cout<<"
 Enter The Value for  "<<i<<"  "<<j<<"  ";
				cin>>Sides[k].Points[i][j];
			}
		}
	}
}

float rotquad = 0.0;

void MyCube::Spinner(void){

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	                    // Clear  Depth Buffer
	glLoadIdentity();									// Reset The Current Modelview Matrix
	glPushMatrix();
	
//NEW//////////////////NEW//////////////////NEW//////////////////NEW////////////////

	glTranslatef(0.0f, 0.0f,-7.0f);						// Translate Into The Screen 7.0 Units
	glRotatef(rotquad,0.0f,1.0f,0.0f);					// Rotate The cube around the Y axis
	glRotatef(rotquad,1.0f,1.0f,1.0f);					
    glPopMatrix();
	glBegin(GL_QUADS);									// Draw a cube with quads

	glColor3fv(Sides[0].Color);						
		glVertex3fv(Sides[0].Points[0]);
		glVertex3fv(Sides[0].Points[1]);
		glVertex3fv(Sides[0].Points[2]);
		glVertex3fv(Sides[0].Points[3]);
		glColor3fv(Sides[1].Color);						
		glVertex3fv(Sides[1].Points[0]);
		glVertex3fv(Sides[1].Points[1]);
		glVertex3fv(Sides[1].Points[2]);
		glVertex3fv(Sides[1].Points[3]);
		glColor3fv(Sides[2].Color);						
		glVertex3fv(Sides[2].Points[0]);
		glVertex3fv(Sides[2].Points[1]);
		glVertex3fv(Sides[2].Points[2]);
		glVertex3fv(Sides[2].Points[3]);
		glColor3fv(Sides[3].Color);						
		glVertex3fv(Sides[3].Points[0]);
		glVertex3fv(Sides[3].Points[1]);
		glVertex3fv(Sides[3].Points[2]);
		glVertex3fv(Sides[3].Points[3]);
		glColor3fv(Sides[4].Color);						
		glVertex3fv(Sides[4].Points[0]);
		glVertex3fv(Sides[4].Points[1]);
		glVertex3fv(Sides[4].Points[2]);
		glVertex3fv(Sides[4].Points[3]);
		glColor3fv(Sides[5].Color);						
		glVertex3fv(Sides[5].Points[0]);
		glVertex3fv(Sides[5].Points[1]);
		glVertex3fv(Sides[5].Points[2]);
		glVertex3fv(Sides[5].Points[3]);
		glEnd();											// End drawing cube with quads
	rotquad +=0.9f;

//NEW//////////////////NEW//////////////////NEW//////////////////NEW////////////////

//	return true;										// Keep Going
//	glFlush();
    glutSwapBuffers();
	glutPostRedisplay();	// Trigger an automatic redraw for animation
	}


void donothin(void){
myCube->Spinner();
}

int main(int argc,char** argv){ 
	myCube=new MyCube;
	glutInit(&argc,argv);
	// We're going to animate it, so double buffer 
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
	// Window position (from top corner), and size (width% and hieght)
    glutInitWindowPosition( 10, 60 );
    glutInitWindowSize( 360, 360 );
    glutCreateWindow( "Cube Spinner" );
	glShadeModel( GL_FLAT );	// The default value of GL_SMOOTH is usually better
    glEnable( GL_DEPTH_TEST );	// Depth testing must be turned on
	
	glutDisplayFunc(donothin);
	glutMainLoop(  );
    return(0);

	return 0;
}

The default view volume is a 2x2x2 cube centered at the origin. You push the cube 7 units along the negative Z axis, but the view volume ends at 1 unit along the negative Z axis.

So set some custom projection matrix, or adapt the object to the default one.

Thanks for the suggestion.Anyways I changed it but it still does not work. :confused: :mad:

maybe you should start by checking if glut itself works on your system. use glClearColor(1.0, 0.0, 0.0, 1.0); , this should turn the window’s content to red.

by the way: i think

int i, j;

glBegin(GL_QUADS);

for(i = 0; i < 6; i ++) {
   glColor3fv(Sides[i].Color);

   for(j = 0; j < 4; j ++) {
      glVertex3fv(Sides[i].Points[j]); } }

glEnd(); 

is better than

glBegin(GL_QUADS);					
	glColor3fv(Sides[0].Color);						
	glVertex3fv(Sides[0].Points[0]);
	glVertex3fv(Sides[0].Points[1]);
	glVertex3fv(Sides[0].Points[2]);
	glVertex3fv(Sides[0].Points[3]);
	glColor3fv(Sides[1].Color);						
	glVertex3fv(Sides[1].Points[0]);
	glVertex3fv(Sides[1].Points[1]);
	glVertex3fv(Sides[1].Points[2]);
	glVertex3fv(Sides[1].Points[3]);
	glColor3fv(Sides[2].Color);						
	glVertex3fv(Sides[2].Points[0]);
	glVertex3fv(Sides[2].Points[1]);
	glVertex3fv(Sides[2].Points[2]);
	glVertex3fv(Sides[2].Points[3]);
	glColor3fv(Sides[3].Color);						
	glVertex3fv(Sides[3].Points[0]);
	glVertex3fv(Sides[3].Points[1]);
	glVertex3fv(Sides[3].Points[2]);
	glVertex3fv(Sides[3].Points[3]);
	glColor3fv(Sides[4].Color);						
	glVertex3fv(Sides[4].Points[0]);
	glVertex3fv(Sides[4].Points[1]);
	glVertex3fv(Sides[4].Points[2]);
	glVertex3fv(Sides[4].Points[3]);
	glColor3fv(Sides[5].Color);						
	glVertex3fv(Sides[5].Points[0]);
	glVertex3fv(Sides[5].Points[1]);
	glVertex3fv(Sides[5].Points[2]);
	glVertex3fv(Sides[5].Points[3]);
glEnd();

or at least shorter :wink:

Ya its workin…i initially did what u suggested but thought maybe using the loops caused the problem… stupid of me… thanks anyways…

I’m wondering why you have called glPopMatrix() before drawing your cube. In this case, your transformations have no effect on your cube. Try to call glPopMatrix() after drawing your cube:
glPushMatrix();
//Do your transformations here
//Drawyour cube
glPopMatrix();

Also in this example, you do not need to call glLoadIdentity(), since you have called the glPushMatrix()/glPopMatrix() pairs.

Try to write a reshape function. specify the view volume and viewport in your reshape function.

-Ehsan-