Git Product home page Git Product logo

Comments (18)

ArEnSc avatar ArEnSc commented on April 28, 2024

Hey I would be down to help you out with this. This can further help me get my feet wet with this project =)

from magnum.

ArEnSc avatar ArEnSc commented on April 28, 2024

So do windowless context's allow this to happen? I am guessing its more prominently used for GUI kits if anything ? http://www.ecere.com/wordpress/wp-content/uploads/2007/11/argb.png

from magnum.

mosra avatar mosra commented on April 28, 2024

Windowless application does not create a window, which means it can't respond to keyboard or mouse events or draw anything on the screen. The image you posted is (as far as I can tell) just an borderless transparent window.

from magnum.

ArEnSc avatar ArEnSc commented on April 28, 2024

Okay so this is what I have so far.
I am going to integrate that into a WindowlessCglApplication.* in a bit.

I am having two issues

  1. The number of pixel formats returned for OpenGL 4.0 is 0 and context creation works without error.
    Is this supposed to happen or is this an API bug ?
    I tried OpenGL 3.2 it returns 2 formats and also creates the context without error.

The next issue is I am not sure how to modify your cmaketexts

These are my guesses.

else()
    option(WITH_GLXAPPLICATION "Build GlxApplication library" OFF)
    cmake_dependent_option(WITH_WINDOWLESSGLXAPPLICATION "Build WindowlessGlxApplication library"    OFF "NOT WITH_MAGNUMINFO;NOT WITH_DISTANCEFIELDCONVERTER" ON)
  cmake_dependent_option(WITH_XEGLAPPLICATION "Build XEglApplication library" OFF "TARGET_GLES" OFF)
  cmake_dependent_option(WITH_GLUTAPPLICATION "Build GlutApplication library" OFF "NOT TARGET_GLES" OFF)
option(WITH_SDL2APPLICATION "Build Sdl2Application library" OFF)
option(WITH_WINDOWLESSCGLAPPLICATION "Build WindowlessCglApplication" OFF)
endif()

I know for a the compile flag I essentially need the osx opengl flag right?

# Windowless CGL application
if(WITH_WINDOWLESSCGLAPPLICATION)
add_library(MagnumWindowlessCglApplication STATIC WindowlessCglApplication.cpp)
set_target_properties(MagnumWindowlessGlxApplication PROPERTIES COMPILE_FLAGS   ?)
install(FILES WindowlessGlxApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
install(TARGETS MagnumWindowlessGlxApplication
    RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}
    LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}
    ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif()



// Class variables
CGLContextObj context;
CGLPixelFormatObj pix;


/* Check version */
int nPix = 0;
GLint major, minor;
CGLGetVersion(&major, &minor);

if(major == 2 && minor < 1)
{
    std::cout << "Platform::WindowlessCglApplication::tryCreateContext(): GL version 2.1 or greater is required";
    return false;
}

CGLPixelFormatAttribute pfAttributesGL4[4] = {
    kCGLPFAAccelerated,
    kCGLPFAOpenGLProfile,
    (CGLPixelFormatAttribute) kCGLOGLPVersion_GL4_Core,
    (CGLPixelFormatAttribute) 0
};


CGLError cglError = CGLChoosePixelFormat(pfAttributesGL4,&pix,&nPix);

error(cglError);

if (cglError == kCGLBadPixelFormat)
{
    std::cout << "Platform::WindowlessCglApplication::tryCreateContext(): GL version 4.0 has failed trying GL version 3.2" << std::endl;

    CGLPixelFormatAttribute pfAttributesGL3_2[4] = {
        kCGLPFAAccelerated,
        kCGLPFAOpenGLProfile,
        (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
        (CGLPixelFormatAttribute) 0
    };

    cglError = CGLChoosePixelFormat(pfAttributesGL3_2,&pix,&nPix);

    if (cglError == kCGLBadPixelFormat)
    {
        std::cout << "Platform::WindowlessCglApplication::tryCreateContext(): GL version 3.2 has failed trying GL version 3.0" << std::endl;

        CGLPixelFormatAttribute pfAttributesGL3[4] = {
            kCGLPFAAccelerated,
            kCGLPFAOpenGLProfile,
            (CGLPixelFormatAttribute) kCGLOGLPVersion_GL3_Core,
            (CGLPixelFormatAttribute) 0
        };

        cglError = CGLChoosePixelFormat(pfAttributesGL3,&pix,&nPix);

        if (cglError == kCGLBadPixelFormat)
        {

            std::cout << "Platform::WindowlessCglApplication::tryCreateContext(): GL version 3.0 has failed trying GL version Legacy" << std::endl;

            CGLPixelFormatAttribute pfAttributesLegacy[4] = {
                kCGLPFAAccelerated,
                kCGLPFAOpenGLProfile,
                (CGLPixelFormatAttribute) kCGLOGLPVersion_Legacy,
                (CGLPixelFormatAttribute) 0
            };


            cglError = CGLChoosePixelFormat(pfAttributesLegacy,&pix,&nPix);

            if(cglError == kCGLBadPixelFormat)
            {
                std::cout << "Platform::WindowlessCglApplication::tryCreateContext(): Context could not be created" << std::endl;
                return false;
            }


        }


    }


}

cglError = CGLCreateContext(pix, NULL, &context);
error(cglError);
cglError = CGLSetCurrentContext(context);



error(cglError);

std::cout << "Number of Pixel Formats   " << nPix << std::endl;

from magnum.

mosra avatar mosra commented on April 28, 2024

To clarify things up:

Add new option into root CMakeLists.txt like this:

option(WITH_WINDOWLESSCGLAPPLICATION "Build WindowlessCglApplication library" OFF)

And add new block into src/Magnum/Platform/CMakeLists.txt:

# Windowless CGL application
if(WITH_WINDOWLESSCGLAPPLICATION)
    add_library(MagnumWindowlessCglApplication STATIC WindowlessCglApplication.cpp)
    install(FILES WindowlessCglApplication.h DESTINATION ${MAGNUM_INCLUDE_INSTALL_DIR}/Platform)
    install(TARGETS MagnumWindowlessCglApplication
        RUNTIME DESTINATION ${MAGNUM_BINARY_INSTALL_DIR}
        LIBRARY DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR}
        ARCHIVE DESTINATION ${MAGNUM_LIBRARY_INSTALL_DIR})
