PDA

View Full Version : Black Window in selfcompiled appz



09-03-2006, 06:24 PM
Hi
First of all, my system:
Debian Stable 3.1
Kernel 2.6
CPU: AMD Sempron(tm) 2400+
RAM: 2*256 MB running in ddr333 cl3.
gpu: nVidia GeForce 6200 (card manufactured by XFX)
Driver: Official nvidia-driver included with Debian, built as kernel module.


Ok now the Problem:
All selfcompiled programs which use the GL Lib, just diplay a Black window and a mouse arrow, when i start them. This happens ONLY with selfcompiled programs. Other software using openGl runs fine.
This seems to be the same problem as in http://www.opengl.org/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic;f=4;t=000538#000000

--Ano

RigidBody
09-04-2006, 12:08 AM
ehm...code?

09-04-2006, 12:16 AM
If i say 'all selfcomplied programs' then i mean it.

You can take anything which use opengl...

But if you really need some code, this is the program which i tryed first, it works on windows:


#include <cstdlib>
#include <SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>


int main ( int argc, char** argv )
{
// initialize SDL video
if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "Unable to init SDL: %s\n", SDL_GetError() );
return 1;
}

// make sure SDL cleans up before exit
atexit(SDL_Quit);



SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

// create a new window
SDL_Surface* screen = SDL_SetVideoMode(640, 480, 32,
SDL_OPENGL|SDL_FULLSCREEN);
if ( !screen )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
return 1;
}






float i =0;
// program main loop
bool done = false;
while (!done)
{
// message processing loop
SDL_Event event;
while (SDL_PollEvent(&amp;event))
{
// check for messages
switch (event.type)
{
// exit if the window is closed
case SDL_QUIT:
done = true;
break;

// check for keypresses
case SDL_KEYDOWN:
{
// exit if ESCAPE is pressed
if (event.key.keysym.sym == SDLK_ESCAPE)
done = true;
break;
}
} // end switch
} // end of message processing

// DRAWING STARTS HERE
glClearColor (0.0, 0.0, 0.0, 0.0);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glColor3f (1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, 1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
glEnd();
glFlush();

SDL_GL_SwapBuffers( );

// DRAWING ENDS HERE

// finally, update the screen :)


} // end main loop

// free loaded bitmap


// all is well ;)
printf("Exited cleanly\n");
return 0;
}

RigidBody
09-04-2006, 12:25 AM
Originally posted by <Angus>:
If i say 'all selfcomplied programs' then i mean it.[/CODE] 'all selfcompiled programs' or 'all selfcompiled programs which use SDL'?

09-04-2006, 12:30 AM
All. i tried some gl examples which only use OpenGL .. this one for example:



//-----------------------------------------------------------------------
// File: sample.cpp
// Description: A sample OpenGL program
// Programmer: Dave Mount
// For: CMSC 427 - Computer Graphics
// Date: Feb 2006
//
// This is just a sample skeleton C++ program, which shows the
// general structure of a minimal OpenGL program.
//-----------------------------------------------------------------------

#include <cstdlib> // standard definitions
#include <iostream> // C++ I/O
#include <cstdio> // C I/O (for sprintf)
#include <cmath> // standard definitions

#include <GL/glut.h> // GLUT
#include <GL/glu.h> // GLU
#include <GL/gl.h> // OpenGL

using namespace std; // make std accessible

//-----------------------------------------------------------------------
// Global data
//-----------------------------------------------------------------------

GLint TIMER_DELAY = 10000; // timer delay (10 seconds)
GLfloat RED_RGB[] = {1.0, 0.0, 0.0}; // drawing colors
GLfloat BLUE_RGB[] = {0.0, 0.0, 1.0};

//-----------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------
static bool isReversed = false; // draw reversed colors?

//-----------------------------------------------------------------------
// Callbacks
// The global variable "isReversed" describes the drawing state.
// When false, a blue rectangle is drawn on top of red diamond.
// When true the colors are reversed. The "isReversed" variable is
// complemented whenever the left mouse button is clicked or the
// timer goes off (every 10 seconds).
//-----------------------------------------------------------------------

void myReshape(int w, int h) {
cout << "MyReshape called width=" << w << " height=" << h << endl;
glViewport (0, 0, w, h); // update the viewport
glMatrixMode(GL_PROJECTION); // update projection
glLoadIdentity();
gluOrtho2D(0.0, 1.0, 0.0, 1.0); // map unit square to viewport
glMatrixMode(GL_MODELVIEW);
glutPostRedisplay(); // request redisplay
}
// draw diamond and rectangle
void drawObjects(GLfloat* diamColor, GLfloat* rectColor) {
glColor3fv(diamColor); // set diamond color
glBegin(GL_POLYGON); // draw the diamond
glVertex2f(0.90, 0.50);
glVertex2f(0.50, 0.90);
glVertex2f(0.10, 0.50);
glVertex2f(0.50, 0.10);
glEnd();
glColor3fv(rectColor); // set rectangle color
glRectf(0.25, 0.25, 0.75, 0.75); // draw the rectangle
}

void myDisplay(void) { // display callback
cout << "MyDisplay called" << endl;
glClearColor(0.5, 0.5, 0.5, 1.0); // background is gray
glClear(GL_COLOR_BUFFER_BIT); // clear the window

if (isReversed) // draw the objects
drawObjects(BLUE_RGB, RED_RGB);
else
drawObjects(RED_RGB, BLUE_RGB);
glutSwapBuffers(); // swap buffers
}

