I'm transferring a program from OSX to Windows, but one error is still nagging me. The error occurs during run-time in gdb. Compiling and linking goes all fine.
freeglut (C:\path\to\file.exe): fgInitGL2: fghGenBuffers is NULL
Outside the GDB environment it gives an APPCRASH (windows-shell) or Segmentation fault (mingw64-shell).
My linker flags are:
-std=c++11 -lstdc++ -lz -lm -lmysqlcleint -lpthread -lboost_thread-mgw49-mt-d-1_57 -lboost_system-mgw49-mt-d-1_57 -lboost_regex-mgw49-mt-d-1_57 -lcurl -lfreeglut -lglu32 -lopengl32 -lws2_32 -lwsock32 -U__CYGWIN__
I'm working in msys2 mingw-w64. During runtime, the program tries to open a new window (at least a pictogram rices in the windows taskbar), but the construction of the window won't succeed. The program runs fine on OSX, where I use glut instead of freeglut.
Header (amongst others):
#include <direct.h>
#include <GL/glut.h>
#include <GL/freeglut.h>
CPP (amongst others):
void interface::startInterface(int &argc, char **argv){
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize (width, height);
glutInitWindowPosition (1920, 0);
glutInit (&argc, argv);
glutCreateWindow ("TIFAR 2.0");
LoadGLTextures(); // Load The Texture(s) ( NEW )
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // Reset The Projection Matrix
gluPerspective(45.0f, (GLfloat) width / (GLfloat) height, 0.1f, 100.0f);
// Calculate The Aspect Ratio Of The Window
glMatrixMode(GL_MODELVIEW);
glutDisplayFunc (interface::display);
glutReshapeFunc (interface::reshape);
glutIdleFunc (interface::idle);
glutKeyboardFunc (interface::processNormalKeys);
glutMainLoop();
}
There are some other parts in the program, like where images are loaded, but I think it will be to much information when I mention everything here.
It took me some time, but the cause of the problem was in the hardware. I was running on a virtual machine (VMware) and although the specifications said that it supported OpenGL up to 2.1 I found out that it doesn't support OpenGL at all.
My solution was to take an old machine, install Windows on it, and copy all files. It compiled and runs as smooth as a can.
If anyone else runs into the same problem I can advise to get it working on a native installation before virtualising. It can safe you a lot of time.
Related
I'm trying out OpenGL and C++, and I followed this video tutorial on writing my program (my code is exactly the same as his). I also followed the instructions on the freeglut website here to set up freeglut, compile, and link my program. The source code compiles with no problem, but when I try running the exe I get an error. The only reason I could think of is that I'm not using an IDE, so I'm probably missing some compilation steps or missing some command line arguments when running the exe, which the IDE would have done automatically. Can someone tell me what I need to do to run my program correctly?
Here's my code:
#include <GL/glut.h>
void init() {
glClearColor(1.0, 1.0, 0.0, 1.0);
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glFlush();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
glutInitWindowPosition(200, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("Window 1");
glutDisplayFunc(display);
init();
glutMainLoop();
}
When I compile I run
gcc -c -o hello.o hello.cpp -I"C:\MinGW\include"
gcc -o hello.exe hello.o -L"C:\MinGW\lib" -lfreeglut -lopengl32 -Wl,--subsystem,windows
Then I try to run hello.exe but I only get an error message "The application was unable to start correctly (0xc000007b)".
BTW I saw this duplicate question but I've tried putting the dll in the same directory (it was there from the start) but that didn't change anything.
Using the 32 bit freeglut dll (instead of the 64 bit dll) in my project fixed the problem.
I'm using FreeGLUT and I would like to use OpenGL 3.2. I'm on MacBook Pro (15", Early 2015) Mojave 10.14.3 which according to Apple documentation supports OpenGL up to 4.1. I have downloaded freeglut with brew. However no matter what I put into glutInitContextVersion, the version does not change. No matter what I do, the OpenGL version stays 2.1.
Intel Iris Pro OpenGL Engine, 2.1 INTEL-12.4.7
The used code looks like this:
#include <iostream>
#include <GL/freeglut.h>
using namespace std;
void displayFunc() {
glClearColor(1.0, 1.0, 0.5, 0.5);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glFlush();
}
int main(int argc, char * argv[]) {
glutInit(&argc, argv);
glutInitContextVersion(3,2);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutInitWindowPosition(10, 10);
glutInitWindowSize(480, 272);
glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE);
glutCreateWindow("Window");
glutDisplayFunc(displayFunc);
// Print the OpenGL version
std::printf("%s\n%s\n", glGetString(GL_RENDERER), glGetString(GL_VERSION));
glutMainLoop();
return 0;
}
My cmake looks like this:
cmake_minimum_required(VERSION 3.3)
project(AVT7)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -framework GLUT -framework OpenGL -framework Cocoa")
include_directories(/usr/local/Cellar/freeglut/3.0.0/include)
link_directories(/usr/local/Cellar/freeglut/3.0.0/lib)
add_executable(AVT7 hello.cpp)
target_link_libraries(AVT7 glut)
How can I get this working? I am aware that there might be problem by Apple not supporting OpenGL any more, however it should still work (especially with FreeGLUT).
I have a program that worked on my computer before I wiped the hard drive and reinstalled the operating system. I reinstalled all the necessary compilers and DLLs but im getting linker errors for glut. below is a snippet of the code I am trying to run and what my compile command is.
Here is the main I am trying to run:
/*
* GL01Hello.cpp: Test OpenGL C/C++ Setup
*/
#include <windows.h> // For MS Windows
#include <GL/freeglut.h> // GLUT, includes glu.h and gl.h
/* Handler for window-repaint event. Call back when the window first appears and
whenever the window needs to be re-painted. */
void display() {
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Set background color to black and opaque
glClear(GL_COLOR_BUFFER_BIT); // Clear the color buffer
// Draw a Red 1x1 Square centered at origin
glBegin(GL_QUADS); // Each set of 4 vertices form a quad
glColor3f(1.0f, 0.0f, 0.0f); // Red
glVertex2f(-0.5f, -0.5f); // x, y
glVertex2f( 0.5f, -0.5f);
glVertex2f( 0.5f, 0.5f);
glVertex2f(-0.5f, 0.5f);
glEnd();
glFlush(); // Render now
}
/* Main function: GLUT runs as a console application starting at main() */
int main(int argc, char** argv) {
glutInit(&argc, argv); // Initialize GLUT
glutCreateWindow("OpenGL Setup Test"); // Create a window with the given title
glutInitWindowSize(320, 320); // Set the window's initial width & height
glutInitWindowPosition(50, 50); // Position the window's initial top-left corner
glutDisplayFunc(display); // Register display callback handler for window re-paint
glutMainLoop(); // Enter the infinitely event-processing loop
return 0;
}
And here is the command that is being run:
g++ GL01Hello.cpp -o GL01Hello.exe -lglu32 -lopengl32 -lfreeglut
and the errors I am getting are all below:
g++ GL01Hello.cpp -o GL01Hello.exe -lglu32 -lopengl32 -lfreeglut
C:\Users\Daniel\AppData\Local\Temp\ccC01yPe.o:GL01Hello.cpp:(.text+0x1c): undefined reference to `_imp____glutInitWithExit#12'
C:\Users\Daniel\AppData\Local\Temp\ccC01yPe.o:GL01Hello.cpp:(.text+0x3e): undefined reference to `_imp____glutCreateWindowWithExit#8'
C:\Users\Daniel\AppData\Local\Temp\ccC01yPe.o:GL01Hello.cpp:(.text+0x60): undefined reference to `_imp____glutCreateMenuWithExit#8'
C:\Users\Daniel\AppData\Local\Temp\ccC01yPe.o:GL01Hello.cpp:(.text+0x198): undefined reference to `_imp__glutInitWindowSize#8'
C:\Users\Daniel\AppData\Local\Temp\ccC01yPe.o:GL01Hello.cpp:(.text+0x1b1): undefined reference to `_imp__glutInitWindowPosition#8'
C:\Users\Daniel\AppData\Local\Temp\ccC01yPe.o:GL01Hello.cpp:(.text+0x1c2): undefined reference to `_imp__glutDisplayFunc#4'
C:\Users\Daniel\AppData\Local\Temp\ccC01yPe.o:GL01Hello.cpp:(.text+0x1cc):
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\Daniel\AppData\Local\Temp\ccC01yPe.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 1
Any help in resolving these linker errors would be extremely helpful.
Edit: I edited all the code above to be a very simple example, and I am still getting a very similar linker error. Someone reported this as a similar problem to the generic "what causes linker errors" Post and I have already tried many of those and none of them have helped. Thank you fo the attempt though
Well, everything you do looks right. My best bet is, that the build of FreeGLUT you're using (specifically the .def and .lib linker stubs) don't match (possibly also the .dll). My suggestion would be, to build FreeGLUT from sources using the very same compiler you're also using to build your program. Try that, and report on any differences.
I'm new to this site, and relatively new to programming.
I've been doing some C++ programming for a while using Visual Studio 2010, and I wanted to get into OpenGL, so I bought the OpenGL Superbible to get started. I've gotten stuck on the second chapter's "simple" project.
After hours of research I've been able to download all the necessary files to use freeGLUT and GLtools. I've made sure that everything is in the right place for the program to work.
Now, it appears as though everything has been worked out... except for one odd problem.
I was instructed that I needed to place freeglut.dll into Windows\System32, so I did. The project will build now, but when I go to run it, it tells me
"The program can't start because freeglut.dll is missing from your computer. Try
reinstalling the program to fix this problem."
Now, I am certain that freeglut.dll is in Windows\System32 as it should be, so what's the problem? how do I solve it?
Here's the original code from the book:
#include "../../shared/gltools.h" //OpenGL toolkit
//////////////////////////////////////////////
//called to draw scene
void RenderScene(void)
{
// clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
//Flush drawing commands
glFlush();
}
////////////////////////////////////////////////////////
//set up the rendering state
void SetupRC(void)
{
glClearColor(0.0f , 0.0f, 1.0f, 1.0f );
}
///////////////////////////////////////////////////////////
//main program entry point
void main(void)
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();
return 0;
}
This is the code that actually compiled, but would not run (it's a bit of a mess from all the conflicting data I got from different resources):
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <GLTools.h>
#include <gl/GLUT.h>
//called to draw scene
void RenderScene(void)
{
// clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
//set up the rendering state
void SetupRC(void)
{
glClearColor(0.0f , 0.0f, 1.0f, 1.0f );
}
//void main(void)
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();
return 0;
}
Try putting the DLL in the same folder as your exe file. The advice to put it in Windows\System32 predates a lot of newer Windows security restrictions.
#ScottMcP-MVP 's answer solved my problem, but I thought I'd add some detail that doesn't really fit in the comment.
My solution:
Add the following subdirectory structure to your solution folder:
In x86, put the 32-bit versions of GLut, GLew and anything else you need.
In x64, put the 64-bit versions of same.
I went ahead and put all .dll, .lib, and .h in the corresponding folders here rather than placing them in the Windows SDK (Or, in Win7+, the "Windows Kits" folder) to ensure that my projects in SVN had the correct version, and checking out on another machine would retrieve all dependencies. This required adding the include and target-specific lib folders to the project properties:
Set your Include Directories field to
$(SolutionDir)ThirdParty\Include\;$(IncludePath)
And your Library Directories field to
$(SolutionDir)\ThirdParty\$(PlatformTarget)\lib\;$(LibraryPath)
Note that all of these should be applied to the "All Platforms" build configuration. The $(PlatformTarget) macro will make sure that the correct lib's and dll's are used. The include folder is target-agnostic, so I've placed it in the root of my ThirdParty folder.
To get the required files into your output folder, add the following post-build event to your project configuration (under "All platforms"):
xcopy $(SolutionDir)ThirdParty\$(PlatformTarget)\*.dll $(OutputPath) /Y
That will copy the correct version of the DLLs to your output folder on build. This keeps you from having to manually put the DLLs in our output folder, and is more compatible with source control where you typically don't want to include your output, bin or debug folders.
Once I had all of this configured, I created a VC OpenGL project template since getting everything configured took 30 minutes of my life I'd rather have back.
I downloaded SDL 1.2.14
on Windows 7
and I have Mobility Radeon X1800 driver installed.
I'm using Microsoft Visual C++ 2010 Express.
I added the SDL include and library directories in the "VC++ Directories"
I added the following Additional Dependencies:
opengl32.lib;
glu32.lib;
SDL.lib;
SDLmain.lib;
I added the SDL.dll to my program folder
I didn't add any opengl directories!
#include "SDL.h"
#include "SDL_opengl.h"
bool running = true;
int main(int argc, char* args[]) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen = SDL_SetVideoMode(640,480,32,SDL_OPENGL);
glViewport(0,0,640,480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, 640/480, 1.0, 200.0);
while(running) {
glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); // Swich to the drawing perspective
glLoadIdentity();
glTranslatef(0.0,0.0,-5.0);
glBegin(GL_TRIANGLES);
glVertex3f(-0.5f, 0.5f, 0.0f);
glVertex3f(-1.0f, 1.5f, 0.0f);
glVertex3f(-1.5f, 0.5f, 0.0f);
glEnd();
SDL_GL_SwapBuffers();
}
SDL_Quit();
return 0;
}
This program draws a simple triangle.
I include 2 header files above and my Opengl code just works!
I don't know if my triangle is done on a the GPU or CPU. And what openGL version I'm using?
I mean i heard that Microsoft don't update there opengl files any longer and that they use CPU implementation of OpenGL 1.1 or something.
How do I know what version of OpenGL I'm using? And can I check at run time?
How do I know if I'm using a CPU or GPU implementation? And can I check at run time?
Thanks for look at my problem.
call glGetString
Here is Microsoft's documentation for glGetString. It just repeats the SGI doc and tells you the function is found in gl.h and opengl32.lib.
Actually when you install your video card driver it "replaces" the opengl existing in your machine, so you will be using that version.
Multiple versions of OpenGL are present at the same time, and which one is used depends on the HDC used to initialize OpenGL. For example, applications running in the local login session can get hardware-accelerated GL while those running in a remote desktop session get the CPU-based implementation ( Ben Voigt )
The currently header and lib that comes with Visual Studio only has OpenGL 1.1 in it, so to access more modern stuff you need to call the wglGetProcAddress to get pointers to the new functions.
Here you can find more information: http://www.opengl.org/wiki/Getting_started