endif()

I'm not sure about the GL 4.0 issue, it might be a bug.

Thanks for the work!

from magnum.

mosra avatar mosra commented on April 28, 2024

You might also want to try compiling and running magnum-info to easily verify that everything works as expected. Modify lines 183-185 in src/Magnum/Platform/CMakeLists.txt to make use of the new WindowlessCglApplication library:

...
elseif(CORRADE_TARGET_NACL)
    target_link_libraries(magnum-info MagnumWindowlessNaClApplication ppapi_cpp ppapi)
elseif(APPLE)
    target_link_libraries(magnum-info MagnumWindowlessCglApplication ???)
else()
...

I don't know what exact libraries are needed to be linked (hence the ???). Then include proper header in src/Magnum/Platform/magnum-info.cpp (modify lines 44-48), e.g.:

#ifdef __APPLE__
#include "Magnum/Platform/WindowlessCglApplication.h"
#elif defined(CORRADE_TARGET_NACL)
#include "Magnum/Platform/WindowlessNaClApplication.h"
#else
#include "Magnum/Platform/WindowlessGlxApplication.h"
#endif

from magnum.

ArEnSc avatar ArEnSc commented on April 28, 2024

for the ??? it requires the cocoa opengl-framework so do you have a previously existing flag that you want me to use like ${OSX_OPENGL}?

from magnum.

mosra avatar mosra commented on April 28, 2024

No, I don't have anything like that. Something like this might be enough (just a wild guess, though):

find_library(COCOA_FRAMEWORK Cocoa)
target_link_libraries(magnum-info MagnumWindowlessCglApplication ${COCOA_FRAMEWORK})

from magnum.

ArEnSc avatar ArEnSc commented on April 28, 2024

Ill send the pull request sometime this week sorry for the delay there are a few other projects going on =D

from magnum.

mosra avatar mosra commented on April 28, 2024

Awesome, thank you! :-)

from magnum.

epreston avatar epreston commented on April 28, 2024

I noticed in @ArEnSc code above uses the kCGLOGLPVersion_GL4_Core constant. It appears that it hasn't been implemented yet. I ran into the same issue, it looks like we are supposed to use kCGLOGLPVersion_3_2_Core and query if we have a 3.3 or 4.1 context coming back.

from magnum.

epreston avatar epreston commented on April 28, 2024

I'm updating an offline renderer as well. :-)

from magnum.

ArEnSc avatar ArEnSc commented on April 28, 2024

Sorry for the 2 month wait
Anyways

I took into consideration of what epreston said above.

Also I ran magnum-info

Determining if the function XOpenDisplay exists in the /opt/local/lib/libX11.dylib;/opt/local/lib/libXext.dylib failed with the following output:

Determining if the function dnet_ntoa exists in the dnet failed with the following output:

Determining if the function dnet_ntoa exists in the dnet_stub failed with the following output:

Determining if the function gethostbyname exists failed with the following output:

Determining if the function gethostbyname exists in the nsl failed with the following output:

Determining if the function gethostbyname exists in the bsd failed with the following output:

Determining if the function connect exists failed with the following output:

Determining if the function connect exists in the socket failed with the following output:

Determining if the function remove exists failed with the following output:

Determining if the function remove exists in the posix failed with the following output:

Determining if the function shmat exists failed with the following output:

