Jump to content
  • Advertisement
Sign in to follow this  
arbuckle911

OpenGL distributing opengl applications with VS.NET 2005 Express

This topic is 4315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

There are tons of threads and small tutorials about how to get vs.net 2005 express apps to work on stock windows installations. I've tried everything from the redistributable installers to the dependency walker, but the stock windows installs just keep spitting back vague error messages about reinstalling the application. I feel that this subject should be throughly covered in an FAQ somewhere. for instance: Q: I'm new to C++ and I'm just installed vs.net 2005 express, and I want to setup my first opengl project, but I can't find the win32 setup. A: To make win32 programs you need to download the platform sdk (link) you'll also need to set these compiler/linker options if you want your app to be able to run on stock windows installations. etc.. I've tried some simple apps from nehe in vs.net 2005 exp, like the SDL basecode and they don't even distribute when compiled with vs.net 2005 exp. If somebody knows how to do this please post it below (for me) and if you're an admin, please consider putting this in an article or FAQ. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
The problem isn't related to OpenGL but rather to VS 2005 (Express) (So it would be better placed in the general programming section).

VS 2005 Express uses a newer version of CRT that is likely not to be present on windows computers without visual studio (I don't know whether they are part of SP2 or something).

I had the same problem but redistributing the following files (in bin directory, where the exe is located) worked:
msvcm80.dll
msvcp80.dll
msvcr80.dll
Microsoft.VC80.CRT.manifest

(Win XP and VS 2003 are likely to use the xxx71 versions that those xxx80 ones)

Also give it a try and google for your error message: "[ERROR MESSAGE]".

Share this post


Link to post
Share on other sites
those files didn't work. I'm going to post my code here. It's only an opengl framework. I don't have it on this computer but when I do if somebody manages to compile it and run it on a stock windows install I'd be interested to hear about it since I've never managed to get any vs.net app to run outside vs.net.

Share this post


Link to post
Share on other sites
Install http://www.microsoft.com/windows/virtualpc/downloads/sp1.mspx and install xp (trial period) on the virtual machine this will give you a standard xp install and help prepare your application for distribution.

Share this post


Link to post
Share on other sites
Here is my code

these are the libraries I've linked in:
opengl32.lib
glu32.lib
user32.lib
gdi32.lib
winspool.lib
comdlg32.lib
advapi32.lib
shell32.lib
ole32.lib
oleaut32.lib
uuid.lib
kernel32.lib

I haven't played with the default compiler settings otherwise, and have never managed to get this to run under XP without vs.net 2005 express installed.
I've been stuck with this problem for a week. Thanks for any advice/solutions.

this is the WIN32.cpp file

/*
This file should only ever be included in the project if it is being compiled under windows. It keep all the win32 code in one place
and calls cross platform code from it to run the game main loop.
All this file does is create an opengl context and starts up the window.
Its couter part is LINUX.cpp.
*/


#include "Application.h"
#include <windows.h>
#include <gl\gl.h>

HGLRC hRC=NULL;
HDC hDC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;

/*This is a global variable for this file only.*/
Application *app;

//this variable helps this win32 code keep track of fullscreeness
bool g_fullscreen;

//Window message handler (OS messages). Should not do any important message handling, should just forward to cross-platform message handler.
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//Application window clean up
GLvoid KillGLWindow(GLvoid);
//Creates the window
bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag);

//Entery point for the program. Creates the window, deletes the window and loop the appliation object inside.
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
const unsigned int WIDTH = 800;
const unsigned int HEIGHT = 600;
MSG msg;
bool done=false;
/* if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
{
g_fullscreen=false;
} else
g_fullscreen = true;*/

g_fullscreen = false;
if (!CreateGLWindow("OpenGL Framework",WIDTH,HEIGHT,32,g_fullscreen))
{
return 0;
}
app = new Application();
app->initGL();
app->ResizeGL(WIDTH, HEIGHT);
while(!done)
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if (msg.message==WM_QUIT)
{
done=true;
}
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
} else {
app->Loop(0.0f); //TODO: Add timer code.
SwapBuffers(hDC);
}
}
delete app;
KillGLWindow();
return (int)(msg.wParam);
}

//The windows message pump, should pass all data to a cross platform handler.
LRESULT CALLBACK WndProc( HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{

case WM_SYSCOMMAND: //Prevent the computer from starting the screensaver or going into power save mode.
{
switch (wParam)
{
case SC_SCREENSAVE:
case SC_MONITORPOWER:
return 0;
}
break;
}

case WM_CLOSE:
{
PostQuitMessage(0);
return 0;
}

case WM_KEYDOWN:
{
//can handle this later.
return 0;
}

case WM_KEYUP:
{
//can handle this later.
return 0;
}

case WM_SIZE:
{
app->ResizeGL(LOWORD(lParam),HIWORD(lParam));
return 0;
}
}
return DefWindowProc(hWnd,uMsg,wParam,lParam); //pass the message back to windows if we don't care about it.
};


