I was looking for a native API access in GLFW3 documentation to get HWND but it's not in my GLFW/glfw3.h file. Is there any #define's to be able to find it by compiler? I can't also find it manually in the file itself using text-finder, so how can I get it?
PS. I can't tag glfw3.
Edit:
Code:
#define GLFW_INCLUDE_GLU
#define GLFW_EXPOSE_NATIVE_WGL
#define GLFW_EXPOSE_NATIVE_WIN32
#include <GL/GLFW/glfw3native.h>
#include <GL/GLFW/glfw3.h>
#include <ctime>
#include <cstdlib>
...
int main()
{
//glfw setup
...
//bla bla bla
...
//all I want to do is to call this one
ScreenToClient( glfwGetWin32Window(window), &point);
}
After getting confused by your problems I tried it my self and I think the include order is your problem. A minimal code example that mimics on Linux what you try to do on Windows compiles and works as intended:
#define GLFW_EXPOSE_NATIVE_X11
#define GLFW_EXPOSE_NATIVE_GLX
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>
int main (int argc, char ** argv)
{
glfwInit();
GLFWwindow* window = glfwCreateWindow (256, 256, "GLFW", nullptr, nullptr);
glfwGetX11Window(window);
glfwTerminate();
return 0;
}
EDIT: Added the incovation of glfwTerminate() for proper clean-up. Please note, of course there should be appropriate error checking taking place, but for the purpose of demonstrating a minimal example, the above is sufficient.
Related
Hi I'm been struggling to get my preprocessor to quit bugging me about this:
So I added _CRT_SECURE_NO_WARNINGS in the C/C++ -> preprocessor -> definitions
But it still said the same, so I defined it below as shown in the code below.
though it didnt work. It is shown in output as an error though and not a warning. Is there anything else I should do?
#include "texture.h"
#include <iostream>
#define _CRT_SECURE_NO_WARNINGS
#include "stb_image.h"
#define STB_IMAGE_IMPLEMENTATION
Texture::Texture(const std::string& fileName)
{
int width, height, numComponents;
unsigned char* data = stbi_load((fileName).c_str(), &width, &height,
&numComponents, 4);
//rest isnt really neccesary i guess
You need to put #define _CRT_SECURE_NO_WARNINGS at the very beginning of the program:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
int main()
{
FILE *f = fopen("a", "r");
}
But following compiles with the warning because #define _CRT_SECURE_NO_WARNINGS comes after #include <iostream>:
#include <iostream>
#define _CRT_SECURE_NO_WARNINGS
int main()
{
FILE *f = fopen("a", "r");
}
The same for #pragma warning(disable: 4996), you need to put it at the beginning of the program (or at least before #include <iostream>)
Consider using
#pragma warning(disable: 4996)
instead.
Do not define _CRT_SECURE_NO_WARNINGS or other warning suppressions, it is a workaround that is supposed to be used when upgrading code not yet utilizing security enhancements in CRT. Fix the code that is causing them.
I'm, trying to output video from raspicam to framebuffer 0, and I'm having an issue with BCM_HOST, where I get a ton of errors from the included vcos.h.
All the errors are of the same 2 types:
'VCHPRE_' does not name a type,
'vcos_boot_t' has not been declared,
In files: connection.h vc_ispmanx.h, message.h etc.
etc.
I'll link to a full pastebin of errors below
I don't even know where to begin solving these, I moved /opt/vc from raspbian to my sysroot folder using VisualGDB's synchronize sysroot feature, and all the include files are there.
Is this a problem with the files themselves? It can't be,
Thanks for any help,
-D
Pastebin link: https://mypastebin.com/xQdN7mZZInHx
Example:
#include <stdio.h>
#include <syslog.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/mman.h>
#include "bcm_host.h"
using namespace std;
int main(int argc, char **argv) {
{
DISPMANX_DISPLAY_HANDLE_T display;
DISPMANX_MODEINFO_T display_info;
DISPMANX_RESOURCE_HANDLE_T screen_resource;
VC_IMAGE_TRANSFORM_T transform;
uint32_t image_prt;
VC_RECT_T rect1;
int ret;
int fbfd = 0;
char *fbp = 0;
struct fb_var_screeninfo vinfo;
struct fb_fix_screeninfo finfo;
return 0;
}
Ok, it seems that using VisualGDB sysroot synchronize tool causes some files to be copied with 0 length. I checked vcos.h and it was empty, but on my linux system it had data. Fixed by copying all the files manually.
Intro
First of all, I would like to say that I have read through the previous answers for this type of question, including this excellently written one.
However, I do not understand enough about C++ to be able to use the more "advanced" fixes.
I have ensured that the right type of console has been selected (Console (/SUBSYSTEM:CONSOLE) for those interested), and have the required imports with the possible exception of an IDL mentioned somewhere (that falls into the lack of understanding category).
If this is a duplicate, I would be more than happy to use the post I duplicated, but I have not been able to find anything that can help someone of my skill level.
Technical Information
IDE: Visual Studio
Platform: Windows
Code
headers.h
#pragma once
#include <stdio.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <Shobjidl.h>
#include <time.h>
#include <stdlib.h>
#include <tchar.h>
main.cpp
#include "headers.h"
using namespace std;
int main() {
string x = "C://Users/student/Desktop/i-should-buy-a-boat.jpg";
x.c_str();
wstring tempx = std::wstring(x.begin(), x.end());
LPCWSTR sw = tempx.c_str();
HRESULT SetWallpaper(
LPCWSTR monitorID,
LPCWSTR wallpaper
);
SetWallpaper(NULL, sw);
}
SetWallpaper() is not a standalone function exported by the Win32 API. It is a method of the IDesktopWallpaper interface (see here).
So you need to use code that is more like this instead:
#include "headers.h"
int main()
{
std::wstring x = L"C:\\Users\\student\\Desktop\\i-should-buy-a-boat.jpg";
CoInitialize(NULL);
IDesktopWallpaper *p;
if (SUCCEEDED(CoCreateInstance(__uuidof(DesktopWallpaper), 0, CLSCTX_LOCAL_SERVER, __uuidof(IDesktopWallpaper), (void**)&p)))
{
p->SetWallpaper(NULL, x.c_str());
p->Release();
}
CoUninitialize();
return 0;
}
I downloaded OpenCV 3.0.0-rc1 and build it using CMAKE-gui 3.2.2 using VS2012 Win64 compiler. Binaries and libraries got generated and I set it up with Qt 64 bit. All programs are working fine except when I try to use the feature cv::LineSegmentDetector it shows a compile error in private.hpp file. The error says
unexpected end-of-line
My code is as follows
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/private.hpp>
#include <opencv2/core/utility.hpp>
using namespace std;
int main()
{
cv::Mat image = cv::imread("C:\\Users\\IMAGE\\Desktop\\PROJ\\SAMPLE.png");
cv::imshow("TEST",image);
cv::waitKey();
cv::LineSegmentDetector lsd;
return 0;
}
And on following the error I found the 2nd line of the following part of the code in private.hpp as error highlighted.
#ifdef HAVE_EIGEN
# if defined __GNUC__ && defined __APPLE__
# pragma GCC diagnostic ignored "-Wshadow"
# endif
# include <Eigen/Core>
# include "opencv2/core/eigen.hpp"
#endif
# if defined __GNUC__ && defined __APPLE__
Please let me know if I am doing some implementation mistake or some changes in the private.hpp can fix this error. I am using windows 8 64 bit.
oh, never try to use something, that is called "private", i guess...
#include <opencv2/opencv.hpp> // includes all others
#include <opencv2/core/utility.hpp> // getTickCount, etc.
int main()
{
// LineSegmentDetector is an abstract class, you can't create an
// instance on the stack, but need to use Ptr and factory:
cv::Ptr<cv::LineSegmentDetector> lsd = cv::createLineSegmentDetector();
return 0;
}
I am trying to use ffmpeg library on windows in C++/Qt. This is my main function:
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
#define INT64_C(val) val##LL
#define UINT64_C(val) val##ULL
#include <QtCore>
#include <SDL/SDL.h>
#ifdef __MINGW32__
#undef main
#endif
//--------------- FFMPEG Headers and Libraries ---------------
extern "C"
{
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libswscale/swscale.h>
}
int main(int c, char *args[])
{
av_register_all();
AVFormatContext *ctx;
if(avformat_open_input(&ctx,"salam.avi",NULL,NULL)!=0)
return -1;
return 0;
}
It gets compiled & linked fine. But I get this error when I try to run it:
The program has unexpectedly finished
This happens on *avformat_open_input* function. What's the problem? Is it about my code, or it is a problem with my libraries?
Thanks in advance
Finally I found it. The answer is so simple. ctx should be initialized by NULL.
AVFormatContext *ctx = NULL;
Could be a problem with the AVI. Make sure your avi is supported by FFMPEG. use this tool To check what exactly the format is and look up the FFMPEG library help/support to see if the format is supported or not.