Determining if the function shmat exists in the ipc failed with the following output:

there is this issue with it

from magnum.

mosra avatar mosra commented on April 28, 2024

This was output from magnum-info? From the XOpenDisplay string it looks like it is still using WindowlessGlxApplication instead of your new WindowlessCglApplication. Did you change the includes and linked the right libraries as I said above?

from magnum.

ArEnSc avatar ArEnSc commented on April 28, 2024

I did link the libraries and perform the includes you said above.

#ifdef __APPLE__
#include "Magnum/Platform/WindowlessCglApplication.h"
#elif defined(CORRADE_TARGET_NACL)
#include "Magnum/Platform/WindowlessNaClApplication.h"
#else
#include "Magnum/Platform/WindowlessGlxApplication.h"
#endif
if(WITH_MAGNUMINFO)
    if(NOT UNIX AND NOT CORRADE_TARGET_NACL)
        message(FATAL_ERROR "magnum-info is not available on this platform. Set WITH_MAGNUMINFO to OFF to skip building it.")
    endif()

    add_executable(magnum-info magnum-info.cpp)
    if(UNIX AND NOT CORRADE_TARGET_NACL)
        target_link_libraries(magnum-info MagnumWindowlessGlxApplication ${X11_LIBRARIES})
    elseif(CORRADE_TARGET_NACL)
        target_link_libraries(magnum-info MagnumWindowlessNaClApplication ppapi_cpp ppapi)
    elseif(APPLE)
        find_library(COCOA_FRAMEWORK Cocoa)
        find_library(OpenGL_LIBRARY OpenGL)
        target_link_libraries(magnum-info MagnumWindowlessCglApplication ${COCOA_LIBRARY} ${OpenGL_LIBRARY} )
    endif()
    target_link_libraries(magnum-info Magnum)

    install(TARGETS magnum-info DESTINATION ${MAGNUM_BINARY_INSTALL_DIR})
    if(CORRADE_TARGET_NACL)
        install(FILES magnum-info-nacl.html DESTINATION ${MAGNUM_DATA_INSTALL_DIR} RENAME magnum-info.html)
        install(FILES magnum-info-nacl.nmf DESTINATION ${MAGNUM_DATA_INSTALL_DIR} RENAME magnum-info.nmf)
    endif()
endif()

Info says this:

-- The C compiler identification is Clang 5.1.0
-- The CXX compiler identification is Clang 5.1.0
-- Found Corrade: /usr/lib/libCorradeUtility.dylib  
-- Found OpenGL: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/OpenGL.framework  
-- LIB_SUFFIX variable is not defined. It will be autodetected now.
-- You can set it manually with -DLIB_SUFFIX=<value> (64 for example)
-- LIB_SUFFIX autodetected as '', libraries will be installed into /usr/lib
-- Looking for XOpenDisplay in /opt/local/lib/libX11.dylib;/opt/local/lib/libXext.dylib
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for XOpenDisplay in /opt/local/lib/libX11.dylib;/opt/local/lib/libXext.dylib - not found
-- Looking for dnet_ntoa in dnet
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for dnet_ntoa in dnet - not found
-- Looking for dnet_ntoa in dnet_stub
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for dnet_ntoa in dnet_stub - not found
-- Looking for gethostbyname
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for gethostbyname - not found
-- Looking for gethostbyname in nsl
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for gethostbyname in nsl - not found
-- Looking for gethostbyname in bsd
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for gethostbyname in bsd - not found
-- Looking for connect
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for connect - not found
-- Looking for connect in socket
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for connect in socket - not found
-- Looking for remove
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for remove - not found
-- Looking for remove in posix
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for remove in posix - not found
-- Looking for shmat
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for shmat - not found
-- Looking for shmat in ipc
CMake Error at /opt/local/share/cmake-2.8/Modules/CMakeCInformation.cmake:37 (get_filename_component):
  get_filename_component called with incorrect number of arguments
Call Stack (most recent call first):
  CMakeLists.txt:3 (PROJECT)


CMake Error: Internal CMake error, TryCompile configure of cmake failed
-- Looking for shmat in ipc - not found
-- Found X11: /opt/local/lib/libX11.dylib
-- Configuring incomplete, errors occurred!

from magnum.

epreston avatar epreston commented on April 28, 2024

In the cmake script, do the test for APPLE before the test for UNIX. Apple may be presented as a unix in cmake. My offline CGL renderer, uses frame buffer objects, part of the standard 3.0 and beyond. You will get a compatible forward context (3.3 or 4.1) when using the 3_2_Core constant.

from magnum.

mosra avatar mosra commented on April 28, 2024

Any progress with this? Or is here anybody else who could pick up what's already done and finish it? Thanks :)

from magnum.

mosra avatar mosra commented on April 28, 2024

Finished and merged in #59. Thank you for your work.

from magnum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.