void myTimer(int id) { // timer callback
cout << "Timer just went off. Reversing colors." << endl;
isReversed = !isReversed; // reverse drawing colors
glutPostRedisplay(); // request redraw
glutTimerFunc(TIMER_DELAY, myTimer, 0); // reset timer for 10 seconds
}

void myMouse(int b, int s, int x, int y) { // mouse click callback
if (s == GLUT_DOWN) {
cout << "Mouse click detected at coordinates x="
<< x << " and y=" << y << endl;
if (b == GLUT_LEFT_BUTTON) {
isReversed = !isReversed;
cout << "Left mouse click. Reversing colors." << endl;
glutPostRedisplay();
}
}
}
// keyboard callback
void myKeyboard(unsigned char c, int x, int y) {
switch (c) { // c is the key that is hit
case 'q': // 'q' means quit
exit(0);
break;
default:
cout << "Hit q to quit. All other characters ignored" << endl;
break;
}
}

//-----------------------------------------------------------------------
// Main program
// This does all the set up for the program. It creates the game
// and then passes control to glut.
//-----------------------------------------------------------------------

int main(int argc, char** argv)
{
cout <<
"Colors swap every 10 seconds.\n"
"Click left mouse button to swap colors.\n" <<
"Try resizing and covering/uncovering the window.\n" <<
"Hit q to quit." << endl;

glutInit(&amp;argc, argv); // OpenGL initializations
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);// double buffering and RGB
glutInitWindowSize(400, 400); // create a 400x400 window
glutInitWindowPosition(0, 0); // ...in the upper left
glutCreateWindow(argv[0]); // create the window

glutDisplayFunc(myDisplay); // setup callbacks
glutReshapeFunc(myReshape);
glutMouseFunc(myMouse);
glutKeyboardFunc(myKeyboard);
glutTimerFunc(TIMER_DELAY, myTimer, 0);
glutMainLoop(); // start it running
return 0; // ANSI C expects this
}
its not sdl related..

RigidBody
09-04-2006, 12:34 AM
is the screen still black when you change the clear color, e.g. glClearColor(1.0, 0.0, 0.0, 1.0); ?

09-04-2006, 12:36 AM
Yes it is, i have tryed so much with the code, i can't belive anymore it is code related..
even big programs like the mentioned game Warzone have this problem..

RigidBody
09-04-2006, 12:45 AM
have you tried just Xlib+GLX (http://www.opengl.org/wiki/index.php/Programming_OpenGL_in_Linux:_GLX_and_Xlib) ? (there's an example at the bottom of the page)


Originally posted by <Angus>:
even big programs like the mentioned game Warzone have this problem.. now i'm a bit confused. did you compile warzone by yourself?

09-04-2006, 12:55 AM
Yes i did.. its a GPL game, i got the SVN source and tryed it.

THe program in xou link DOES WORK :) )

But what does that mean for me?


--Ano

RigidBody
09-04-2006, 01:14 AM
well, don't know...it's hard to say if the reason that SDL does not work on your system is the same reason why GLUT does not work.

for your own programs, i would have recommended using Xlib and GLX instead of GLUT anyway. with Xlib you'll get a better understanding about how the x-windows system works, and you have better control of your program. although most examples in the web are based on GLUT, it's a good exercise for you to insert them in a small program framework like the one that i linked.

concerning warzone or other progs which are too big to port them to xlib...sorry, don't know how to solve this.

09-04-2006, 05:10 AM
Sounds like a compilation/configuration issue (like using a wrong library/header file), as some programs do work. Have you compared the commands used for compilation? Or the output of 'ldd'?

09-04-2006, 06:12 AM
Yes.s ldd says it uses the same libs..

i even tryed the full sdl examples included with makfile and so on..
(http://www.libsdl.org/opengl/OpenGL-intro-1.1.1.zip)

--Ano

09-04-2006, 12:27 PM
That still leaves the compiler/linker options. The example that works for you uses just a gcc call to compile, while Warzone and the SDL examples have their own makefiles that might make some wrong assumptions. Try to compile the SDL examples by hand, as the working example. Or rebuild one of your Debian packages locally and see if that works.

Oh, and I guess by "Official nvidia-driver included with Debian, built as kernel module" you mean the kernel module. But the actual driver can't be included in Debian, so it has to be installed separately and thus might get things wrong.

09-04-2006, 12:29 PM
... you mean _just_ the kernel module, since the actual driver ...

09-05-2006, 04:27 AM
There are some packets in the non-free section of the debian-archives, I think nvidia-glx and nvidia-kernel* or so. I built the kernel module out of these and of that I think as the "official nvidia-driver" ;) .
@"anonymous bastard": There may be some examples which use makefiles, but I compiled the code I've written while going through the tutorial only with gcc(actually g++), "by hand". I used the call
g++ main.cpp `sdl-config --libs --cflags` -lGL -lGLU -o sdl.bin
(With varying filenames, of course).
sdl-config just echoes some libs, I think -lSDL or so, don't know exactly.

09-05-2006, 01:19 PM
It works now.
It was the wrong simlink in /usr/lib/libGL.so which simlinked to a nonexisting .so .
Just had to fix this simlink and it worked.
This however does not explain, why only opengl did work .

09-05-2006, 01:21 PM
Almost forget
Thank you all for help

:)