diff --git a/CMakeLists.txt b/CMakeLists.txt index d5b51cc..65314ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,9 +23,11 @@ message(STATUS "SFML found: ${SFML_FOUND}") find_package( OpenCL REQUIRED ) message(STATUS "OpenCL found: ${OPENCL_FOUND}") -# Find GLEW -find_package(GLEW REQUIRED) -message(STATUS "GLEW found: ${GLEW_FOUND}") +if (WIN32) + # Find GLEW + find_package(GLEW REQUIRED) + message(STATUS "GLEW found: ${GLEW_FOUND}") +endif() # Find Vulkan #find_package(VULKAN REQUIRED) @@ -127,6 +129,7 @@ target_link_libraries (${PNAME} ${OpenCL_LIBRARY}) target_link_libraries (${PNAME} ${OPENGL_LIBRARIES}) target_link_libraries (${PNAME} ${GLEW_LIBRARIES}) #target_link_libraries (${PNAME} ${Vulkan_LIBRARIES}) +#target_link_libraries(${PNAME} "/Users/cs445001_09/Desktop/voxel-raycaster/SFML/extlibs/freetype.framework/Versions/A/freetype") if (NOT WIN32) target_link_libraries (${PNAME} -lpthread) diff --git a/include/GL_Testing.h b/include/GL_Testing.h index 30ba664..a4c3520 100644 --- a/include/GL_Testing.h +++ b/include/GL_Testing.h @@ -3,9 +3,15 @@ #include #include +#ifdef defined _WIN32 #define GLEW_STATIC #include +#elif defined TARGET_OS_MAC +#include + +#endif + class GL_Testing { public: diff --git a/include/raycaster/Hardware_Caster.h b/include/raycaster/Hardware_Caster.h index 0c7b202..0219b49 100644 --- a/include/raycaster/Hardware_Caster.h +++ b/include/raycaster/Hardware_Caster.h @@ -22,8 +22,9 @@ #include #elif defined TARGET_OS_MAC -# include -# include +#include +#include +#include #endif diff --git a/src/GL_Testing.cpp b/src/GL_Testing.cpp index b4c26df..6e20e39 100644 --- a/src/GL_Testing.cpp +++ b/src/GL_Testing.cpp @@ -14,7 +14,13 @@ GL_Testing::GL_Testing() { matrix = new GLfloat[16]; memcpy(matrix, tmp, sizeof(GLfloat) * 16); - GLint err = glewInit(); + #ifdef linux + GLint err = glewInit(); + #elif _WIN32 + GLint err = glewInit(); + #elif TARGET_OS_MAC + GLint err = 0; + #endif if (err) { std::cout << "error initializing glew" << std::endl; @@ -98,11 +104,26 @@ void GL_Testing::create_buffers() { // Second Triangle }; + #ifdef linux glGenVertexArrays(1, &VAO); + #elif defined _WIN32 + glGenVertexArrays(1, &VAO); + #elif defined TARGET_OS_MAC + glGenVertexArraysAPPLE(1, &VAO); + #endif + glGenBuffers(1, &VBO); glGenBuffers(1, &EBO); // Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s). + + #ifdef linux glBindVertexArray(VAO); + #elif defined _WIN32 + glBindVertexArray(VAO); + #elif defined TARGET_OS_MAC + glBindVertexArrayAPPLE(VAO); + #endif + glBindBuffer(GL_ARRAY_BUFFER, VBO); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); @@ -115,7 +136,13 @@ void GL_Testing::create_buffers() { glBindBuffer(GL_ARRAY_BUFFER, 0); - glBindVertexArray(0); + #ifdef linux + glbindvertexarray(0); + #elif defined _win32 + glbindvertexarray(0); + #elif defined target_os_mac + glbindvertexarrayapple(0); + #endif } void GL_Testing::transform() @@ -146,9 +173,27 @@ void GL_Testing::rotate(double delta) { void GL_Testing::draw() { glUseProgram(shader_program); + + #ifdef linux glBindVertexArray(VAO); + #elif defined _WIN32 + glBindVertexArray(VAO); + #elif defined TARGET_OS_MAC + glBindVertexArrayAPPLE(VAO); + #endif + + + //glDrawArrays(GL_TRIANGLES, 0, 6); glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0); - glBindVertexArray(0); + + #ifdef linux + glbindVertexArray(0); + #elif defined _win32 + glbindVertexArray(0); + #elif defined target_os_mac + glbindVertexArrayAPPLE(0); + #endif + } // diff --git a/src/main.cpp b/src/main.cpp index 13c54f4..07d261f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,7 +74,12 @@ int main() { // Keep at this at the top of main. I think it has to do with it and // sf::RenderWindow stepping on each others feet + #ifdef linux glewInit(); + #elif defined _WIN32 + glewInit(); + #elif defined TARGET_OS_MAC + #endif // The socket listener for interacting with the TCP streaming android controller NetworkInput ni; @@ -92,7 +97,7 @@ int main() { _map.a.get_voxel(sf::Vector3i(5, 5, 0)); // ============================= - return 0; + //return 0; sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "SFML"); window.setMouseCursorVisible(false); @@ -147,7 +152,7 @@ int main() { // Load in the spritesheet texture sf::Texture spritesheet; spritesheet.loadFromFile("../assets/textures/minecraft_tiles.png"); - spritesheet.getNativeHandle(); + //spritesheet.getNativeHandle(); raycaster->create_texture_atlas(&spritesheet, sf::Vector2i(16, 16)); diff --git a/src/raycaster/Hardware_Caster.cpp b/src/raycaster/Hardware_Caster.cpp index 57bd428..f14bd28 100644 --- a/src/raycaster/Hardware_Caster.cpp +++ b/src/raycaster/Hardware_Caster.cpp @@ -99,7 +99,7 @@ void Hardware_Caster::validate() void Hardware_Caster::create_texture_atlas(sf::Texture *t, sf::Vector2i tile_dim) { - create_image_buffer("texture_atlas", t->getSize().x * t->getSize().x * 4 * sizeof(float), t); + create_image_buffer("texture_atlas", t->getSize().y * t->getSize().x * 4 * sizeof(float), t); // create_buffer observes arg 3's @@ -441,7 +441,9 @@ int Hardware_Caster::check_cl_khr_gl_sharing() { char *ext_str = new char[ext_str_size]; clGetDeviceInfo(device_id, CL_DEVICE_EXTENSIONS, ext_str_size, ext_str, &ext_str_size); - if (std::string(ext_str).find("cl_khr_gl_sharing") == std::string::npos) { + std::cout << std::string(ext_str); + if (std::string(ext_str).find("cl_khr_gl_sharing") == std::string::npos && + std::string(ext_str).find("cl_APPLE_gl_sharing") == std::string::npos) { std::cout << "No support for the cl_khr_gl_sharing extension"; delete ext_str; return RayCaster::SHARING_NOT_SUPPORTED; @@ -522,9 +524,11 @@ int Hardware_Caster::set_kernel_arg( sizeof(cl_mem), (void *)&buffer_map.at(buffer_name)); - if (assert(error, "clSetKernelArg")) + if (assert(error, "clSetKernelArg")){ + std::cout << buffer_name << std::endl; + std::cout << buffer_map.at(buffer_name) << std::endl; return OPENCL_ERROR; - + } return 0; } @@ -630,6 +634,8 @@ int Hardware_Caster::run_kernel(std::string kernel_name, const int work_size) { cl_kernel kernel = kernel_map.at(kernel_name); + std::cout << std::endl << command_queue << std::endl; + error = clEnqueueAcquireGLObjects(getCommandQueue(), 1, &buffer_map.at("image"), 0, 0, 0); if (assert(error, "clEnqueueAcquireGLObjects")) return OPENCL_ERROR;