glutCreateWindow exits with code 1 in Windows 10 - opengl

I am trying to go through a basic tutorial posted here (http://sourceforge.net/project/showfiles.php?group_id=104004&package_id=158526&release_id=463385) and listed on this page (http://gpgpu.org/developer/legacy-gpgpu-graphics-apis). I have also downloaded FreeGlut precompiled libraries for Windows () as well as GLEW headers/libraries.
I am running in Win32 and all my libraries area also the x86 versions.
THe code fails immediately on the 3rd line below with error code 1.
int main()
{
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(512, 512);
glutCreateWindow("Hello, GPGPU! (GLSL version)"); // exits the app
glutIdleFunc(idle);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
initialize();
glutMainLoop();
return 0;
}

Related

Can't run OpenGL on WSL2

I am trying to run an OpenGL code on WSL2 but am getting the following error on trying to run the executable:
GLFW error 65543: GLX: Failed to create context: GLXBadFBConfig
Unable to create GLFW window
This is the code I am using to create a window:
....
GLFWwindow* initialize() {
int glfwInitRes = glfwInit();
if (!glfwInitRes) {
fprintf(stderr, "Unable to initialize GLFW\n");
return nullptr;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
GLFWwindow* window = glfwCreateWindow(1280, 720, "InitGL", nullptr, nullptr);
if (!window) {
fprintf(stderr, "Unable to create GLFW window\n");
glfwTerminate();
return nullptr;
}
glfwMakeContextCurrent(window);
....
return window;
}
....
GLFWwindow* window = initialize();
I am using VcxSrv as my X server.
Following is from the output for glxinfo
direct rendering: No (LIBGL_ALWAYS_INDIRECT set)
server glx vendor string: SGI
server glx version string: 1.4
client glx vendor string: Mesa Project and SGI
client glx version string: 1.4
GLX version: 1.4
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce 940MX/PCIe/SSE2
OpenGL version string: 1.4 (4.6.0 NVIDIA 457.30)
The following fix worked for me.
As #dratenik mentioned above, the problem persists because of direct rendering: No. To solve this, do the following:
In the bashrc/zshrc file, add the following:
export LIBGL_ALWAYS_INDIRECT=0
Or you could just remove export LIBGL_ALWAYS_INDIRECT=1 line from your bashrc/zshrc file if you have added it.
Then, start a new instance of VcxSrv with and unselect the Native opengl box on the Extra Settings page, and select the Disable access control box.
After doing this, direct rendering should be turned on, and you should get the following on running glxinfo:
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4
...

Why is this simple OpenGL program via GLFW not working on Intel HD P4600?

I am trying to run one of the simplest OpenGL 3.3 programs one can ever run but it wouldn't run successfully. The program always returns with negative integer.
Here is how I got to this situation. I did nothing on my own but following this guide LearnOpenGL - Creating a window.
I downloaded the latest source files of GLFW. Generated the GLFW project files from CMAKE GUI application for Visual Studio 2019 (I am using the free Community Edition though). Compiled the GLFW project files and got the glfw3.lib library file. No error whatsoever in this process. CMAKE showed this is for 64-bit build.
Went over to GLAD web service website. Set Language = C/C++, Specification = OpenGL, API/GL = Version 3.3; everything else = none, Profile = Core. Then the website gave me the glad files(.h and .c files).
Then I created a new C++ empty project. Included the location of header files (glfw3.h, glad.h) and location for GLFW library file (glfw3.lib) in the Project's properties's VC++ Directory. In linker -> Input, I added glfw3.lib and opengl32.lib.
Added the glad.c file in project as suggested. Compiled this new OpenGL project. Everything works perfectly.
There is no compilation error. There is no linking error.
Important notice: When you first build the program and then run it the first time, I can see the OpenGL window's opening but within a second it closes automatically; without any KB and/or Mouse interaction and then I get a negative integer as return in the console window. If I keep running the program again and again, I don't see that new UI Window again unless I rebuild it and then run it again.
When I use the debug, it invokes the following exception:
Exception Unhandled
Unhandled exception at 0x0000000010002203 (EZFRD64.dll) in opengl1.exe: 0xC0000005: Access violation reading location 0x00000000731A0090.
What wrong am I doing? Where did I go wrong?
Following is my system configuration:
CPU: Intel Xeon-E3 1246 v3 (This is Intel's 4th Geneartion/Haswell architecture),
GPU: Integrated Intel HD P4600/P4700 (basically it is Intel HD 4600 like all those 4th gen i5s and i7s have)
Latest Graphics Driver (Driver Date under Device Manager: 21-Jan-2020) has been installed.
"OpenGL Extension Viewer" is showing the following core feature support:
OpenGL 3.0: 100% support.
OpenGL 3.1: 100% support.
OpenGL 3.2: 100% support.
OpenGL 3.3: 100% support.
OpenGL 4.0: 100% support.
OpenGL 4.1: 100% support.
OpenGL 4.2: 100% support.
OpenGL 4.3: 100% support.
OpenGL 4.4: 80% support.
OpenGL 4.5: 18% support.
OpenGL 4.6: 9% support.
OpenGL ARB 2015: 8% support.
Following is the code I am trying to run:
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void processInput(GLFWwindow* window);
const unsigned int SCR_WIDTH = 800;
const unsigned int SCR_HEIGHT = 600;
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
GLFWwindow* window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "LearnOpenGL", NULL, NULL);
if (window == NULL)
{
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
while (!glfwWindowShouldClose(window))
{
glfwSwapBuffers(window);
processInput(window);
glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwPollEvents();
}
glfwTerminate();
return 0;
}
void processInput(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}
RE: that mysterious EZFRD64.dll, a post on Reddit:
According to google "EZFRD64.dll" mentioned there is a driver for some generic/off-brand "USB Vibration Controller" and appears to be known to cause issues at least on Windows 10.
See 1 2 3 and many more posts just on the first page of results for that dll.
Janky code running in/near the kernel can cause problems, film at 11 :)

Unable to bundle resource file in executable as images in gtkmm using c++

Unable to bundle .png in my executable created using GTKmm in C++
I am working on GTKmm using C++. My project requirement is to add certain images(say icons/.png) in the executable. Executable is working fine in my build path where as it doesn't works anywhere else(due to file not found).
What should be the approach to bundle the images to executable (to make a distributable executable)
I have tried almost all the approaches available online.
// Sample code
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Gtk::Window win;
Gtk::Table tb_png;
Gtk::VBox mainBox;
Gtk::Alignment* alignment;
win.set_position(Gtk::WIN_POS_CENTER);
win.set_title("PNG");
//window.set_default_size(800, 900);
win.set_size_request(620,565);
win.set_resizable(FALSE);
win.set_icon_from_file("imagem/newlogobmp.bmp");
Gtk::Image step1("imagem/step01.png");
alignment = Gtk::manage(new Gtk::Alignment);
mainBox.pack_start(*alignment,Gtk::PACK_SHRINK);
Gtk::Alignment mywidget(0.1,0.2, 0.9, 0.8);
tb_png.attach(step1,0,1,0,1); //
mywidget.add(tb_png);
// Put widget in middle alignment
alignment->add(mywidget);
win.add(mainBox);
win.show_all();
kit.run(win);
return 0;
}

