I am trying to create make a purple window using glfw window library and with bgfx C++ on arch linux like below:
but it gives out the error:
X Error of failed request: GLXBadDrawable
Major opcode of failed request: 152 (GLX)
Minor opcode of failed request: 11 (X_GLXSwapBuffers)
Serial number of failed request: 33
Current serial number in output stream: 33
my main.cpp:
#include "main.h"
int main(int, char**) {
glfwInit();
GLFWwindow* window = glfwCreateWindow(WNDW_WIDTH, WNDW_HEIGHT, "Hello, bgfx!", NULL, NULL);
bgfx::Init bgfxInit;
bgfxInit.type = bgfx::RendererType::Count; // Automatically choose a renderer.
bgfxInit.resolution.width = WNDW_WIDTH;
bgfxInit.resolution.height = WNDW_HEIGHT;
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
bgfx::init(bgfxInit);
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x443355FF, 1.0f, 0);
bgfx::setViewRect(0, 0, 0, WNDW_WIDTH, WNDW_HEIGHT);
unsigned int counter = 0;
while(true) {
bgfx::frame();
counter++;
}
return 0;
}
main.h:
#include <iostream>
#define BX_CONFIG_DEBUG
#define BGFX_P_H_HEADER_GUARD
#include "libs/bgfx/include/bgfx/bgfx.h"
#include "libs/bgfx/include/bgfx/platform.h"
#include <GLFW/glfw3.h>
#define GLFW_EXPOSE_NATIVE_X11
#include <GLFW/glfw3native.h>
int WNDW_WIDTH=1600;
int WNDW_HEIGHT =900;
here i included my glfw and bgfx header files
my CMakefile.txt:
cmake_minimum_required(VERSION 3.0.0)
project(bgfx_engine VERSION 0.1.0)
add_executable(bgfx_engine main.cpp)
target_link_libraries(${PROJECT_NAME} GL X11 glfw)
target_link_directories(${PROJECT_NAME} PRIVATE ./libs/bgfx/.build/linux64_gcc/bin/)
target_link_libraries(${PROJECT_NAME} bgfxRelease bimgRelease bxRelease)
I dont know what that error means so i am unable to solve it.
Related
I have got a PC/104 (its OS is Ubuntu 16.04 with kernel 4.19.89 xenomai3) that is connected to two motors via two CAN adapters. Few days back, I wrote some simple code to open my PC/104's CAN ports using the libpcanfd library.
My project folder observes the following hierarchy:
io_error_debug
build
include (empty)
src
CMakeLists.txt
main.cpp
CMakeLists.txt
CMakeLists.txt at /root:
cmake_minimum_required(VERSION 2.6)
project(io_error_debug)
include_directories(${PROJECT_SOURCE_DIR}/include) # add before adding subdirectory
add_subdirectory (src)
add_executable(io_error_debug src/main.cpp)
target_link_libraries(io_error_debug /usr/lib/libpcanfd.so # pcan
"-Wl,--no-as-needed -Wl,#/usr/xenomai/lib/cobalt.wrappers -Wl,#/usr/xenomai /lib/modechk.wrappers /usr/xenomai/lib/xenomai/bootstrap-pic.o -L/usr/xenomai/lib -lcobalt -lmodechk -lpthread -lrt"
)
CMakeLists.txt under /src:
aux_source_directory(. SRC_LIST)
main.cpp:
#include <sys/time.h>
#include <lcm/lcm_coretypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <inttypes.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <pthread.h>
#include <errno.h>
#include <sys/syscall.h>
#include <pcanfd.h>
#include <libpcanfd.h>
#include <cmath>
#include <iostream>
int main(int argc, char *argv[]){
int fd;
fd = pcanfd_open("/dev/pcan0", OFD_BITRATE | PCANFD_INIT_STD_MSG_ONLY | OFD_NONBLOCKING, 1000000);
if (fd < 0)
{
printf("Open operation failed with err %d on port no. %s\n",fd, "/dev/pcan0");
exit(1);
}else{
printf("Open succeeded with return value %d on port no. %s\n",fd, "/dev/pcan0");
}
}
The code compiles and executes well when the motors are switched on. However, when I switch off the motors and switch them on again, I get the following error after executing my code:
Open operation failed with err -5 on port no. /dev/pcan0
Furthermore, dmesg shows these suspicious error lines when I run my code:
[16900.914132] pcan: set_normal_mode(CAN1) failed (err -5)
[16900.914162] pcan: can't open device hardware itself (err -5)!
The documentation states that -5 is an errno error. Therefore, I looked for the value -5 in this errno errors' list and I found out that it isI/O error. Interestingly, when I switch off the PC/104 and execute my code, the program runs well. Nevertheless, when I repeat the aforementioned operation (i.e., switching off and on the motors) I will encounter the same error. I do not understand what is happening.
#include<iostream>
#include <SDL_mixer.h>
#include <SDL.h>
using namespace std;
int main(int argc, char* argv[])
{
SDL_Init(SDL_INIT_AUDIO);
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048) < 0)
{
cout << "Error: " << Mix_GetError() << std::endl;
}
Mix_Music* song = Mix_LoadMUS("sample.wav");
Mix_PlayMusic(song, 1);
Mix_FreeMusic(song);
song = nullptr;
Mix_Quit();
SDL_Quit();
return 0;
}
I am trying to play a simple song, that I converted to WAV. It is located within the program's folder. I didn't get any errors/warnings when compling and the libraries seem to be linked correctly. On failure, loadMUS returns NULL (which isn't the case) and PlayMusic returns -1 upon failure (which again isn't the case). Yet, when I run the program nothing is heard. This is my first time working with SDL.
To just play a wave file this sample will work with SDL2:
#include <SDL.h>
#include <SDL_audio.h>
int main() {
SDL_Init(SDL_INIT_AUDIO);
SDL_AudioSpec spec{};
Uint8 *audio_buf{};
Uint32 audio_len{};
SDL_LoadWAV("path_to.wav", &spec, &audio_buf, &audio_len);
SDL_AudioSpec ob_spec{};
auto device = SDL_OpenAudioDevice(NULL, 0, &spec, &ob_spec, SDL_AUDIO_ALLOW_ANY_CHANGE);
SDL_QueueAudio(device, audio_buf, audio_len);
SDL_PauseAudioDevice(device, 0);
SDL_Delay(5000);
SDL_CloseAudioDevice(device);
SDL_FreeWAV(audio_buf);
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
BTW to link easy to SDL2 just use CMake with
cmake_minimum_required(VERSION 3.19)
project(sample_sdl VERSION 1.0)
find_package(SDL2 REQUIRED)
add_executable(${PROJECT_NAME} src/main.cpp)
set_property(TARGET ${PROJECT_NAME} PROPERTY LINKER_LANGUAGE CXX)
set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 20)
target_link_libraries(${PROJECT_NAME} PRIVATE SDL2::SDL2 SDL2::SDL2main)
I have a fairly simple example.
#include <iostream>
extern "C"
{
#include <libavutil/opt.h>
#include <libavutil/avutil.h>
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
}
int main(int, char **)
{
AVFormatContext *format = 0; // avformat_alloc_context();
// avformat_open_input(&format, "http://s5radio.ponyvillelive.com:8026/stream.mp3", NULL, NULL);
// avformat_find_stream_info(format, NULL);
std::cout << "Hello, world!" << std::endl;
return 0;
}
I this outputs "Hello, world!" and I can set break points but the moment I uncomment anything calling avformat code the program silently closes with no error and no break points are hit making it impossible to debug.
An example would be changing AVFormatContext *format = 0; to AVFormatContext *format = avformat_alloc_context(); or uncommenting avformat_open_input(&format, "http://s5radio.ponyvillelive.com:8026/stream.mp3", NULL, NULL);. Without breakpoints or errors how do I solve?
Update:
This is what I get from the debugger:
ERROR: Unable to start debugging. Unexpected GDB output from command "-exec-run". During startup program exited with code 0xc0000139.
The program 'path\to\my\project\LibavPlayground.exe' has exited with code 0 (0x00000000).
Update2:
this is my cmake:
cmake_minimum_required(VERSION 3.0.0)
project(LibavPlayground VERSION 0.1.0 LANGUAGES CXX C)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBAV REQUIRED libavutil libavcodec libavformat)
include_directories(${LIBAV_INCLUDE_DIRS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS -Wno-deprecated-declarations")
include_directories(include PUBLIC)
include_directories(src PRIVATE)
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/src/*.cpp)
add_executable(LibavPlayground ${SRC_FILES})
target_link_libraries(LibavPlayground ${LIBAV_LIBRARIES})
and all the libav* libraries were installed with a single pacman -S mingw-w64-x86_64-ffmpeg command
The current solution is to use WSL instead of MinGw as I don't duplicate the issue in WSL. Although I really hope someone out there has a real solution.
I've been using PyQt for years now and had to recode a project in C++ using CLion. I have managed (after awhile) to get the code building on my MacBookPro, but when I move the project to Windows 10, all hell broke loose! I've reloaded mingw with the x86 version and gotten everything to work except MOC and AUTOUIC. The only lines I changed in the CMakeLists.txt file between Oses were the ones that pointed to the Qt install. As I said, I'm new to all this in C++ and may have some 'mistakes' in my makefile, but it works on OSX but not in Windows!
I am able to compile ui and resources files manually and get the build to compile, but I don't know how to resolve this issue.
Any help and guidance would be greatly appreciated!
====================[ Build | crapsStarter | Debug ]============================
C:\Users\a.fireheart.CLion2019.3\system\cygwin_cmake\bin\cmake.exe
--build /cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug
--target crapsStarter -- -j 6 [ 14%] Automatic MOC for target crapsStarter
AutoMoc subprocess error
------------------------ The moc process failed to compile "/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/craps.h"
into
"/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug/crapsStarter_autogen/EWIEGA46WW/moc_craps.cpp".
Command
------- C:/Qt/5.14.1/winrt_x64_msvc2017/bin/moc.exe -I/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug
-I/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter -I/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug/crapsStarter_autogen/include
-IC:/Qt/5.14.1/winrt_x64_msvc2017/include -IC:/Qt/5.14.1/winrt_x64_msvc2017/include/QtCore -IC:/Qt/5.14.1/winrt_x64_msvc2017/./mkspecs/winrt-x64-msvc2017 -IC:/Qt/5.14.1/winrt_x64_msvc2017/include/QtGui -IC:/Qt/5.14.1/winrt_x64_msvc2017/include/QtANGLE -IC:/Qt/5.14.1/winrt_x64_msvc2017/include/QtWidgets -I/usr/lib/gcc/x86_64-pc-cygwin/9.2.0/include/c++ -I/usr/lib/gcc/x86_64-pc-cygwin/9.2.0/include/c++/x86_64-pc-cygwin -I/usr/lib/gcc/x86_64-pc-cygwin/9.2.0/include/c++/backward -I/usr/lib/gcc/x86_64-pc-cygwin/9.2.0/include -I/usr/include -I/usr/include/w32api -DQT_CORE_LIB -DQT_GUI_LIB -DQT_WIDGETS_LIB --include /cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug/crapsStarter_autogen/moc_predefs.h
-o /cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/cmake-build-debug/crapsStarter_autogen/EWIEGA46WW/moc_craps.cpp
/cygdrive/c/Users/a.fireheart/CLionProjects/crapsStarter/craps.h
Output
make[3]: * [CMakeFiles/crapsStarter_autogen.dir/build.make:58:
CMakeFiles/crapsStarter_autogen] Error 1 make[2]:
[CMakeFiles/Makefile2:104: CMakeFiles/crapsStarter_autogen.dir/all]
Error 2 make[1]: [CMakeFiles/Makefile2:84:
CMakeFiles/crapsStarter.dir/rule] Error 2 make: * [Makefile:118:
crapsStarter] Error 2
***************** My CMakeLists.txt file content *******************************
cmake_minimum_required(VERSION 3.15)
project(crapsStarter)
set(CMAKE_CXX_STANDARD 17)
#set(RESOURCES crapsResources.qrc)
set(CMAKE_AUTOMOC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
#set(CMAKE_AUTOUIC ON)
include_directories(cmake-build-debug/crapsStarter_autogen/include)
# Tell cmake where Qt is located
set(Qt5_DIR "C:/Qt/5.14.1/winrt_x64_msvc2017/lib/cmake/Qt5")
set(QT_INCLUDES "C:/Qt/5.14.1/winrt_x64_msvc2017/include")
MESSAGE("QT_INCLUDES: ${QT_INCLUDES}")
# Include a library search using find_package()
# via REQUIRED, specify that libraries are required
set(Qt5 NEED)
find_package(Qt5 COMPONENTS Core Gui Widgets REQUIRED)
set(SOURCE_FILES craps.cpp die.cpp crapsGame.cpp crapsResources.cpp)
add_executable(crapsStarter ${SOURCE_FILES})
# specify which libraries to connect
target_link_libraries(${PROJECT_NAME} Qt5::Core)
target_link_libraries(${PROJECT_NAME} Qt5::Gui)
target_link_libraries(${PROJECT_NAME} Qt5::Widgets)
craps.h
//
// Created by Arana Fireheart on 2/2/20.
//
#ifndef CRAPSSTARTER_CRAPS_H
#define CRAPSSTARTER_CRAPS_H
#include "ui_CrapsMainWindow.h"
#include "die.h"
#include <QMainWindow>
class CrapsMainWindow : public QMainWindow, private Ui::CrapsMainWindow {
Q_OBJECT
public:
CrapsMainWindow(QMainWindow *parent = nullptr);
void printStringRep();
void updateUI();
private:
Die die1, die2;
bool firstRoll = true;
int winsCount = 0;
public Q_SLOTS:
void rollButtonClickedHandler();
};
#include "moc_craps.cpp"
#endif //CRAPSSTARTER_CRAPS_H
craps.cpp
#include <iostream>
#include <stdio.h>
//#include <QApplication>
//#include <QWidget>
//#include <QGridLayout>
//#include <QPushButton>
//#include <QLabel>
//#include <QPixmap>
#include "die.h"
#include "craps.h"
#include "ui_CrapsMainWindow.h"
CrapsMainWindow :: CrapsMainWindow(QMainWindow *parent) {
// Build a GUI window with two dice.
setupUi(this);
Die die1, die2;
bool firstRoll = true;
int winsCount = 0;
QObject::connect(rollButton, SIGNAL(clicked()), this, SLOT(rollButtonClickedHandler()));
}
void CrapsMainWindow::printStringRep() {
// String representation for Craps.
char buffer[25];
int length = sprintf(buffer, "Die1: %i\nDie2: %i\n", die1.getValue(), die2.getValue());
printf("%s", buffer);
}
void CrapsMainWindow::updateUI() {
// printf("Inside updateUI()\n");
std::string die1ImageName = ":/dieImages/" + std::to_string(die1.getValue());
std::string die2ImageName = ":/dieImages/" + std::to_string(die2.getValue());
die1UI->setPixmap(QPixmap(QString::fromStdString(die1ImageName)));
die2UI->setPixmap(QPixmap(QString::fromStdString(die2ImageName)));
currentBankValueUI->setText(QString::fromStdString("100"));
}
// Player asked for another roll of the dice.
void CrapsMainWindow::rollButtonClickedHandler() {
//void Craps::rollButtonClickedHandler() {
printf("Roll button clicked\n");
die1.roll();
die2.roll();
printStringRep();
updateUI();
}
I am attempting to Compile a simple OpenGL program on windows with statically linked glew32mxsd.lib... I am also working with glfw and if I compile without glew everything works.
I Downloaded the glew src and build the static mx debug library from source. I then copied the resulting glew32mxsd.lib file to my project directory. I am using cmake so my cmake code appears as follows.
SET (GLEW_VERSION 1.9.0)
SET (GLEW_DIRECTORY ${EXTERNAL_LIBS}/glew/${GLEW_VERSION})
SET (GLEW_INCLUDES ${GLEW_DIRECTORY}/include)
SET (GLEW_LIBS ${GLEW_DIRECTORY}/win/${SYSTEM_ARC}/lib)
INCLUDE_DIRECTORIES (${GLEW_INCLUDES})
ADD_EXECUTABLE (myproject ${HEADER_FILES} ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(engine OpenGL32.lib)
TARGET_LINK_LIBRARIES(engine ${GLEW_LIBS}/glew32mxsd.lib)
Also in my source I am using the following in my header
#define GLEW_STATIC
#define GLEW_MX
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#ifdef WIN32
#include <GL/wglew.h>
#endif
//-----------------------------------------------------------------
static GLEWContext *glewGetContext()
{
return nullptr;
}
Everything compiles and links without any errors but...
When I run the program I get a memory access error. The call stack is
engine.exe!glewContextInit(GLEWContextStruct * ctx) Line 8912 C
engine.exe!cext::graphics::internal::WindowManager::initGLExtentions() Line 204 C++
engine.exe!cext::graphics::WindowManager::initGLExtentions() Line 273 C++
engine.exe!main(int argc, char * * argv) Line 363 C++
engine.exe!__tmainCRTStartup() Line 536 C
engine.exe!mainCRTStartup() Line 377 C
And looking at line 8912 in glew.c the following line is revealed
CONST_CAST(GLEW_VERSION_4_3) = ( major > 4 ) || ( major == 4 && minor >= 3 ) ? GL_TRUE : GL_FALSE;
My glewInit looks like the following
void initGLExtentions()
{
glewExperimental = true;
GLenum err = glewInit();
if (GLEW_OK != err)
{
printf("Error: %s\n",glewGetErrorString(err));
}
printf("Status: Using GLEW %s\n",glewGetString(GLEW_VERSION));
if (!GLEW_ARB_vertex_buffer_object)
{
printf("VBO not supported\n");
exit(EXIT_FAILURE);
}
}
...
glfwWindow *window = makeWindow(options,hints);
if (!window)
{
fprintf( stderr, "Failed to open GLFW window\n" );
glfwTerminate();
exit( EXIT_FAILURE );
}
glfwMakeContextCurrent(window);
initGLExtentions();
Using the same code on Mac works without a problem which leads me to believe that it is something to do with the static lib. However even after following all the instructions on the glew website I must be missing something still.
Edit: Additional Information
I ran dependency walker on my application after reading about it in another thread. Running dependency walker on my exe file produces the following missing files
API-MS-WIN-CORE-COM-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ERROR-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-ROBUFFER-L1-1-0.DLL
API-MS-WIN-CORE-WINRT-STRING-L1-1-0.DLL
API-MS-WIN-SHCORE-SCALING-L1-1-0.DLL
DCOMP.DLL
GPSVC.DLL
IESHIMS.DLL
These are called from the USER32.DLL. Are these related to the glew.lib or wglew.lib in anyway?