PDA

View Full Version : Black screen



Tim88348
09-20-2011, 06:15 AM
Hello,

i am new at Open GL and dont know where's the problem.
I see alsways a black screen. Here is my code (C++):

My System: Virtual Box with Ubuntu inside.


#include <ctype.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/glx.h>

void display (void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity;
glTranslatef(-1.5, 0,-6);

glBegin(GL_TRIANGLES);
glVertex3f(-1,-1, 0);
glVertex3f( 1,-1, 0);
glVertex3f( 0, 1, 0);
glEnd;

glutSwapBuffers();
}

void keyboard (unsigned char key, int x, int y)
{
if(tolower(key)=='q') exit(0);
}

int main (int argc, char **argv)
{
Display *dpy;
int major, minor;
dpy = XOpenDisplay(NULL);
glXQueryVersion(dpy, &amp;major, &amp;minor);

glutInit(&amp;argc, argv);
glutInitWindowSize(512,512);
glutInitDisplayMode(GLUT_RGB|GLUT_ALPHA|GLUT_DEPTH |GLUT_DOUBLE);
glutCreateWindow("Beispiel: Fenster");
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMainLoop();

return 0;
}


Thanks for help.

Live_MusIc
09-20-2011, 06:36 AM
I'm starting with opengl also, but i would try sending some color to each vertex
glBegin(GL_TRIANGLES);
glColor3f(1,1,1);
glVertex3f(-1,-1, 0);
glColor3f(1,1,1);
glVertex3f( 1,-1, 0);
glColor3f(1,1,1);
glVertex3f( 0, 1, 0);
glEnd;
Also, maybe the viewport is wrong setted.
Try replacing glTranslatef(-1.5, 0,-6); with glTranslatef(0.0, 0,-6); too.
Also you should specify the normal facing to the camera, otherwise if back face culling is enabled you wont see anything.

Tim88348
09-20-2011, 09:15 AM
Hi,

the solution with the colors and glTranslate dont help.
At the moment i dont have manually set the viewport. The whole code is above.