OpenGL version on Xcode - glfw vs sfml

I am learning opengl on my mac using both glfw and sfml and meet some hurdle on the OpenGL version.
When I run the code:
printf ("Renderer: %s\n", glGetString (GL_RENDERER));
printf ("OpenGL version supported: %s\n", glGetString (GL_VERSION));
printf("glsl: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
on glfw
Renderer: Intel(R) Iris(TM) Graphics 6100
OpenGL version supported: 4.1 INTEL-10.22.25
glsl: 4.10
on sfml
Renderer: Intel(R) Iris(TM) Graphics 6100
OpenGL version supported: 2.1 INTEL-10.22.25
glsl: 1.20
Is it my setting on the xcode project or that is the default framework setting? Is there a way I can change sfml to work with OpenGL 4.1 so that I get glsl 4.1 too?
glfw have this settings:
glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);
Do sfml have something similar?
With SFML you can specify the OpenGL version using sf::ContextSettings.
sf::ContextSettings settings;
settings.depthBits = 24;
settings.stencilBits = 8;
settings.majorVersion = 4;
settings.minorVersion = 1;
settings.attributeFlags = sf::ContextSettings::Default;
Then you pass it to the sf:Window as you create it:
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, settings);
Bottom line is that SFML needs a backwards compatibility context. Because internally SFML relies on some legacy OpenGL functionality.
So if you aren't using SFML for anything SFML specific. Then I recommend continuing to use GLFW.

SDL/SDL_image.h: No such file or directory

