Create OpenGL core profile under GLFW - c

How do I create a core profile using GLFW and OpenGL? I'm currently running Mesa 10.0.2 which should support OpenGL 3.3 in a core profile and 3.0 in a non-core profile.
Currently this is what I'm trying to do.
glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// Create context
if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
{
fprintf( stderr, "Failed to create context\n" );
glfwTerminate();
return -1;
}

I found this to be largely a GLFW version issue as genpfault and Brett Hale pointed out. Once I ported the offending code to GLFW 3 the issue disappeared. I also updated to a newer version of the GLM library. For those who are playing with opengl-tutorial.org, I suggest taking it as an exercise to rewrite the code using updated libraries as the ones supplied are very old at this point.

Related

How can I take a screenshot on Wayland?

Now I need to develop a plug-in that can take screenshots on Ubuntu, CentOS and fedora. I try to write it in Xlib. It can run on Ubuntu and CentOS, but Fedora uses Wayland, and the plug-in that I developed can't work.
Gnome screenshot can work on these platforms, but after reading his source code, I found that it can achieve screenshots by calling other processes, which is hard for me to learn from.
So is there any way I can take a screenshot on Wayland engine?
I get it in using dbus, here is the light code:
method_name = "Screenshot";
method_params = g_variant_new ("(bbs)",
TRUE,
FALSE, /* flash */
filename);
connection = g_application_get_dbus_connection (g_application_get_default ());
g_dbus_connection_call_sync (connection,
"org.gnome.Shell.Screenshot",
"/org/gnome/Shell/Screenshot",
"org.gnome.Shell.Screenshot",
method_name,
method_params,
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);

uefi specifications example mentions EfiCoreImageHandle. How to get it?

Quoting the UEFI specifications section about EFI_BOOT_SERVICES.HandleProtocol():
The HandleProtocol() function is still available for use by old EFI
applications and drivers. However, all new applications and drivers
should use EFI_BOOT_SERVICES.OpenProtocol() in place of
HandleProtocol(). The following code fragment shows a possible
implementation of HandleProtocol() using OpenProtocol(). The variable
EfiCoreImageHandle is the image handle of the EFI core.
EFI_STATUS
HandleProtocol (
IN EFI_HANDLE Handle,
IN EFI_GUID *Protocol,
OUT VOID **Interface
)
{
return OpenProtocol (
Handle,
Protocol,
Interface,
EfiCoreImageHandle,
NULL,
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
);
}
End of quote.
My question is: how to get the value for EfiCoreImageHandle when an EFI application was run by a boot manager, or from a UEFI shell?
Simply put, EfiCoreImageHandle is just a placeholder in the specification. Have a look at how I invoke OpenProtocol in the ShowEDID utility in https://github.com/fpmurphy/UEFI-Utilities-2019.
Also look at the ShowUSB utility where I currently use HandleProtocol, i.e.
Status = gBS->HandleProtocol( HandleBuffer[Index],
&gEfiUsbIoProtocolGuid,
(VOID**)&UsbIo );
I could replace the above code with:
Status = gBS->OpenProtocol( HandleBuffer[Index],
&gEfiUsbIoProtocolGuid,
(VOID **)&UsbIo,
gImageHandle,
NULL,
EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL );
Tested with UDK2018 and Lenovo T480

video capturing with opencv

I am coding an app in C for windows using openCV. I want to capture video from the webcam and show it in a window.
The app is almost finished but it doesn't work properly. I think it's because of the cvQueryFrame() that alwasy returns NULL and I don't know why. I tried capturing some frames before going into the while but didn't fix the problem.
The compiler doesn't show me any error. It's not a compiling problem but an execution one. I debugged it step by step and in the line
if(!originalImg) break;
it allways jumps out of the while. That's why the app doesn't remain in execution. It opens and closes very fast.
Here's the code:
void main()
{
cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE);
while (1)
{
originalImg = cvQueryFrame(capture);
if(!originalImg) break;
cvShowImage("Original Image", originalImg);
c = cvWaitKey(10);
if( c == 27 ) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Original Image");
}
Let's see if someone have some idea and can help me with this, thanks!
Assuming the compilation was ok (included all relevant libraries), it may be that the camera has not been installed properly. Can you check if you are able to use the webcam otherwise (using some other software)
If the compilation is actually the issue, please refer to the following related question:
https://stackoverflow.com/a/5313594/1218748
Quick summary:
Recompile opencv_highgui changing the "Preprocesser Definitions" in the C/C++ panel of the properties page to include: HAVE_VIDEOINPUT HAVE_DSHOW
There are other good answers that raise some relvant good points, but my gut feeling is that the above solution would work :-)
It seems you have not opened capture.
Add in the beginning of main:
CvCapture* capture = 0;
capture = cvCaptureFromCAM(0);

Create openGL context in linux console(Raspbian)

