I still can't seem to find any way to make working release version.
Could someone please try this code on visual studio and tell me if release version works for them without any errors?
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <WindowsX.h>
#define GLEW_STATIC
#include <glew.h>
#pragma comment(lib, "glew32s.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#include <string>
#include <vector>
#include <set>
#include <hash_map>
#include <sstream>
#include <stdio.h>
#include <fstream>
#include <iostream>
HWND hWnd;
HDC hDC;
HGLRC hRC;
#define LOGI(...) { char buff[10240]; sprintf_s(buff, __VA_ARGS__); OutputDebugStringA("INFO: "); OutputDebugStringA(buff); OutputDebugStringA("\n"); }
#define LOGW(...) { char buff[10240]; sprintf_s(buff, __VA_ARGS__); OutputDebugStringA("WARNING: "); OutputDebugStringA(buff); OutputDebugStringA("\n"); }
#define LOGE(...) { char buff[10240]; sprintf_s(buff, __VA_ARGS__); MessageBoxA(0, buff, "Error", MB_ICONERROR); \
OutputDebugStringA("ERROR: "); OutputDebugStringA(buff); OutputDebugStringA("\n"); }
// Set up pixel format for graphics initialization
void SetupPixelFormat()
{
PIXELFORMATDESCRIPTOR pfd, *ppfd;
int pixelformat;
ppfd = &pfd;
ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
ppfd->nVersion = 1;
ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
ppfd->dwLayerMask = PFD_MAIN_PLANE;
ppfd->iPixelType = PFD_TYPE_COLORINDEX;
ppfd->cColorBits = 16;
ppfd->cDepthBits = 24;
ppfd->cAccumBits = 0;
ppfd->cStencilBits = 0;
pixelformat = ChoosePixelFormat(hDC, ppfd);
SetPixelFormat(hDC, pixelformat, ppfd);
}
// Initialize OpenGL graphics
bool InitGraphics()
{
hDC = GetDC(hWnd);
SetupPixelFormat();
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
GLenum err = glewInit();
if (err != GLEW_OK) {
LOGE("GLEW not initialized.");
return false;
}
if (!GLEW_VERSION_2_1) {
LOGE("GLEW doesn't support OpenGL 2.1");
return false;
}
return true;
}
// Resize graphics to fit window
void ResizeGraphics()
{
// Get new window size
RECT rect;
GetClientRect(hWnd, &rect);
int width = rect.right;
int height = rect.bottom;
}
// Draw frame
void DrawGraphics()
{
// Show the new scene
SwapBuffers(hDC);
}
// Handle window events and messages
LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_MOUSEMOVE:
break;
case WM_SIZE:
ResizeGraphics();
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
// Default event handler
default:
return DefWindowProc (hWnd, uMsg, wParam, lParam);
break;
}
return 1;
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
#ifdef _DEBUG
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG );
#endif
const LPCWSTR appname = TEXT("Ghost engine");
WNDCLASS wndclass;
MSG msg;
// Define the window class
wndclass.style = 0;
wndclass.lpfnWndProc = (WNDPROC)MainWndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon(hInstance, appname);
wndclass.hCursor = LoadCursor(NULL,IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wndclass.lpszMenuName = appname;
wndclass.lpszClassName = appname;
//wndclass.hIcon = static_cast<HICON>(LoadImage(hInstance, MAKEINTRESOURCE(IDI_ERROR), IMAGE_ICON, 32, 32, LR_DEFAULTSIZE));
// Register the window class
if (!RegisterClass(&wndclass)) {
LOGE("Failed to register window struct.");
return FALSE;
}
// Create the window
hWnd = CreateWindow(
appname,
appname,
WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
CW_USEDEFAULT,
CW_USEDEFAULT,
800,
600,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd) {
LOGE("Failed to initialize window.");
return false;
}
// Initialize OpenGL
if (!InitGraphics()) {
LOGI("Deleting engine.");
wglDeleteContext(hRC);
ReleaseDC(hWnd, hDC);
}
// Display the window
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
// Event loop
while (true)
{
if (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) == TRUE)
{
if (!GetMessage(&msg, NULL, 0, 0)) break;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
DrawGraphics();
}
LOGI("Deleting engine.");
wglDeleteContext(hRC);
ReleaseDC(hWnd, hDC);
return 1;
}