BaLtHaZaR
08-04-2009, 01:26 AM
Hello everyone.I am new here and i don't realy know how things work around here.This is my first time on a OpenGL forum.
So here is my problem: I try to create a map editor for a game engine.I did all the WIN32 stuff and works very good,but the openGL code seems that don't work.I created a RASTER class that includes the Init and Release functions.I use them in my code but the first problem i have is that when i use an object of type RASTER it don't recognise the declaration of Release function.And the second is that i don't see anything in my RenderWindow.I hope anyone reed this and maybe help me finish my project.For the Release function i receive this error:
expected constructor, destructor, or type conversion before '.' token
this is my MapEditor.cpp fire:
#include<windows.h>
#include<winbase.h>
#include<stdio.h>
#include "resource.h"
#include "RASTER.h"
#define DEFAULT_BUTTON_WIDTH 100
#define DEFAULT_BUTTON_HEIGHT 20
HINSTANCE GlobalInstance;
HMENU Menu;
HMENU PopupMenu;
HWND Window;
HWND bCreateWall;
HWND ComboBox;
HWND RenderWindow;
RASTER raster;
LRESULT CALLBACK WndProc (HWND , UINT , WPARAM , LPARAM );
LRESULT CALLBACK MapDetailsDlgProc(HWND, UINT, WPARAM, LPARAM);
void WMCommand(HWND , UINT , WPARAM w, LPARAM );
void DisplayPopupMenu(long , long );
void ResizeGLWindow(long,long);
void WMSize(HWND,UINT ,WPARAM, LPARAM );
void SetGLDefaults(void);
void WMSize(HWND , UINT , WPARAM w, LPARAM );
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevious,LPSTR lpCmdString,int nFunsterStil)
{
MSG msg;
WNDCLASS wc;
RECT rect;
GlobalInstance = hInstance;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wc.hInstance = hInstance;
wc.lpszClassName = "ME";
wc.lpfnWndProc = WndProc;
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.lpszMenuName = NULL;
if (!RegisterClass(&wc))
{
MessageBox (NULL,"Error:Cannot Register Class","ERROR!",MB_OK);
return (0);
}
Window = CreateWindow ("ME","Map Editor",WS_OVERLAPPEDWINDOW,
0,0,640,480,NULL,NULL,hInstance,NULL);
ShowWindow (Window, nFunsterStil);
if(Window == NULL)
{
MessageBox (NULL,"Error:Failed to Create Window","ERROR!",MB_OK);
return(0);
}
GetWindowRect(Window,&rect);
bCreateWall = CreateWindow("BUTTON","Create Wall", WS_CHILD |WS_VISIBLE,
0,100,DEFAULT_BUTTON_WIDTH,DEFAULT_BUTTON_HEIGHT,W indow,NULL,hInstance,NULL);
RenderWindow = CreateWindow("STATIC",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER,DEFAULT_BUTTON_WIDTH,
0,rect.right-rect.left-DEFAULT_BUTTON_WIDTH,rect.bottom-rect.top,Window,NULL,hInstance,NULL);
Menu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU));
SetMenu(Window,Menu);
PopupMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_POPMENU));
if(!raster.Init(RenderWindow))return(0);
GetClientRect(RenderWindow,&rect);
ResizeGLWindow(rect.right-rect.left,rect.bottom-rect.top);
SetGLDefaults();
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(1);
}
raster.Release(RenderWindow);
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_COMMAND:
WMCommand(hWnd,msg,wParam,lParam);
break;
case WM_SIZE:
WMSize(hWnd,msg,wParam,lParam);
break;
case WM_RBUTTONUP:
DisplayPopupMenu(LOWORD(lParam),HIWORD(lParam));
break;
default:
return DefWindowProc (hWnd, msg, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK MapDetailsDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
SetDlgItemText(hWnd,IDC_MAP_DETAILS_NAME,"Map Name");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_ADDSTRING,0,(LPARAM)"Erase Me");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_RESETCONTENT,0,0);
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_ADDSTRING,0,(LPARAM)"Single Player");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_ADDSTRING,0,(LPARAM)"Multi Player");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_SETCURSEL,0,1);
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_ADDSTRING,0,(LPARAM)"Erase Me");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_RESETCONTENT,0,0);
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_ADDSTRING,0,(LPARAM)"Exit");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_ADDSTRING,0,(LPARAM)"Get Fragged");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_SETCURSEL,0,1);
case WM_COMMAND:
if(wParam == IDOK)
{
long level_type = SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,
CB_GETCURSEL,0,0);
long level_rule = SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,
LB_GETCURSEL,0,0);
char temp[500];
sprintf(temp,"Level Type: %i\r\nLevel Rule: %i\r\nOK Button!",level_type,level_rule);
MessageBox(hWnd,temp,"OK",MB_OK);
EndDialog(hWnd,0);
}
else if(wParam == IDCANCEL)
{
MessageBox(hWnd,"Cancel Button!","Cancel",MB_OK);
EndDialog(hWnd,0);
}
break;
}
return(0);
}
void WMCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if(lParam ==(LPARAM)bCreateWall) MessageBox(Window,"You Pressed bCreateWall",
"Congrats!",MB_OK);
else if(wParam == ID_FILE_EXIT)PostQuitMessage(0);
else if(wParam == ID_DRAWING_WIREFRAME)
{
CheckMenuItem(Menu,ID_DRAWING_WIREFRAME, MF_CHECKED);
CheckMenuItem(Menu,ID_DRAWING_SOLID, MF_UNCHECKED);
}
else if(wParam == ID_DRAWING_SOLID)
{
CheckMenuItem(Menu,ID_DRAWING_SOLID, MF_CHECKED);
CheckMenuItem(Menu,ID_DRAWING_WIREFRAME, MF_UNCHECKED);
}
else if(wParam == ID_FILE_MOVE)MessageBox(Window,"Move","Click",MB_OK);
else if(wParam == ID_FILE_DELETE)MessageBox(Window,"Delete","Click",MB_OK);
else if(wParam == ID_FILE_TEXTURE)MessageBox(Window,"Texture","Click",MB_OK);
else if(wParam == ID_FILE_DUPLICATE)MessageBox(Window,"Duplicate","Click",MB_OK);
else if(wParam == ID_MAP_DETAILS)DialogBox(GlobalInstance,
MAKEINTRESOURCE(IDD_MAP_DETAILS),NULL,(DLGPROC)Map DetailsDlgProc);
}
void DisplayPopupMenu(long x , long y )
{
HMENU temp = GetSubMenu(PopupMenu,0);
TrackPopupMenu(temp,TPM_LEFTALIGN | TPM_RIGHTBUTTON,x,y,0,Window,NULL);
}
void ResizeGLWindow(long width,long height)
{
glViewport(0,0,(GLsizei)width,(GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-200,200, -200,200, -2000,2000);
glMatrixMode(GL_MODELVIEW);
}
void SetGLDefaults()
{
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
}
void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.6f,0.6f,0.6f,1.0f);
glLoadIdentity();
glPushMatrix();
glTranslatef(0.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.05f,-0.05f,0.0f);
glVertex3f(0.95f,-0.05f,0.0f);
glVertex3f(0.95f,-0.95f,0.0f);
glVertex3f(0.05f,-0.95f,0.0f);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(-0.25f,-0.25f,0.0f);
glVertex3f(-0.50f,-0.125f,0.0f);
glVertex3f(-0.75f,-0.25f,0.0f);
glVertex3f(-0.875f,-0.5f,0.0f);
glVertex3f(-0.75f,-0.75f,0.0f);
glVertex3f(-0.50f,-0.875f,0.0f);
glVertex3f(-0.25f,-0.75f,0.0f);
glVertex3f(-0.125f,-0.5f,0.0f);
glEnd();
glBegin(GL_LINES);
glVertex3f(-0.25f,0.25f,0.0f);
glVertex3f(-0.75f,0.75f,0.0f);
glEnd();
glPopMatrix();
SwapBuffers(hDC);
}
void WMSize(HWND hWnd,UINT msg,WPARAM wParam, LPARAM lParam)
{
RECT rect;
GetClientRect(Window,&rect);
MoveWindow(RenderWindow,DEFAULT_BUTTON_WIDTH,0,
rect.right-rect.left-DEFAULT_BUTTON_WIDTH,rect.bottom-rect.top,true);
GetClientRect(RenderWindow,&rect);
ResizeGLWindow(rect.right-rect.left,rect.bottom-rect.top);
}
and this is RASTER class file:
#include<windows.h>
#include<GL/gl.h>
#include<GL/glu.h>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
HDC hDC;
class RASTER
{
public:
bool Init(HWND hwnd,unsigned char color_bits = 24 ,unsigned char depth_bits = 32);
bool Release(HWND hWnd);
};
bool RASTER::Init(HWND hWnd,unsigned char color_bits ,unsigned char depth_bits )
{
PIXELFORMATDESCRIPTOR pfd;
int PixelFormat;
HGLRC glrc;
hDC = GetDC(hWnd);
if(hDC == NULL)
{
MessageBox(hWnd,"Error: Can't Get Device Context for Window!","ERROR",MB_OK|MB_ICONERROR);
return(false);
}
/*Original Method
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = color_bits;
pfd.cRedbits = 0;
pfd.cRedShift = 0;
pfd.cGreenBits = 0;
pfd.cGreenShift = 0;
pfd.cBlueBits = 0;
pfd.cBlueShift = 0;
pfd.cAlphaBits = 0;
pfd.cAlphaShift = 0;
pfd.cAccumbits = 0;
pfd.AccumRedBits = 0;
pfd.cAccumGreenBits = 0;
pfd.AccumBlueBits = 0;
pfd.AccumAlphaBits = 0;
pfd.cDepthbits = depth_bits;
pfd.cStencilBits = 0;
pfd.cAuxBuffers = 0;
pfd.cLayerType = 0;
pfd.bReserved = 0;
pfd.dwLayerMask = 0;
pfd.dwVisibleMask = 0;
pfd.dwDamageMask = 0;
*/
memset(&pfd,0,sizeof(pfd));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.cColorBits = color_bits;
pfd.cDepthBits = depth_bits;
PixelFormat = ChoosePixelFormat(hDC,&pfd);
if(PixelFormat == 0)
{
MessageBox(hWnd,"Error;Can't Choose Pixel Format","ERROR",MB_OK |MB_ICONERROR);
ReleaseDC(hWnd,hDC);
hDC =NULL;
return(false);
}
if(SetPixelFormat(hDC,PixelFormat,&pfd)==0)
{
MessageBox(hWnd,"Error: Can't Set The Pixel Format","ERROR",MB_OK |MB_ICONERROR);
ReleaseDC(hWnd,hDC);
hDC = NULL;
return(false);
}
glrc = wglCreateContext(hDC);
if(glrc == NULL)
{
MessageBox(hWnd,"Error: Can't Create GL Context","ERROR",MB_OK |MB_ICONERROR);
ReleaseDC(hWnd,hDC);
hDC = NULL;
return(false);
}
if(!wglMakeCurrent(hDC,glrc))
{
MessageBox(hWnd,"Error: Can't Make Current GL Context","ERROR",MB_OK |MB_ICONERROR);
ReleaseDC(hWnd,hDC);
glrc = NULL;
hDC = NULL;
return(false);
}
return(true);
}
bool RASTER::Release(HWND hWnd)
{
HDC hDC;
HGLRC glrc;
if(hDC == NULL || glrc == NULL) return(false);
if(wglMakeCurrent(NULL,NULL) == false)
{
MessageBox(hWnd,"Error: Release Of DC And RC Failed","Release Error" ,MB_OK |MB_ICONERROR);
return(false);
}
if(wglDeleteContext(glrc)==false)
{
MessageBox(hWnd,"Error: Release Rendering Context Failed","Release Error", MB_OK |MB_ICONERROR);
return(false);
}
glrc = NULL;
if(ReleaseDC(hWnd,hDC)==false)
{
MessageBox(hWnd,"Error: Release Device Context Failed", "Release Error", MB_OK |MB_ICONERROR);
return(false);
}
hDC = NULL;
return(true);
}
Hope someone will read this and help me.Thank you very much
So here is my problem: I try to create a map editor for a game engine.I did all the WIN32 stuff and works very good,but the openGL code seems that don't work.I created a RASTER class that includes the Init and Release functions.I use them in my code but the first problem i have is that when i use an object of type RASTER it don't recognise the declaration of Release function.And the second is that i don't see anything in my RenderWindow.I hope anyone reed this and maybe help me finish my project.For the Release function i receive this error:
expected constructor, destructor, or type conversion before '.' token
this is my MapEditor.cpp fire:
#include<windows.h>
#include<winbase.h>
#include<stdio.h>
#include "resource.h"
#include "RASTER.h"
#define DEFAULT_BUTTON_WIDTH 100
#define DEFAULT_BUTTON_HEIGHT 20
HINSTANCE GlobalInstance;
HMENU Menu;
HMENU PopupMenu;
HWND Window;
HWND bCreateWall;
HWND ComboBox;
HWND RenderWindow;
RASTER raster;
LRESULT CALLBACK WndProc (HWND , UINT , WPARAM , LPARAM );
LRESULT CALLBACK MapDetailsDlgProc(HWND, UINT, WPARAM, LPARAM);
void WMCommand(HWND , UINT , WPARAM w, LPARAM );
void DisplayPopupMenu(long , long );
void ResizeGLWindow(long,long);
void WMSize(HWND,UINT ,WPARAM, LPARAM );
void SetGLDefaults(void);
void WMSize(HWND , UINT , WPARAM w, LPARAM );
int WINAPI WinMain (HINSTANCE hInstance,HINSTANCE hPrevious,LPSTR lpCmdString,int nFunsterStil)
{
MSG msg;
WNDCLASS wc;
RECT rect;
GlobalInstance = hInstance;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
wc.hInstance = hInstance;
wc.lpszClassName = "ME";
wc.lpfnWndProc = WndProc;
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.lpszMenuName = NULL;
if (!RegisterClass(&wc))
{
MessageBox (NULL,"Error:Cannot Register Class","ERROR!",MB_OK);
return (0);
}
Window = CreateWindow ("ME","Map Editor",WS_OVERLAPPEDWINDOW,
0,0,640,480,NULL,NULL,hInstance,NULL);
ShowWindow (Window, nFunsterStil);
if(Window == NULL)
{
MessageBox (NULL,"Error:Failed to Create Window","ERROR!",MB_OK);
return(0);
}
GetWindowRect(Window,&rect);
bCreateWall = CreateWindow("BUTTON","Create Wall", WS_CHILD |WS_VISIBLE,
0,100,DEFAULT_BUTTON_WIDTH,DEFAULT_BUTTON_HEIGHT,W indow,NULL,hInstance,NULL);
RenderWindow = CreateWindow("STATIC",NULL,WS_CHILD | WS_VISIBLE | WS_BORDER,DEFAULT_BUTTON_WIDTH,
0,rect.right-rect.left-DEFAULT_BUTTON_WIDTH,rect.bottom-rect.top,Window,NULL,hInstance,NULL);
Menu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU));
SetMenu(Window,Menu);
PopupMenu = LoadMenu(hInstance,MAKEINTRESOURCE(IDR_POPMENU));
if(!raster.Init(RenderWindow))return(0);
GetClientRect(RenderWindow,&rect);
ResizeGLWindow(rect.right-rect.left,rect.bottom-rect.top);
SetGLDefaults();
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return(1);
}
raster.Release(RenderWindow);
LRESULT CALLBACK WndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch (msg)
{
case WM_DESTROY:
PostQuitMessage (0);
break;
case WM_COMMAND:
WMCommand(hWnd,msg,wParam,lParam);
break;
case WM_SIZE:
WMSize(hWnd,msg,wParam,lParam);
break;
case WM_RBUTTONUP:
DisplayPopupMenu(LOWORD(lParam),HIWORD(lParam));
break;
default:
return DefWindowProc (hWnd, msg, wParam, lParam);
}
return 0;
}
LRESULT CALLBACK MapDetailsDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_INITDIALOG:
SetDlgItemText(hWnd,IDC_MAP_DETAILS_NAME,"Map Name");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_ADDSTRING,0,(LPARAM)"Erase Me");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_RESETCONTENT,0,0);
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_ADDSTRING,0,(LPARAM)"Single Player");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_ADDSTRING,0,(LPARAM)"Multi Player");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,CB_SETCURSEL,0,1);
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_ADDSTRING,0,(LPARAM)"Erase Me");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_RESETCONTENT,0,0);
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_ADDSTRING,0,(LPARAM)"Exit");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_ADDSTRING,0,(LPARAM)"Get Fragged");
SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,LB_SETCURSEL,0,1);
case WM_COMMAND:
if(wParam == IDOK)
{
long level_type = SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_TYPE ,
CB_GETCURSEL,0,0);
long level_rule = SendDlgItemMessage(hWnd,IDC_MAP_DETAILS_LEVEL_RULE S,
LB_GETCURSEL,0,0);
char temp[500];
sprintf(temp,"Level Type: %i\r\nLevel Rule: %i\r\nOK Button!",level_type,level_rule);
MessageBox(hWnd,temp,"OK",MB_OK);
EndDialog(hWnd,0);
}
else if(wParam == IDCANCEL)
{
MessageBox(hWnd,"Cancel Button!","Cancel",MB_OK);
EndDialog(hWnd,0);
}
break;
}
return(0);
}
void WMCommand(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if(lParam ==(LPARAM)bCreateWall) MessageBox(Window,"You Pressed bCreateWall",
"Congrats!",MB_OK);
else if(wParam == ID_FILE_EXIT)PostQuitMessage(0);
else if(wParam == ID_DRAWING_WIREFRAME)
{
CheckMenuItem(Menu,ID_DRAWING_WIREFRAME, MF_CHECKED);
CheckMenuItem(Menu,ID_DRAWING_SOLID, MF_UNCHECKED);
}
else if(wParam == ID_DRAWING_SOLID)
{
CheckMenuItem(Menu,ID_DRAWING_SOLID, MF_CHECKED);
CheckMenuItem(Menu,ID_DRAWING_WIREFRAME, MF_UNCHECKED);
}
else if(wParam == ID_FILE_MOVE)MessageBox(Window,"Move","Click",MB_OK);
else if(wParam == ID_FILE_DELETE)MessageBox(Window,"Delete","Click",MB_OK);
else if(wParam == ID_FILE_TEXTURE)MessageBox(Window,"Texture","Click",MB_OK);
else if(wParam == ID_FILE_DUPLICATE)MessageBox(Window,"Duplicate","Click",MB_OK);
else if(wParam == ID_MAP_DETAILS)DialogBox(GlobalInstance,
MAKEINTRESOURCE(IDD_MAP_DETAILS),NULL,(DLGPROC)Map DetailsDlgProc);
}
void DisplayPopupMenu(long x , long y )
{
HMENU temp = GetSubMenu(PopupMenu,0);
TrackPopupMenu(temp,TPM_LEFTALIGN | TPM_RIGHTBUTTON,x,y,0,Window,NULL);
}
void ResizeGLWindow(long width,long height)
{
glViewport(0,0,(GLsizei)width,(GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-200,200, -200,200, -2000,2000);
glMatrixMode(GL_MODELVIEW);
}
void SetGLDefaults()
{
glEnable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
}
void Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.6f,0.6f,0.6f,1.0f);
glLoadIdentity();
glPushMatrix();
glTranslatef(0.0f,0.0f,0.0f);
glBegin(GL_TRIANGLES);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(0.0f,1.0f,0.0f);
glVertex3f(1.0f,1.0f,0.0f);
glEnd();
glBegin(GL_QUADS);
glVertex3f(0.05f,-0.05f,0.0f);
glVertex3f(0.95f,-0.05f,0.0f);
glVertex3f(0.95f,-0.95f,0.0f);
glVertex3f(0.05f,-0.95f,0.0f);
glEnd();
glBegin(GL_POLYGON);
glVertex3f(-0.25f,-0.25f,0.0f);
glVertex3f(-0.50f,-0.125f,0.0f);
glVertex3f(-0.75f,-0.25f,0.0f);
glVertex3f(-0.875f,-0.5f,0.0f);
glVertex3f(-0.75f,-0.75f,0.0f);
glVertex3f(-0.50f,-0.875f,0.0f);
glVertex3f(-0.25f,-0.75f,0.0f);
glVertex3f(-0.125f,-0.5f,0.0f);
glEnd();
glBegin(GL_LINES);
glVertex3f(-0.25f,0.25f,0.0f);
glVertex3f(-0.75f,0.75f,0.0f);
glEnd();
glPopMatrix();
SwapBuffers(hDC);
}
void WMSize(HWND hWnd,UINT msg,WPARAM wParam, LPARAM lParam)
{
RECT rect;
GetClientRect(Window,&rect);
MoveWindow(RenderWindow,DEFAULT_BUTTON_WIDTH,0,
rect.right-rect.left-DEFAULT_BUTTON_WIDTH,rect.bottom-rect.top,true);
GetClientRect(RenderWindow,&rect);
ResizeGLWindow(rect.right-rect.left,rect.bottom-rect.top);
}
and this is RASTER class file:
#include<windows.h>
#include<GL/gl.h>
#include<GL/glu.h>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
HDC hDC;
class RASTER
{
public:
bool Init(HWND hwnd,unsigned char color_bits = 24 ,unsigned char depth_bits = 32);
bool Release(HWND hWnd);
};
bool RASTER::Init(HWND hWnd,unsigned char color_bits ,unsigned char depth_bits )
{
PIXELFORMATDESCRIPTOR pfd;
int PixelFormat;
HGLRC glrc;
hDC = GetDC(hWnd);
if(hDC == NULL)
{
MessageBox(hWnd,"Error: Can't Get Device Context for Window!","ERROR",MB_OK|MB_ICONERROR);
return(false);
}
/*Original Method
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = color_bits;
pfd.cRedbits = 0;
pfd.cRedShift = 0;
pfd.cGreenBits = 0;
pfd.cGreenShift = 0;
pfd.cBlueBits = 0;
pfd.cBlueShift = 0;
pfd.cAlphaBits = 0;
pfd.cAlphaShift = 0;
pfd.cAccumbits = 0;
pfd.AccumRedBits = 0;
pfd.cAccumGreenBits = 0;
pfd.AccumBlueBits = 0;
pfd.AccumAlphaBits = 0;
pfd.cDepthbits = depth_bits;
pfd.cStencilBits = 0;
pfd.cAuxBuffers = 0;
pfd.cLayerType = 0;
pfd.bReserved = 0;
pfd.dwLayerMask = 0;
pfd.dwVisibleMask = 0;
pfd.dwDamageMask = 0;
*/
memset(&pfd,0,sizeof(pfd));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.cColorBits = color_bits;
pfd.cDepthBits = depth_bits;
PixelFormat = ChoosePixelFormat(hDC,&pfd);
if(PixelFormat == 0)
{
MessageBox(hWnd,"Error;Can't Choose Pixel Format","ERROR",MB_OK |MB_ICONERROR);
ReleaseDC(hWnd,hDC);
hDC =NULL;
return(false);
}
if(SetPixelFormat(hDC,PixelFormat,&pfd)==0)
{
MessageBox(hWnd,"Error: Can't Set The Pixel Format","ERROR",MB_OK |MB_ICONERROR);
ReleaseDC(hWnd,hDC);
hDC = NULL;
return(false);
}
glrc = wglCreateContext(hDC);
if(glrc == NULL)
{
MessageBox(hWnd,"Error: Can't Create GL Context","ERROR",MB_OK |MB_ICONERROR);
ReleaseDC(hWnd,hDC);
hDC = NULL;
return(false);
}
if(!wglMakeCurrent(hDC,glrc))
{
MessageBox(hWnd,"Error: Can't Make Current GL Context","ERROR",MB_OK |MB_ICONERROR);
ReleaseDC(hWnd,hDC);
glrc = NULL;
hDC = NULL;
return(false);
}
return(true);
}
bool RASTER::Release(HWND hWnd)
{
HDC hDC;
HGLRC glrc;
if(hDC == NULL || glrc == NULL) return(false);
if(wglMakeCurrent(NULL,NULL) == false)
{
MessageBox(hWnd,"Error: Release Of DC And RC Failed","Release Error" ,MB_OK |MB_ICONERROR);
return(false);
}
if(wglDeleteContext(glrc)==false)
{
MessageBox(hWnd,"Error: Release Rendering Context Failed","Release Error", MB_OK |MB_ICONERROR);
return(false);
}
glrc = NULL;
if(ReleaseDC(hWnd,hDC)==false)
{
MessageBox(hWnd,"Error: Release Device Context Failed", "Release Error", MB_OK |MB_ICONERROR);
return(false);
}
hDC = NULL;
return(true);
}
Hope someone will read this and help me.Thank you very much