00001
00002
00003
00004 #include "stdafx.h"
00005 #include "SDKParticules.h"
00006 #include "..\sdkparticules\glview.h"
00007
00008
00009
00010
00011 IMPLEMENT_DYNAMIC(CGlView, CWnd)
00012 CGlView::CGlView()
00013 {
00014 }
00015
00016 CGlView::CGlView(CWnd *pWnd)
00017 {
00018 m_pWnd = pWnd;
00019 m_hWnd = pWnd->m_hWnd;
00020 m_hDC = ::GetDC(m_hWnd);
00021 m_fZoom = -10.0f;
00022 m_fAngleX = 45.0f;
00023 m_fAngleY = 45.0f;
00024 m_ShowGrid=false;
00025 }
00026
00027 CGlView::~CGlView()
00028 {
00029 }
00030
00031 BOOL CGlView::SetPixelformat(HDC hdc)
00032 {
00033
00034 PIXELFORMATDESCRIPTOR *ppfd;
00035 int pixelformat;
00036
00037 PIXELFORMATDESCRIPTOR pfd = {
00038 sizeof(PIXELFORMATDESCRIPTOR),
00039 1,
00040 PFD_DRAW_TO_WINDOW |
00041 PFD_SUPPORT_OPENGL |
00042 PFD_GENERIC_FORMAT |
00043 PFD_DOUBLEBUFFER,
00044 PFD_TYPE_RGBA,
00045 32,
00046 0, 0, 0, 0, 0, 0,
00047 8,
00048 0,
00049 8,
00050 0, 0, 0, 0,
00051 64,
00052 8,
00053 8,
00054 PFD_MAIN_PLANE,
00055 0,
00056 0, 0, 0
00057 };
00058
00059
00060 ppfd = &pfd;
00061
00062
00063 if ( (pixelformat = ChoosePixelFormat(hdc, ppfd)) == 0 )
00064 {
00065 ::MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
00066 return FALSE;
00067 }
00068
00069 if (SetPixelFormat(hdc, pixelformat, ppfd) == FALSE)
00070 {
00071 ::MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
00072 return FALSE;
00073 }
00074
00075 return TRUE;
00076
00077 }
00078
00079
00080 GLvoid CGlView::ReSizeGLScene(GLsizei width, GLsizei height)
00081 {
00082
00083 if (height==0)
00084 {
00085 height=1;
00086 }
00087
00088 glViewport(0,0,width,height);
00089
00090 glMatrixMode(GL_PROJECTION);
00091 glLoadIdentity();
00092
00093
00094 gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
00095
00096 glMatrixMode(GL_MODELVIEW);
00097 glLoadIdentity();
00098
00099 }
00100
00101
00102 int CGlView::InitGL(GLvoid)
00103 {
00104 m_hDC = ::GetDC(this->m_hWnd);
00105
00106 if(!SetPixelformat(m_hDC))
00107 {
00108 ::MessageBox(::GetFocus(),"SetPixelformat Failed!","Error",MB_OK);
00109 return -1;
00110 }
00111
00112 m_hRC = wglCreateContext(m_hDC);
00113 int i= wglMakeCurrent(m_hDC,m_hRC);
00114
00115 glShadeModel(GL_SMOOTH);
00116 glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
00117 glClearDepth(1.0f);
00118 glDepthFunc(GL_LEQUAL);
00119 glCullFace(GL_BACK);
00120 glEnable(GL_CULL_FACE);
00121 glEnable(GL_DEPTH_TEST);
00122
00123 ExNihilo::InitBasicObjectList();
00124 LoadTexture("../Data/Textures/twirl.bmp");
00125 system.SetParticuleTextureName("twirl");
00126 return TRUE;
00127 }
00128
00129
00130 int CGlView::DrawGLScene(GLvoid)
00131 {
00132 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00133 glLoadIdentity();
00134 glTranslatef(0.0f,0.0f,m_fZoom);
00135 glRotatef(m_fAngleX,1.0,0.0,0.0);
00136 glRotatef(m_fAngleY,0.0,1.0,0.0);
00137
00138 glDisable(GL_LIGHTING);
00139 glDisable(GL_TEXTURE_2D);
00140
00141 if(m_ShowGrid)glCallList(GRILLE);
00142
00143 glDisable(GL_LIGHTING);
00144 glColor3f(0.2f,0.2f,0.2f);
00145 glBegin(GL_QUADS);
00146 glVertex3f(-10.0f,- 0.5f,10.0f);
00147 glVertex3f( 10.0f,- 0.5f,10.0f);
00148 glVertex3f( 10.0f,- 0.5f,-10.0f);
00149 glVertex3f(-10.0f,- 0.5f,-10.0f);
00150 glEnd();
00151
00152 glDisable(GL_LIGHTING);
00153 glDisable(GL_TEXTURE_2D);
00154 system.Draw();
00155
00156 SwapBuffers(m_hDC);
00157 return TRUE;
00158 }
00159
00160 void CGlView::IncreaseZoom(void)
00161 {
00162 m_fZoom=m_fZoom+1.0f;
00163 }
00164
00165 void CGlView::DecreaseZoom(void)
00166 {
00167 m_fZoom=m_fZoom-1.0f;
00168 }
00169
00170 bool CGlView::LoadTexture (CString fileName)
00171 {
00172 int Status=FALSE;
00173 AUX_RGBImageRec *TextureImage[1];
00174 memset(TextureImage,0,sizeof(void *)*1);
00175
00176 if (TextureImage[0]=auxDIBImageLoad(fileName) )
00177 {
00178 Status=TRUE;
00179 glDeleteTextures(1, &texture[0]);
00180 glGenTextures(1, &texture[0]);
00181 glBindTexture(GL_TEXTURE_2D, texture[0]);
00182 glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
00183 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
00184 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
00185 }
00186
00187 if (TextureImage[0])
00188 {
00189 if (TextureImage[0]->data)
00190 {
00191 free(TextureImage[0]->data);
00192 }
00193
00194 free(TextureImage[0]);
00195 }
00196 system.m_TextureID=texture[0];
00197
00198 return Status;
00199 }
00200
00201 BEGIN_MESSAGE_MAP(CGlView, CWnd)
00202 END_MESSAGE_MAP()
00203
00204
00205
00206
00207
00208
00209