Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Problems with Opengl (command line works, Eclipse not)
icon5.gif  Problems with Opengl (command line works, Eclipse not) [message #532312] Fri, 07 May 2010 22:29 Go to next message
Jo is currently offline JoFriend
Messages: 2
Registered: May 2010
Junior Member
Hi all,

Although I've searched for hours Google, Ubuntu Forums, Linux Mint Forums and this one, I haven't found quite exactly the same situation I'm in. Basically I installed Eclipse IDE for C/C++ Developers (not Eclipse CDT) and I'm attempting to configure Opengl in it. After many hours, searching and different errors, I am now able to successfully compile and run a simple example I have (the code will be presented right after this post) in the terminal. The command I'm using is:

Quote:
g++ -lglut -o trabalho0exe trabalho0.cpp


The problem is that in Eclipse the project is (apparently) built correctly but when I try to run it the output is only

Quote:
freeglut (/home/blacknail/workspace/trabalho0/Debug/trabalho0): failed to open display ''


As I read somewhere I've already included the glut library in the project libraries (right click in the project -> Properties -> Settings -> GCC C++ Linker -> Libraries -> Libraries tab).

By this description I know the problem must be in Eclipse (not in Mint), and so I decided to post this here, although it appears that this forum is only for the CDT version (as I am aware, the CDT version is a plug-in for the java version and I'm using the native C++ version of Eclipse - am I wrong on this one?).

I'm using Linux Mint 8 Helena - x64 edition (basically similar to Ubuntu 9.10). I would be grateful if someone could help me, since I think I've been running in circles.

Many thanks in advance,
João

P.S. 1: Although I don't think in this case the code is important, it goes just below:

    /* ===================================================================================
       Departamento Eng. Informatica - FCTUC
       Computacao Grafica - 2009/10
       ..................................................... JHenriques / BCabral/DBaccan
       Trabalho 1 - Introducao ao OpenGL
    ======================================================================================= */


    //.................................................... Bibliotecas necessarias
       #include <GL/glut.h>
       #include <cstdlib> // adicionado por mim
       
    // ........................... Variaveis globais: cor poligno, dimensoes janela
       GLfloat  r,g,b;
       GLint    wDIMx=400, wDIMy=400;
       

    //-----------------------------------------------------------------------------------
    //                                                      Inicializacao
    //-----------------------------------------------------------------------------------
    void init(void){
       glClearColor(1.0, 1.0, 1.0, 1.0);   //....   Cor para apagar
       gluOrtho2D(-1, 1,-1, 1);         //....   Definicao coordenadas area de desenho (variam de -1 a 1 nos dois eixos)
       r=1.0;                        //....   Cor inicial (vermelho)
       g=0.0;
       b=0.0;
    }


    //-----------------------------------------------------------------------------------
    //                                                         Desenho
    //-----------------------------------------------------------------------------------
    void display(void){

       glViewport( 0, 0, wDIMx,wDIMy );   
     
       glClear(GL_COLOR_BUFFER_BIT);      //....   Apaga ecra

       glColor3f (r, g, b);            //....   Especfica cor actual
       glBegin(GL_TRIANGLES);            //....  Desenha poligno
          glVertex2f(0.5,0.5); 
          glVertex2f(0.75,0.75); 
          glVertex2f(0.75,0.25);   
       glEnd();
     
       glFlush();                     //....   Refresh
    }


    //-----------------------------------------------------------------------------------
    //                                                   Eventos teclado
    //-----------------------------------------------------------------------------------
    void keyboard(unsigned char key, int x, int y){

       switch (key) {
        
       case 'r':
          r=1.0; g=0.0; b=0.0;
          glutPostRedisplay();
          break;
       case 'g':
          r=0.0; g=1.0; b=0.0;
          glutPostRedisplay();
          break;
       case 'b':
          r=0.0; g=0.0; b=1.0;
          glutPostRedisplay();
          break;    
       case 27:
          exit(0);
          break;
       }
    }

    //-----------------------------------------------------------------------------------
    //                                                               MAIN
    //-----------------------------------------------------------------------------------
    int main(int argc, char** argv){
     
       glutInit(&argc, argv);                     //===1:Inicia janela
       glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);   //      :Single mode, RBG
       glutInitWindowSize (400, 400);               //      :dimensoes (pixeis)
       glutInitWindowPosition (100,100);            //      :localizacao
       glutCreateWindow ("Exemplo inicial");         //      :titulo

       init();                                 //===2:Inicializacao estado/parametros
     
                                           //===3:Definicao callbaks   
       glutDisplayFunc(display);                  //      :desenho
       glutKeyboardFunc(keyboard);                  //      :eventos teclado
     
       glutMainLoop();                           //===4:Inicia processamento
     
       return 1;
    }


P.S. 2: I don't know if it is important but the command

Quote:
locate glut.h


returns:

Quote:

/usr/include/GL/freeglut.h
/usr/include/GL/glut.h
/usr/share/doc/freeglut3-dev/freeglut.html

[Updated on: Fri, 07 May 2010 22:33]

Report message to a moderator

Re: Problems with Opengl (command line works, Eclipse not) [message #532319 is a reply to message #532312] Sat, 08 May 2010 04:14 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
On 05/07/2010 05:29 PM, Jo wrote:
> Hi all,
>
> Although I've searched for hours Google, Ubuntu Forums, Linux Forums and
> this one, I haven't found quite exactly the same situation I'm in.
> Basically I installed Eclipse IDE for C/C++ Developers (not Eclipse CDT)
> and I'm attempting to configure Opengl in it. After many hours,
> searching and different errors, I am now able to successfully compile
> and run a simple example I have (the code will be presented right after
> this post) in the terminal. The command I'm using is:
>
> Quote:
>> g++ -lglut -o trabalho0exe trabalho0.cpp
>
>
> The problem is that in Eclipse the project is (apparently) built
> correctly but when I try to run it the output is only
>
> Quote:
>> freeglut (/home/blacknail/workspace/trabalho0/Debug/trabalho0): failed
>> to open display ''
>
>
> As I read somewhere I've already included the glut library in the
> project libraries (right click in the project -> Properties -> Settings
> -> GCC C++ Linker -> Libraries -> Libraries tab).
>
> By this description I know the problem must be in Eclipse (not in Mint),
> and so I decided t post this here, although it appears that this forum
> is only for the CDT version (as I am aware, the CDT version is a plug-in
> for the java version and I'm using the native C++ version of Eclipse -
> am I wrong on this one?).
>
> I'm using Linux Mint 8 Helena - x64 edition. I would be grateful if
> someone could help me, since I think I've been running in circles.
>
> Many thanks in advance,
> João
>
> P.S. 1: Although I don't think in this case the code is important, it
> goes just below:
>
>
> /*
> ============================================================ =======================
>
> Departamento Eng. Informatica - FCTUC
> Computacao Grafica - 2009/10
> ..................................................... JHenriques /
> BCabral/DBaccan
> Trabalho 1 - Introducao ao OpenGL
> ============================================================ ===========================
> */
>
>
> //.................................................... Bibliotecas
> necessarias
> #include <GL/glut.h>
> #include <cstdlib> // adicionado por mim
> // ........................... Variaveis globais: cor poligno, dimensoes
> janela
> GLfloat r,g,b;
> GLint wDIMx=400, wDIMy=400;
>
> //---------------------------------------------------------- -------------------------
>
> // Inicializacao
> //---------------------------------------------------------- -------------------------
>
> void init(void){
> glClearColor(1.0, 1.0, 1.0, 1.0); //.... Cor para apagar
> gluOrtho2D(-1, 1,-1, 1); //.... Definicao coordenadas area de desenho
> (variam de -1 a 1 nos dois eixos)
> r=1.0; //.... Cor inicial (vermelho)
> g=0.0;
> b=0.0;
> }
>
>
> //---------------------------------------------------------- -------------------------
>
> // Desenho
> //---------------------------------------------------------- -------------------------
>
> void display(void){
>
> glViewport( 0, 0, wDIMx,wDIMy ); glClear(GL_COLOR_BUFFER_BIT); //....
> Apaga ecra
>
> glColor3f (r, g, b); //.... Especfica cor actual
> glBegin(GL_TRIANGLES); //.... Desenha poligno
> glVertex2f(0.5,0.5); glVertex2f(0.75,0.75); glVertex2f(0.75,0.25); glEnd();
> glFlush(); //.... Refresh
> }
>
>
> //---------------------------------------------------------- -------------------------
>
> // Eventos teclado
> //---------------------------------------------------------- -------------------------
>
> void keyboard(unsigned char key, int x, int y){
>
> switch (key) {
> case 'r':
> r=1.0; g=0.0; b=0.0;
> glutPostRedisplay();
> break;
> case 'g':
> r=0.0; g=1.0; b=0.0;
> glutPostRedisplay();
> break;
> case 'b':
> r=0.0; g=0.0; b=1.0;
> glutPostRedisplay();
> break; case 27:
> exit(0);
> break;
> }
> }
>
> //---------------------------------------------------------- -------------------------
>
> // MAIN
> //---------------------------------------------------------- -------------------------
>
> int main(int argc, char** argv){
> glutInit(&argc, argv); //===1:Inicia janela
> glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // :Single mode, RBG
> glutInitWindowSize (400, 400); // :dimensoes (pixeis)
> glutInitWindowPosition (100,100); // :localizacao
> glutCreateWindow ("Exemplo inicial"); // :titulo
>
> init(); //===2:Inicializacao estado/parametros
> //===3:Definicao callbaks glutDisplayFunc(display); // :desenho
> glutKeyboardFunc(keyboard); // :eventos teclado
> glutMainLoop(); //===4:Inicia processamento
> return 1;
> }
>
>
> P.S. 2: I don't know if it is important but the command
>
> Quote:
>> locate glut.h
>
>
> returns:
>
> Quote:
>> /usr/include/GL/freeglut.h
>> /usr/include/GL/glut.h
>> /usr/share/doc/freeglut3-dev/freeglut.html
>
Don't 'unable to open display' messages normally indicate that the
process isn't able to find a Display variable. In the launch
configuration of your executable, add a Display variable to the
Environment tab, or select to inherit environment.
Re: Problems with Opengl (command line works, Eclipse not) [message #532338 is a reply to message #532319] Sat, 08 May 2010 14:28 Go to previous messageGo to next message
Jo is currently offline JoFriend
Messages: 2
Registered: May 2010
Junior Member
Hi David,

Thanks for your quick answer. As you said, I added a Display variable in the properties of my project (C / C++ Build -> Environment). The variable is named "Display", it's value is "${DISPLAY}" and it's Origin is "USER:CONFIG". I built the project again but the same message appears when I try to run it :\

I don't know if I made exactly what you wanted, I guess so, if I skipped something please tell me.

I',m kind of lost here, it's been several hours trying to put Opengl to work in Eclipse (some months ago I was able to do it, I can't remember what I did different back then).

Thanks again,
João
Re: Problems with Opengl (command line works, Eclipse not) [message #532362 is a reply to message #532338] Sun, 09 May 2010 00:48 Go to previous messageGo to next message
David Wegener is currently offline David WegenerFriend
Messages: 1445
Registered: July 2009
Senior Member
On 05/08/2010 09:28 AM, Jo wrote:
> Hi David,
>
> Thanks for your quick answer. As you said, I added a Display variable in
> the properties of my project (C / C++ Build -> Environment). The
> variable is named "Display", it's value is "${DISPLAY}" and it's Origin
> is "USER:CONFIG". I built the project again but the same message appears
> when I try to run it :\
>
> I don't know if I made exactly what you wanted, I guess so, if I skipped
> something please tell me.
>
> I',m kind of lost here, it's been several hours trying to put Opengl to
> work in Eclipse (some months ago I was able to do it, I can't remember
> what I did different back then).
>
> Thanks again,
> João

No, this isn't what I was talking about. You made a change to your
project properties. I was talking about your Launch Config (Run->Run
configuration...) Go to the Environment tab of the Launch Config for
your exectuable. Display variables are normally something like :0.0
Re: Problems with Opengl (command line works, Eclipse not) [message #1122705 is a reply to message #532362] Tue, 01 October 2013 21:24 Go to previous message
Srikrishna Acharya is currently offline Srikrishna AcharyaFriend
Messages: 1
Registered: October 2013
Junior Member
That was very useful, I too have struck up there. Now can you please tell me how can we fix this for entire IDE rather than for project to project fix.
Previous Topic:Memory map view for Linker script
Next Topic:Keyboard shortcut for "Cancel Operation"
Goto Forum:
  


Current Time: Thu Apr 25 13:55:49 GMT 2024

Powered by FUDForum. Page generated in 0.03024 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top