hey I'm trying to run this program on netbeans on Ubuntu

#include <windows.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <GL/glu.h>
#include <GL/glut.h>
void myInit(void)
 {
    glClearColor(1.0,0.0,0.0,0.0);       
    glColor3f(0.0f, 0.0f, 1.0f);          
    glPointSize(9.0);            
    glMatrixMode(GL_PROJECTION); 
    glLoadIdentity();
    gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
//<<<<<<<<<<<<<<<<<<<<<<<< myDisplay >>>>>>>>>>>>>>>>>
void myDisplay(void)
{
    glClear(GL_COLOR_BUFFER_BIT); 
    glBegin(GL_POINTS);
        glVertex2i(400, 350);         
        glVertex2i(100, 130);
        glVertex2i(150, 130);
    glEnd();    
    glFlush();                       
}

//<<<<<<<<<<<<<<<<<<<<<<<< main >>>>>>>>>>>>>>>>>>>>>>
void main(int argc, char** argv)
{
    glutInit(&argc, argv);        
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 
    glutInitWindowSize(640,480);    
    glutInitWindowPosition(300, 0); 
    glutCreateWindow("my first attempt");
    glutDisplayFunc(myDisplay);   
    myInit();                   
    glutMainLoop();             
}

the problem is that this program runs perfectly on windows but on Linux it doesn't and I think the problem is in <windows.h> so is there an equivalent library that will make this program work?? and is there any other libraries required to run this on linux. oh and btw I've installed all the opengl libraries .

Dani AI

Generated

— the core issues are platform headers and build/link setup, not an OpenGL API change. There is no Linux equivalent of <windows.h>; remove that include and keep the standard GL headers. Also use a standard main return type (the C++ standard expects int main(...)), since glutMainLoop() does not return to your code. was correct to point out the need to link the OpenGL-related libraries, but you also need the development packages installed on Ubuntu.

Install the development packages if you have not already:

sudo apt-get install build-essential pkg-config libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev

A reliable way to compile from the command line is to let pkg-config provide the right compiler and linker flags. For example, use a compile line that pulls flags for GLUT (replace the filenames as needed):

g++ -o myapp main.cpp $(pkg-config --cflags --libs glut)

If using NetBeans, add the same pkg-config output or the libraries (GL, GLU, glut) into the project linker flags (Project Properties -> Linker -> Libraries / Additional Options), or switch the project to a custom Makefile that runs the above command.

Troubleshooting notes:

  • If you get "GL/gl.h: No such file", the dev packages are missing.
  • "Undefined reference" errors mean the link flags are absent or in the wrong place; using pkg-config avoids this.
  • Running on a headless machine requires an X server (or X forwarding / Xvfb).
  • If modern drivers create a core-profile context, immediate-mode calls like glBegin may be unavailable; GLUT/freeglut usually gives a compatibility context, but on very new setups you may need to request a compatibility profile or port to modern OpenGL.

>this program runs perfectly

I doubt that: main returns int.

Remove <windows.h> as it's windows specific.

The required libraries are glut, gl and glu, although you may not need all three with that code. I don't know about using netbeans for c++ so I can't advise you on how to use it to link against those libs but if you:

g++ main.cpp -I/usr/X11R6/lib -lglut -lGL -lGLU -Wall -o firstglut

from the command line, where main.cpp contains the code you posted (corrected as previously mentioned) and /usr/X11R6/lib is replaced with your distribution specific path to your opengl libs directory, it should build and run fine.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.