I want to make a minimal visual display in console with openGL, but as far as my knowledge goes there has to be a window system involved(glut, glfw, sdl, etc..).
I've seen omxplayer build a graphic environment(I just assume it is openGL or something similar, so please correct me if I'm wrong) from console, in order to save some processing power, and make movies watchable in the PI.
I'm just wondering how do they do it? Is there some literature in the topic? I'm mostly interested in solutions in C/C++, but any language with these capabilities would be great to know about!
I scavenged through the source code, but couldn't really find a clue about this particular task. Any help or pointer would be appreciated!
Note: the Raspberry Pi does OpenGL ES, not OpenGL.
You can find examples of making console based OpenGL ES applications in the VideoCore SDK:
/opt/vc/src/hello_pi
I'm not sure what you mean by "window system", especially as you mention SDL. You can absolutely use SDL + OpenGL ES in the console. That's what the Quake3 port (and the Quake2 port I made) uses.
It uses the EGL native platform interface.
Here's some code from the SubtitleRenderer class:
void SubtitleRenderer::initialize_vg() {
// get an EGL display connection
display_ = eglGetDisplay(EGL_DEFAULT_DISPLAY);
ENFORCE(display_);
// initialize the EGL display connection
ENFORCE(eglInitialize(display_, NULL, NULL));
// get an appropriate EGL frame buffer configuration
static const EGLint attribute_list[] = {
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE
};
EGLConfig config{};
EGLint num_config{};
ENFORCE(eglChooseConfig(display_, attribute_list, &config, 1, &num_config));

Why am I getting Error Code 6 on StartService?

For my purposes, I need to write a kernel mode driver for Windows. Currently I am attempting to make it work under Windows 7 x64.
I created a simple project in Visual Studio 2012 with default code for a KMDF driver. I compiled the code with test-signing on. The driver was compiled and signed.
I also have Test-Signing ON enabled as clearly displayed on the bottom left corner of my Desktop.
Upon trying to start the driver as a service, I always get an Error Code 6: Invalid Handle error.(I have since simplified the code to just try and start it but still did not work;default code did not work either)
Basically, I am having the same problem as the question asked here
https://stackoverflow.com/questions/12080157/startservice-error-6
unfortunately he was never answered. I tried the provided solution, but it didn't help either.
My code that tries to start the driver is
int _cdecl main(void)
{
HANDLE hSCManager;
HANDLE hService;
SERVICE_STATUS ss;
hSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE);
printf("Load Driver\n");
if(hSCManager)
{
printf("Create Service\n");
hService = CreateService(hSCManager, "Example",
"Example Driver",
SERVICE_ALL_ACCESS | SERVICE_START | DELETE | SERVICE_STOP ,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_IGNORE,
"\\path\\to\\driver\\KMDFDriver1.sys",
NULL, NULL, NULL, NULL, NULL);
if(!hService)
{
hService = OpenService(hSCManager, "Example",
SERVICE_ALL_ACCESS | SERVICE_START | DELETE | SERVICE_STOP);
if(!hService)
{
// If initial startup of the driver failed, it will fail here.
process_error();
return 0;
}
}
if(hService)
{
printf("Start Service\n");
if(StartService(hService, 0, NULL) == 0)
{
// Start service ALWAYS returns 0. Only when executed for the first time. Next time it fails on OpenService.
process_error();
printf("Did not start!\n");
}
printf("Press Enter to close service\r\n");
getchar();
ControlService(hService, SERVICE_CONTROL_STOP, &ss);
DeleteService(hService);
CloseServiceHandle(hService);
}
CloseServiceHandle(hSCManager);
}
return 0;
}
And this is the driver code
DRIVER_INITIALIZE DriverEntry;
#ifdef ALLOC_PRAGMA
#pragma alloc_text (INIT, DriverEntry)
#endif
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
{
WDF_DRIVER_CONFIG config;
NTSTATUS status;
DbgPrint("Hello World!\n");
WDF_DRIVER_CONFIG_INIT(&config,
NULL
);
config.DriverInitFlags = WdfDriverInitNonPnpDriver;
status = WdfDriverCreate(DriverObject,
RegistryPath,
WDF_NO_OBJECT_ATTRIBUTES,
&config,
WDF_NO_HANDLE
);
if (!NT_SUCCESS(status)) {
KdPrint( ("WdfDriverCreate failed with "
"status 0x%x\n", status));
}
return status;
}
The function process_error() is a wrapper around GetLastError() which in addition to providing the numeric value, displays a text version of the error code.
I have exhausted all options provided to me to solve this issue. A google search revealed only one occurrence of this problem, and the question was asked here.
What could the problem be?
Extra notes: The driver was compiled with Visual Studio 2012 Ultimate, while my startup code was compiled with MinGW-W64(using GCC). But the startup code shouldn't matter as much as the driver.
Extra notes 2: After wondering for a long time what could be wrong I started thinking if it's the test-sign certificate, because I tried driver source code provided from MSDN, and upon successful compilation, I still got ERROR_INVALID_HANDLE(Error Code 6) when trying to start it.
I have still not found a solution.
I tracked this down to the project settings of the driver. The KMDF versions were missing from the project.
Adjust the following (under Driver Model Settings):
- KMDF Version Major = 1
- KMDF Version Minor = 9
Hit OK, recompile, and reinstall. Worked for me!
A few thoughts:
You're using HANDLE hSCManager && HANDLE hService, they should be declared as SC_HANDLE
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682450(v=vs.85).aspx
"lpBinaryPathName [in, optional]
The fully qualified path to the service binary file. If the path contains a space, it must be quoted so that it is correctly interpreted. For example, "d:\my share\myservice.exe" should be specified as "\"d:\my share\myservice.exe\"".
Try using the full path to the driver
I had the same problem with starting my kernel driver:
startservice failed 6:
the handle is invalid
Turned out that the "classID GUID" of the driver was the same as that of an other one (found out through device manager, looking in events showed different driver names).
Used an online generator to make a new GUID and replaced the one that's in the .inf file of the project (in VS, not any texteditor or some).
After a rebuild and deployment on target machine everything worked fine.
Hope this helps...
Run visual studio with admin privilege
Your call to OpenSCManager() is only asking for SC_MANAGER_CREATE_SERVICE permission by itself, which is not enough for OpenService() or StartService() to succeed.

Resources