0

My "CMakeList.txt" file

cmake_minimum_required(VERSION 3.1)
project(butler)

#########################################################
# FIND GLUT
#########################################################

find_package(GLUT REQUIRED)
include_directories(${GLUT_INCLUDE_DIRS})
link_directories(${GLUT_LIBRARY_DIRS})
add_definitions(${GLUT_DEFINITIONS})
if(NOT GLUT_FOUND)
    message(ERROR " GLUT not found!")
endif(NOT GLUT_FOUND)
#########################################################
# FIND OPENGL
#########################################################
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
link_directories(${OpenGL_LIBRARY_DIRS})
add_definitions(${OpenGL_DEFINITIONS})
if(NOT OPENGL_FOUND)
    message(ERROR " OPENGL not found!")
endif(NOT OPENGL_FOUND)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

set(SOURCE_FILES main.cpp)
add_executable(butler ${SOURCE_FILES})
target_link_libraries(butler ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} )

And some example from Internet:

#include <windows.h>
#include <cstdlib>
#include "GL/glut.h"

float clr = 0.2;

void display() {
    glClear(GL_COLOR_BUFFER_BIT);

    clr += 0.1;
    if (clr > 1.0)
        clr = 0;
    glBegin(GL_POLYGON);
    {
        glColor3f(clr, clr, clr);
        glVertex2f(-0.5, -0.5);
        glVertex2f(-0.5, 0.5);
        glVertex2f(0.5, 0.5);
        glVertex2f(0.5, -0.5);
    }
    glEnd();

    glFlush();
}

// Main execution  function
int main(int argc, char *argv[]) {
    glutInit(&argc, argv);      // Initialize GLUT
    glutCreateWindow("win1");   // Create a window 1
    glutDisplayFunc(display);   // Register display callback
    glutCreateWindow("win2");   // Create a window 2
    glutDisplayFunc(display);   // Register display callback

    glutMainLoop();             // Enter main event loop
}

and I have error: "freeglut (/some/path/to/Debug/butler): failed to open display ''". I try to add DISPLAY variable with ':0.0' value but have error "freeglut (/some/path/to/Debug/butler): failed to open display ':0.0'"

GFB
  • 345
  • 1
  • 5
  • 15
  • 1
    It sounds like you don't have an X server running, or it's running as something other than ":0.0". – Jim Lewis Apr 12 '15 at 22:51
  • Can I run this programm without X server? I do not absolutely understand what is "X server". Some time ago I wrote same code in VisualStudio2010 and it works fine. And now I installed CLion + Cygwin and start "a fun carouseles". – GFB Apr 13 '15 at 08:50

2 Answers2

2

When compiling with Cygwin the programs you get expect a "unix-ish" kind of environment. Graphics is done by an X server to which clients connect to on the one end, and a graphics driver attaches to the other end; the Cygwin X server uses the Windows GDI (and a very baseline OpenGL profile) for its backend. The error get is the program telling you, that it expects to be able to connect to an X server, but that it can't find one.

And when it comes to OpenGL on Windows, you should not use one!

When building a program the uses OpenGL: Don't use the Cygwin toolchain!

Instead use the MinGW toolchain targeting the native Windows graphics APIs; you'll also need the appropriate builds for the relevant libraries. You can install the MinGW toolchain inside your Cygwin environment, but personally I prefer to have a self contained, independent installation.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
1

If your main priority is just getting it to run once compiled, without regard to performance, compatibility or portability, you can run:

startxwin /some/path/to/Debug/butler

in a Cygwin terminal (assuming you have the xinit Cygwin package installed, per the documentation).

This starts an X server in "multiwindow" mode and runs your program. Once your program exits, it will stop the X server and clean up.

smitelli
  • 6,835
  • 3
  • 31
  • 53