I'm trying to follow Lazy Foo's tutorials. But when I try to run one of his examples I get this compiler error:
error: SDL/SDL_image.h: No such file or directory
The compiler/linker is set up correctly, I'm using Code::Blocks on Windows XP.
However, the problem is simply that there are no SDL_image.h. I've checked in the folder that it supposedly should have been. I tried to download the SDL library again and checked again, still no SDL_image.h file. Where did the SDL_image.h file go?
The library I dowloaded was the 'SDL-devel-1.2.14-mingw32.tar.gz' under 'Development Libraries' for Win32 from this link: http://www.libsdl.org/download-1.2.php
You need to install SDL_image separately. It's not shipped with SDL.
You need to install SDL_image library like mentioned in the other answers, if you are on a Debian based systems you can simply install with the following command:
sudo apt-get install libsdl-image1.2-dev
In the third tutorial of lazyfoo is completely explained.
Basically, you must add "-lSDL_image" to the compilation line.
In your case as you are using windows, then you should first install sdl_image and then
#include <SDL_image.h>
not
#include <SDL/SDL_image.h>
If you were using linux and your sdl-image package is installed to /usr/include/SDL then you need to use
#include <SDL_image.h>
In most cases when you install from source in linux. Your package may not be resident in /usr/include/SDL
In these kind of situation, I use
#include <SDL/SDL_image.h>
and it works
For anyone who tries this, an update would be to actually add "-lSDL2_image" to your compilation line. Everyone else simply has -lSDL_image" which changed when SDL2 released. After that just go to the bin and add all of your .dll files to System32 and you should be all set!
You have to Download
"SDL_image-devel-1.2.4-VC6.zip"
For code blocks
download link ยป
http://www.libsdl.org/projects/SDL_image/release/SDL_image-devel-1.2.4-VC6.zip
copy the files present in the include folder that you will find inside the zip file after extraction.And paste it to the C:\SDL\include\SDL in my case or to the directory where your other
SDL *.h are present.
Similary, Copy the files present in the lib folder of the zip file and paste it to C:\SDL\lib or to the folder where other lib files are present..
Then copy all the *.dll files present in the archive to the C:\windows\system32
Further you have to add "-lSDL_image" to the compilation line by openning settings > compiler& debugger > linker.
Then open a empty file project and add empty file to the project then #include "SDL\SDL_image.h"
Hope it works for you !!
Or
First download SDL_image-devel-1.2.4-VC6.zip from above given link and
Goto link >> http://www.lazyfoo.net/SDL_tutorials/lesson03/windows/codeblocks/index.php for more detailed explaination.
SDL2 Windows Setup for (32b) that worked for me (C language):
download SDL2_image-devel-2.0.5-mingw.tar.gz and SDL2_image-2.0.5-win32-x86.zip (32 chose other for 64) from here: https://www.libsdl.org/projects/SDL_image/.
copy "SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\include\SDL2\SDL_image.h" to you SDL folder where all your headers are my case "MinGW\include\SDL2".
copy content from "SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\bin" to "\MinGW\bin".
copy content of : "SDL2_image-devel-2.0.5-mingw\SDL2_image-2.0.5\i686-w64-mingw32\lib" to "MinGW\lib"
include header like this :
#include <SDL2/SDL_image.h>
link it in your makefile (see this '... -llibSDL2_image ...'):
build:
gcc -Wfatal-errors \
-std=c99 \
./*.c \
-I"C:\libsdl\include" \
-L"C:\libsdl\lib" \
-lmingw32 \
-lSDL2main \
-lSDL2 \
-lSDL2 \
-llibSDL2_image \
-o example.exe
Dummy CodeExample.c
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_timer.h>
#include <stdio.h>
int main(int argc, char *args[])
{
// attempt to initialize graphics and timer system
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
{
printf("Error initializing SDL: %s\n", SDL_GetError());
}
// Declare pointers
SDL_Window *window;
SDL_Renderer *renderer;
SDL_Texture *bitmapTex = NULL;
SDL_Surface *bitmapSurface = NULL;
// Create an application window with the following settings:
window = SDL_CreateWindow(
"An SDL2 window", // window title
SDL_WINDOWPOS_CENTERED, // initial x position
SDL_WINDOWPOS_CENTERED, // initial y position
840, // width, in pixels
480, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);
// Check that the window was successfully created
if (!window)
{
// In the case that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
// create renderer which sets up graphics hardware
Uint32 render_flags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
renderer = SDL_CreateRenderer(window, -1, render_flags);
if (!renderer)
{
printf("error creating renderer: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// Load theimage into memory using SDL_Image library function
bitmapSurface = IMG_Load("image.png");
bitmapTex = SDL_CreateTextureFromSurface(renderer, bitmapSurface);
SDL_FreeSurface(bitmapSurface);
if (!bitmapTex)
{
// In the case that the window could not be made...
printf("Error creating texture: %s\n", SDL_GetError());
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
// The window is open: could enter program loop here (see SDL_PollEvent())
while (1)
{
SDL_Event e;
if (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT)
{
break;
}
}
// Clear the window
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, bitmapTex, NULL, NULL);
SDL_RenderPresent(renderer);
}
SDL_DestroyTexture(bitmapTex);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
The SDL library is modular and only the core is distributed, by default, when you acquire the library. For SDL 1, this includes SDL, itself, and (for those writing SDL applications) SDL-devel; for SDL 2, the libraries are SDL2 and SDL2-devel. The corresponding include files in developer's applications are <SDL/SDL.h> and <SDL2/SDL.h>, with the include files having been installed in whatever location is standard for your system, when the *-devel libraries are acquired and installed.
The modules all follow a similar pattern, SDL_X, SDL_X-devel for SDL 1 and SDL2_X and SDL2_X-devel for SDL 2, for module X, with the corresponding developers' include files being <SDL/SDL_X.h> and <SDL2/SDL_X.h>. For instance, for the image module, X = image, the libraries are SDL_image, SDL_image-devel, SDL2_image, SDL2_image-devel, and the include files are <SDL/SDL_image.h> and <SDL2/SDL_image.h>.
The modules are: "image" (as just mentioned) for handling images in the different standard formats (e.g. PNG); "mixer", for handling the different audio file formats, "gfx" for graphics drawing primitives, "net" for networked applications, "rtf" for Rich Text Format, "ttf" for the font-handling (ttf stands for "TrueTypeFont").
The Source Code for SDL is over here:
https://github.com/orgs/libsdl-org/repositories?type=all