I have recently purchased a new laptop and got a new version of VS from my school. And I'm having a little trouble setting up my libraries.
I created a basic SDL_Window, as well as a SDL_GLContext.
I'm able to include my libraries and run the program, but I can't call functions like glClearColor, or glGetString(GL_VERSION). I get a rather strage warning and an error that I have never seen before, I'm guessing it's related to the 2013 version?
I have tried ignoring all specific default libraries, as well as trying to change the programtype (Multithreaded DLL, those 4).
And I have made sure all the dll-files are in place in my system folder.
What makes me wonder is the fact that glewInit() works, but not glClearColor() etc...
Output:
1>MSVCRTD.lib(cinitexe.obj) : warning LNK4098: defaultlib 'msvcrt.lib'
conflicts with use of other libs; use /NODEFAULTLIB:library
1>Window.obj : error LNK2019: unresolved external symbol
__imp__glClearColor#16 referenced in function "public: void __thiscall Window::initOpenGL(void)" (?initOpenGL#Window##QAEXXZ)
1>C:\Users\Aleksander\documents\visual studio 2013\Projects\OpenGL
Test\Debug\OpenGL Test.exe : fatal error LNK1120: 1 unresolved
externals
Header:
#pragma once
#include <SDL.h> //Tested OK
#include <SDL_image.h> //Tested OK
#include <SDL_mixer.h> //Tested OK
#include <SDL_net.h> //Tested OK
#include <OpenGL\glew.h> //?
#include <freeglut\freeglut.h> //?
#include <gl\GL.h> //?
#include <glm\glm.hpp> //Tested OK
#include <iostream> //Standard OK
#include <Box2D\Box2D.h> //Tested OK
using namespace std;
class Window {
SDL_Window *window;
SDL_GLContext context;
bool quit;
public:
Window();
~Window();
void initSDL();
void initOpenGL();
void run();
};
Source:
#include "Window.h"
Window::Window() {
printf("Starting window...\n");
//Initialize window
quit = false;
initSDL();
initOpenGL();
//Run window
run();
}
Window::~Window() {
printf("Closing window...\n");
//Clear window memory
SDL_GL_DeleteContext(context);
SDL_DestroyWindow(window);
//Close window library
SDL_Quit();
}
void Window::initSDL() {
if (SDL_Init(SDL_INIT_EVERYTHING) == -1) {
quit = true;
printf("Unable to initialize SDL!\n");
}
else {
//Create window
const char *title = "OpenGL Test";
int pos = SDL_WINDOWPOS_CENTERED;
int w = 800;
int h = 600;
Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
window = SDL_CreateWindow(title, pos, pos, w, h, flags);
//Create OpenGL context
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
context = SDL_GL_CreateContext(window);
}
}
void Window::initOpenGL() {
GLenum init = glewInit();
if (init != GLEW_OK) {
quit = true;
printf("Unable to initialize OpenGL!\n");
printf("Error: %s!\n", glewGetErrorString(init));
}
else {
//printf("Vendor: %s\n", glGetString(GL_VENDOR));
//printf("Version: %s\n", glGetString(GL_VERSION));
//printf("Renderer: %s\n", glGetString(GL_RENDERER));
}
}
void Window::run() {
printf("Window started running!\n");
SDL_Event event;
while (!quit) {
SDL_GL_SwapWindow(window);
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
quit = true;
}
}
}
}
Related
A very easy/hard question.
What packages do i need to download to be able to create a simple X11 window with an EGL/OpenGLES contex.
As i have today the the problem with dri2 failing to authenticate.
But it can’t be that i link to the wrong library else it wouldn’t accept the X11 window at all at eglGetDisplay.
I really don’t want to use any library like glfw or sdl (wrapper
wrapper).
I use raspbian stretch with the default full KMS(driver by VMWare).
My Code is(if it matter's):
#include <X11/Xlib.h>
#include <EGL/egl.h>
#include <EGL/eglplatform.h>
#include <GLES2/gl2.h>
#include <iostream>
struct Pane {
Window win;
Display *display;
Atom windowDeletMessage;
int x11_file;
EGLDisplay egl_display;
EGLContext egl_context;
EGLSurface egl_surface;
EGLConfig egl_config;
EGLint egl_num_config;
EGLint egl_minor;
EGLint egl_major;
};
void setup_window(Pane &self) {
self.display = XOpenDisplay(nullptr);
if (self.display == nullptr) {
exit(0);
}
auto s = DefaultScreen(self.display);
self.win = XCreateSimpleWindow(self.display,
RootWindow(self.display, s),
10,
10,
800,
600,
1,
BlackPixel(self.display, s),
WhitePixel(self.display, s));
self.windowDeletMessage = XInternAtom(self.display, "WM_DELETE_WINDOW", false);
XSetWMProtocols(self.display, self.win, &self.windowDeletMessage, 1);
XStoreName(self.display, self.win, "Default Window");
XSelectInput(self.display,self.win, KeyPressMask | KeyReleaseMask | LeaveWindowMask | EnterWindowMask | PointerMotionMask | ResizeRedirectMask);
XMapWindow(self.display, self.win);
XFlush(self.display);
self.x11_file = ConnectionNumber(self.display);
}
void GetEvent(Pane &self, XEvent &e) {
// Event handling...
}
void setup_egl(Pane &self)
{
const EGLint Attributes[] = //Note to much is to much
{
EGL_RED_SIZE,8,
EGL_GREEN_SIZE,8,
EGL_BLUE_SIZE,8,
EGL_ALPHA_SIZE,8,
EGL_NONE,
};
self.egl_display = eglGetDisplay(self.display);
if(self.egl_display == EGL_NO_DISPLAY)
{
printf("EGL Failed to Obtain Window!") // Note this is not Error handling!
exit(103);
}
if(eglInitialize(self.egl_display,&self.egl_major,&self.egl_minor) == EGL_FALSE)
{
printf("EGL Failed to Initzialize!""");
exit(104);
};
eglChooseConfig(self.egl_display, Attributes, &self.egl_config, 1, &self.egl_num_config);
self.egl_context = eglCreateContext(self.egl_display, self.egl_config,EGL_NO_CONTEXT,nullptr);
self.egl_surface = eglCreateWindowSurface(self.egl_display, self.egl_config, self.win, nullptr);
eglMakeCurrent(self.egl_display, self.egl_surface, self.egl_surface, self.egl_context);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
eglSwapBuffers(self.display, self.egl_surface);
}
int main(int argc, char **argv) {
Pane pane;
setup_window(pane);
setup_egl(pane);
XEvent e;
while (true) {
GetEvent(pane, e);
glClear(GL_COLOR_BUFFER_BIT);
}
}
Edit:
As i used an USB-Drive to boot and not the SD Card. So raspi-config couldn't access the config file on the SD Card and a such it could not enable full KMS.
I can not for the life of me figure out why the implementation functions aren't being seen and the call to the constructor is unresolved. Any ideas would be appreciated.
Error:
1>Debug\MeGLWindow.obj : warning LNK4042: object specified more than once; extras ignored
1>MeApp.obj : error LNK2019: unresolved external symbol "public: __thiscall MeGLWindow::MeGLWindow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0MeGLWindow##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) referenced in function "public: __thiscall MeApp::MeApp(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0MeApp##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
1>C:\Users\FrizzleFry\documents\visual studio 2012\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe : fatal error LNK1120: 1 unresolved externals
App Header
#ifndef ME_APP
#define ME_APP
#include "MeGLWindow.h"
#include <string>
class MeApp {
private:
MeGLWindow* meWind;
std::string app;
public:
MeApp() {}
MeApp(std::string);
~MeApp();
void run();
};
#endif
The implementation
#include "MeApp.h"
#include <SDL.h>
#include <gl\glew.h>
#include <SDL_opengl.h>
#include <gl\glu.h>
#include <string>
MeApp::MeApp(std::string appName) {
app = appName;
meWind = new MeGLWindow(app);
}
MeApp::~MeApp() {
//delete[] meWind;
//meWind = NULL;
}
void MeApp::run() {
bool quit = false;
//Event handler
SDL_Event e;
//Enable text input
SDL_StartTextInput();
//While application is running
while( !quit )
{
//Handle events on queue
while( SDL_PollEvent( &e ) != 0 )
{
//User requests quit
if( e.type == SDL_QUIT )
{
quit = true;
}
//Handle keypress with current mouse position
else if( e.type == SDL_TEXTINPUT )
{
int x = 0, y = 0;
SDL_GetMouseState( &x, &y );
//handleKeys( e.text.text[ 0 ], x, y );
}
//meWind->show();
}
//Disable text input
SDL_StopTextInput();
}
}
The window header and implementation:
#ifndef ME_GL_WINDOW
#define ME_GL_WINDOW
#include "SDL.h"
#include "GL\glew.h"
#include "SDL_opengl.h"
#include "GL\glu.h"
#include <string>
class MeGLWindow {
private:
std::string appName;
int SCREEN_WIDTH, SCREEN_HEIGHT;
SDL_Window* meWind;
SDL_GLContext meContext;
public:
MeGLWindow() {}
MeGLWindow(std::string);
~MeGLWindow();
void show();
};
#endif
cpp
#include <SDL.h>
#include <gl\glew.h>
#include <SDL_opengl.h>
#include <gl\glu.h>
#include <string>
#include "MeGLWindow.h"
#include <iostream>
#include <string>
MeGLWindow::MeGLWindow(std::string app) {
appName = app;
if(SDL_Init( SDL_INIT_VIDEO) < 0) {
std::cout << "Failed to initilialize SDL!" << std::endl;
exit(1);
}
SCREEN_HEIGHT = 640;
SCREEN_WIDTH = 480;
//Use OpenGL 3.1 core
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
//Create window
meWind = SDL_CreateWindow( appName.c_str() , SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN );
if( meWind == NULL )
{
std::cout << "Failed to create window!" << std::endl;
exit(2);
}
meContext = SDL_GL_CreateContext( meWind );
if( meContext = NULL ) {
std::cout << "Failed to create GL Context!" << std::endl;
exit(3);
}
glewExperimental = GL_TRUE;
GLenum glewerror = glewInit();
if( glewerror != GLEW_OK )
{
std::cout << "Error initializing GLEW!" << std::endl;
exit(4);
}
//use vsync
if( SDL_GL_SetSwapInterval( 1 ) < 0 )
{
std::cout << "Unable to set vsync!" << std::endl;
//printf( "warning: unable to set vsync! sdl error: %s\n", sdl_geterror() );
}
//initialize opengl
//( !initgl() )
}
MeGLWindow::~MeGLWindow() {
//glDeleteProgram( gProgramID );
//Destroy window
SDL_DestroyWindow( meWind );
meWind = NULL;
//Quit SDL subsystems
SDL_Quit();
}
void MeGLWindow::show() {
glClear( GL_COLOR_BUFFER_BIT );
SDL_GL_SwapWindow( meWind );
}
call file
#include <SDL.h>
#include <gl\glew.h>
#include <SDL_opengl.h>
#include <gl\glu.h>
#include <stdio.h>
#include <string>
#include "MeApp.h"
int main( int argc, char* args[] )
{
MeApp app("My Application");
app.run();
return 0;
}
EDIT
Well, I thought that maybe the .obj file was corrupted and had tried deleting it and rebuilding. They were rebuilt but still gave me this error.
If I introduce non-sensical code (I added the line a in the MeGLWindow.h as a class member) and the build gloriously failed due to:
1>c:\users\frizzlefry\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\meglwindow.h(22): error C2146: syntax error : missing ';' before identifier 'MeGLWindow'
1>c:\users\frizzlefry\documents\visual studio 2012\projects\consoleapplication1\consoleapplication1\meglwindow.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>
1>Build FAILED.
I then went to the project directory and deleted the entire debug folder save the two .dll files.
I then deleted the nonsensical code and rebuilt the solution to no avail. I received the same unresolved external symbol error.
When I originally created the files, I accidently named the file meGLWindow.h and I started getting this error after renaming the file. It wouldn't let me just rename the file with a capital, it would say that the file already existed. So I renamed it to something different, (2MeGLWindow.h) and then deleted the original file in the project folder and renamed it back to MeGLWindow.h
Then this error occured (but I had added code and didn't think this was the cause) especially since if I remove the MeGLWindow function calls (like new MeGLWindow(app);) then no build error occurs. It's only if I try to have either the main function or the app class create an instance of MeGLWindow.
I'm considering just copy pasta into a new solution. But maybe there are some sort of list of source files in the solution that are pointing to the wrong meGLWindow.h file that I originally created?
EDIT2
Just got fed up, it was 5 files. I made a new project, copy pasted the header and cpp files and it works like a charm. I will never simply rename a header file ever again.
Warning LNK4042 is a bit deceptive, actually it means that object FILE was specified more that once, so for some reason you already have MeGLWindow.obj, and it does not contain a symbol for the MeGLWindow(std::string), hence the error. Possible reasons are:
Build can't delete old MeGLWindow.obj from the times when that constructor was not implemented yet.
Build doesn't even try to delete old MeGLWindow.obj.
Some other MeGLWindow.obj pops up in the build before the proper one.
Solution: try clean build/rebuild/manually deleting Debug/MeGLWindow.obj; Carefully check build options, output file names. Check security/UAC/access rights. Hopefully that helps.
I am currently attempting to write a very simple 2d game engine using SDL in order to help myself get more comfortable with coding. Unfortunately, I made the mistake of starting with a single source file, and now that my code is getting bigger, I am trying to split the existing code (which works fine before the split) into multiple header and source files. The first major issue I've encountered is that when I try to define SCREEN_HEIGHT, SCREEN_WIDTH, Window, and Renderer in init.cpp after declaring them in init.h, I get error: 'blank' does not name a type (blank being Window, Renderer, etc.). I am also trying to make them global, which may be part of the issue. Included below is the relevant code (I took out all the stuff I think is irrelevant in this case). I suspect I'm just missing something really simple here, but I've been unable to find an existing answer online like I have with my previous problems.
main.cpp
#include "globals.h"
#include "texture.h"
....
globals.h
#ifndef GLOBALS
#define GLOBALS
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <stdio.h>
#include <string>
#endif //GLOBALS
texture.h
#ifndef TEXTURE
#define TEXTURE
#include "globals.h"
#include "init.h"
....
#endif // TEXTURE
texture.cpp
#include "texture.h"
....
init.h
#ifndef INIT
#define INIT
#include "globals.h"
//screen dimensions
int SCREEN_WIDTH;
int SCREEN_HEIGHT;
//initiates SDL and creates a window and renderer
bool init();
//the created window
SDL_Window* Window;
//the renderer that will be used
SDL_Renderer* Renderer;
#endif // INIT
init.cpp
#include "init.h"
SCREEN_WIDTH = 640;
SCREEN_HEIGHT = 480;
Window = NULL;
Renderer = NULL;
bool init()
{
bool success = true;
if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0)
{
printf( "SDL was unable to initialize! SDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1"))
{
printf( "Linear texture filtering not enabled!");
}
else
{
Window = SDL_CreateWindow( "Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if( Window == NULL)
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
Renderer = SDL_CreateRenderer( Window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if( Renderer == NULL)
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError());
success = false;
}
else
{
SDL_SetRenderDrawColor( Renderer, 0xFF, 0xFF, 0xFF, 0xFF);
int PNGImage = IMG_INIT_PNG;
if( !(IMG_Init( PNGImage) & PNGImage))
{
printf( "Image loading not enabled! SDL_Image Error: %s\n", IMG_GetError());
success = false;
}
if( TTF_Init() == -1)
{
printf( "True type fonts not enabled! SDL_TTF Error: %s\n", TTF_GetError());
success = false;
}
}
}
}
}
return success;
}
I get the error in init.cpp at the top of the code before bool init()
Renderer = NULL; is an assignment statement, which you cannot have in global scope. You can only have declarations in global scope. Since you have already declared Renderer in your header file, you don't need to redeclare it either. Just set it to null within one of your initialization functions (e.g. your current init() function).
I feel like I'm misunderstanding a big concept here in c++
(Can't buy any books.)
I couldn't find anything else on this, sorry if something hidden in an obscure part of the internet turns up.
I've been trying to work with SDL lately when I found a new interesting way of creating an application wrapper for sdl. But when separating it into a separate cpp and header file... stuff happens.
C++:
//
// AppSdl.cpp
// sdlgaim
//
// Created by Home on 28/4/14.
// Copyright (c) 2014 hyperum. All rights reserved.
//
#include "AppSdl.h"
app_sdl::app_sdl() :
_running(false)
{
}
app_sdl::~app_sdl()
{
destroy();
}
int app_sdl::init(int width, int height, const char *title)
{
// Initialize the SDL library.
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) < 0)
{
fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
return APP_FAILED;
}
win = SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
// Success.
return APP_OK;
}
void app_sdl::destroy()
{
if (win)
{
SDL_DestroyWindow(win);
SDL_DestroyRenderer(renderer);
SDL_Quit();
}
}
int app_sdl::run(int width, int height, const char *title)
{
// Initialize application.
int state = init(width, height, title);
if (state != APP_OK) return state;
// Enter to the SDL event loop.
SDL_Event ev;
_running = true;
while (SDL_WaitEvent(&ev))
{
onEvent(&ev);
Render();
if (_running == false)
{
break;
}
}
// Success.
return APP_OK;
}
void app_sdl::onEvent(SDL_Event* ev)
{
switch (ev->type)
{
case SDL_QUIT:
_running = false;
break;
case SDL_KEYDOWN:
{
switch (ev->key.keysym.sym)
{
case SDLK_ESCAPE:
_running = false;
break;
}
}
}
}
void app_sdl::Render()
{
SDL_Rect r;
int w,h;
SDL_GetWindowSize(win, &w, &h);
r.w = 200;
r.h = 200;
r.x = w/2-(r.w/2);
r.y = h/2-(r.h/2);
//
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0, 0xff);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0, 0xff);
SDL_RenderFillRect(renderer, &r);
SDL_RenderPresent(renderer);
}
Header:
//
// AppSdl.h
// sdlgaim
//
// Created by Home on 28/4/14.
// Copyright (c) 2014 hyperum. All rights reserved.
//
#ifndef __sdlgaim__AppSdl__
#define __sdlgaim__AppSdl__
#include <iostream>
#include <SDL2/SDL.h>
struct app_sdl
{
app_sdl();
~app_sdl();
// Application state (just convenience instead of 0, 1, ...).
enum APP_STATE
{
APP_OK = 0,
APP_FAILED = 1
};
// Destroy application, called by destructor, don't call manually.
void destroy();
int init(int width, int height, const char *title);
// Run application, called by your code.
int run(int width, int height, const char *title);
// Called to process SDL event.
void onEvent(SDL_Event* ev);
// Called to render content into buffer.
void Render();
// Whether the application is in event loop.
bool _running;
SDL_Window *win;
SDL_Renderer *renderer;
};
#endif /* defined(__sdlgaim__AppSdl__) */
Now, you see, when I include the cpp file and do this:
app_sdl app;
return app.run(640, 480, APPTITLE); in my main integer, everything runs fine. But when I include the HEADER file instead, this happens:
Undefined symbols for architecture x86_64:
"app_sdl::run(int, int, char const*)", referenced from:
_main in main.o
"app_sdl::app_sdl()", referenced from:
_main in main.o
"app_sdl::~app_sdl()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Anyone knows what's happening here? And what I should do?
As you may know, including a cpp file is not the right thing to do even if it seems to work around this problem.
Error like yours occurs when you forget to add the source file to the compile command.
I've never used xcode, but quick googling resulted in this page which suggests:
examine which symbols are missing
target->build phases->compile source
add the missing source files if they are not listed
command+b to compile the source code again
I'm using Visual Studio 2013 and am new to C++. I installed GLEW and freeglut. I try to build my file "main.c", and I receive this:
1>------ Build started: Project: testGlut1, Configuration: Debug Win32 ------
1> main.c
1>main.obj : error LNK2019: unresolved external symbol __imp__glewInit#0 referenced function _Initialize
1>main.obj : error LNK2019: unresolved external symbol __imp__glewGetErrorString#4 referenced in function _Initialize
1>C:\Users\User\documents\visual studio 2013\Projects\testGlut1\Debug\testGlut1.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I read through a similar issue, however the solution didn't work for me, in fact, nothing changed. Also, I only have 2 unresolved externals whereas the aforementioned issue showed 16 unresolved externals. Why? Why are those two errors isolated as such?
The source code for my program:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/freeglut.h>
#define WINDOW_TITLE_PREFIX "Chapter 1"
int CurrentWidth = 800,
CurrentHeight = 600,
WindowHandle = 0;
unsigned FrameCount = 0;
void Initialize(int, char*[]);
void InitWindow(int, char*[]);
void ResizeFunction(int, int);
void RenderFunction(void);
void TimerFunction(int);
void IdleFunction(void);
int main(int argc, char* argv[])
{
Initialize(argc, argv);
glutMainLoop();
exit(EXIT_SUCCESS);
}
void Initialize(int argc, char* argv[])
{
GLenum GlewInitResult;
InitWindow(argc, argv);
GlewInitResult = glewInit();
if (GLEW_OK != GlewInitResult) {
fprintf(
stderr,
"ERROR: %s\n",
glewGetErrorString(GlewInitResult)
);
exit(EXIT_FAILURE);
}
fprintf(
stdout,
"INFO: OpenGL Version: %s\n",
glGetString(GL_VERSION)
);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
}
void InitWindow(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitContextVersion(4, 0);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutSetOption(
GLUT_ACTION_ON_WINDOW_CLOSE,
GLUT_ACTION_GLUTMAINLOOP_RETURNS
);
glutInitWindowSize(CurrentWidth, CurrentHeight);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
if (WindowHandle < 1) {
fprintf(
stderr,
"ERROR: Could not create a new rendering window.\n"
);
exit(EXIT_FAILURE);
}
glutReshapeFunc(ResizeFunction);
glutDisplayFunc(RenderFunction);
glutIdleFunc(IdleFunction);
glutTimerFunc(0, TimerFunction, 0);
}
void ResizeFunction(int Width, int Height)
{
CurrentWidth = Width;
CurrentHeight = Height;
glViewport(0, 0, CurrentWidth, CurrentHeight);
}
void RenderFunction(void)
{
++FrameCount;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
glutPostRedisplay();
}
void IdleFunction(void)
{
glutPostRedisplay();
}
void TimerFunction(int Value)
{
if (0 != Value) {
char* TempString = (char*)
malloc(512 + strlen(WINDOW_TITLE_PREFIX));
sprintf(
TempString,
"%s: %d Frames Per Second # %d x %d",
WINDOW_TITLE_PREFIX,
FrameCount * 4,
CurrentWidth,
CurrentHeight
);
glutSetWindowTitle(TempString);
free(TempString);
}
FrameCount = 0;
glutTimerFunc(250, TimerFunction, 1);
}
Here are my additional dependencies:
Here is the Debug folder in MyDocuments:
There were simply incompatibilities between the OS versions of the linked files. I thought that the process was using SysWOW64 to search for the DLL files of GLUT and GLEW since my OS is Windows 64-bit. Anyway, I used the tool, Dependecy Walker 2.2, to track an previously created .exe file and learned that my OS was searching C:\Windows\System32 for the DLL files. That changed everything, annoyingly. Out of frustration in having searched for answers for over a day and a half, I went into C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x86 and swapped the glew32.lib (64-bit) for glew32.lib (32-bit), and voila, I can run my program without any errors. Since I am not an expert, or even practiced in C programming, I can only say that this is a temporary solution for my problem. I'm not sure why the program searches through C:\Windows\System32 rather than C:\Windows\SysWOW64. But, I hope that this solution helps those whom have exprienced a mysterious linker error messages when trying to use GLEW, GLUT, and Microsoft Visual Studio.