//This is the function that should destroy the win32 resources only, not the application. It is the CreateGLWindow fallback.
GLvoid KillGLWindow(GLvoid)
{
//if we are in fullscreen goto desktop
if (g_fullscreen)
{
ChangeDisplaySettings(NULL,0);
ShowCursor(TRUE);
}
//delete all the window and opengl resources
if (hRC)
{
if (!wglMakeCurrent(NULL,NULL))
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
if (!wglDeleteContext(hRC))
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hRC=NULL;
}
if (hDC && !ReleaseDC(hWnd,hDC))
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL;
}
if (hWnd && !DestroyWindow(hWnd))
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL;
}
if (!UnregisterClass("WoIWindow",hInstance))
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL;
}
};
//Creates the window, handles all error. Can be called worry free.
bool CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat;
WNDCLASS wc;
DWORD dwExStyle;
DWORD dwStyle;
RECT WindowRect;
WindowRect.left=(long)0;
WindowRect.right=(long)width;
WindowRect.top=(long)0;
WindowRect.bottom=(long)height;
g_fullscreen=fullscreenflag;

//Win32 windows menus, icons etc.
hInstance = GetModuleHandle(NULL);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Move, And Own DC For Window
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "WoIWindow";

if (!RegisterClass(&wc)) //Register the window with the OS.
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if (g_fullscreen)
{
DEVMODE dmScreenSettings;
memset(&dmScreenSettings,0,sizeof(dmScreenSettings));
dmScreenSettings.dmSize=sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = width;
dmScreenSettings.dmPelsHeight = height;
dmScreenSettings.dmBitsPerPel = bits;
dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
{
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
g_fullscreen=false;
else {
MessageBox(NULL,"Program Will Now Close.","No fullscreen",MB_OK|MB_ICONSTOP);
return false;
}
}
}
if (g_fullscreen) //If everything went ok with setting fullscreen:
{
dwExStyle=WS_EX_APPWINDOW;
dwStyle=WS_POPUP;
ShowCursor(FALSE);
} else { //If we could not set fullscreen:
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle=WS_OVERLAPPEDWINDOW;
}
AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); //no effect in fullscreen mode.

if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
"WoIWindow", // Class Name
title, // Window Title
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN | // Required Window Style
dwStyle, // Selected Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Adjusted Window Width
WindowRect.bottom-WindowRect.top, // Calculate Adjusted Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Don't Pass Anything To WM_CREATE
{
KillGLWindow();
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}

/***********************************CRITICAL WINDOW SETUP CODE**********************
*
* The structure created below is actually really important for the opengl context.
* If we wanted to add stencil shadows later we would have to change this stucture
* to make sure the the stencil buffer was enabled.
* It is also important to make sure that the linux SDL code sets up EXACTLY the
* as way as this.
*
***********************************************************************************/



static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};
if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?
{
KillGLWindow();
MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
{
KillGLWindow();
MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
{
KillGLWindow();
MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
{
KillGLWindow();
MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context
{
KillGLWindow();
MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return false;
}
ShowWindow(hWnd,SW_SHOW);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
// ReSizeGLScene(width, height);

return true;
};



this is Application.cpp

#include "Application.h"

Application::Application()
{

};

Application::~Application()
{

};

void Application::Loop(float dt)
{
//RENDER HAS TO BE LAST SINCE SwapBuffers(hDC); IN WIN32 NEEDS TO COME RIGHT AFTER IT.
Render();
};

void Application::initGL()
{
//Generally don't mess with these.
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

//Can mess with these values.
glEnable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);
};

void Application::Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
};

void Application::ResizeGL(unsigned int width, unsigned int height)
{
if (height==0) //If the user makes the window 0 pixels high, set the height to 1 to avoid a divide by 0.
height=1;

glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
};



this is Application.h


#ifndef _APPLICATION_MOD_
#define _APPLICATION_MOD_

#ifdef WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>


/*This class is the "entery point" and the hub for the cross platfrom code. WIN32.cpp and LINUX.cpp both init this class and run its Loop() funciton.
The game is then run completely from inside here. The constructor can be considered as the main() function and the loop can be considered to run non-stop until the program is done.
The destructor HAS to clean up all memory this class creates. WIN32.cpp and LINUX.cpp will not handle any of it.*/

class Application
{
public:
/*The constuctor, can be considered to be the entery point of the app.*/
Application();
/*Can be considered to be the last lines run by the app.*/
~Application();

/*When the window is resized opengl needs to know about it so that it can adjust the aspect ratio. Pass the new info here and this function will take care of it.
IMPORTANT: Make sure this function is called when the window is created to setup the initial aspect.*/

void ResizeGL(unsigned int width, unsigned int height);

/*Looped from within the windowing code. dt is in seconds since the last call to this function.*/
void Loop(float dt);

/*Sets up opengl specific libraries like GLee and devIL. Also setups up lighting, rendering quality etc. Once this is called the app is ready for glBegin() and glEnd()*/
void initGL();
private:
void Render();
};

#endif

Share this post


Link to post
Share on other sites
I think Lord_Evil is right.

Here is a link to a zip file you may want to include in your distribution.

The zip file contains a directory whose content (note: not the directory itself) must be copied where your .exe lies.

Share this post


Link to post
Share on other sites
i changed my runtime from multithreaded dll to just multithreaded and it seemed to fix everything. I'm just curious as to what effect that has on a program, and if there should be a way to distribute apps that use multi-threaded dll.
thanks again to all those who took the time to reply.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!