// cview_basic.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "cview_basic.h"
#include "MainFrm.h"
#include "cview_basicDoc.h"
#include "cview_basicView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCview_basicApp
BEGIN_MESSAGE_MAP(CCview_basicApp, CWinApp)
//{{AFX_MSG_MAP(CCview_basicApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will
add and remove mapping macros here.
// DO NOT EDIT
what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCview_basicApp construction
CCview_basicApp::CCview_basicApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and
only CCview_basicApp object
CCview_basicApp theApp;
TCHAR szConfig[]=_T("Config");
/////////////////////////////////////////////////////////////////////////////
// CCview_basicApp initialization
BOOL CCview_basicApp::InitInstance()
{
// Standard initialization
// If you are not using these features and wish to reduce
the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
// Change the registry key under which our settings are
stored.
// TODO: You should modify this string to be something
appropriate
// such as the name of your company or organization.
Enable3dControls();
SetRegistryKey(_T("Chad Screen Savers Inc."));
WriteProfileInt(szConfig, _T("Style"),
0);
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and
views.
if (_mbsnicmp(reinterpret_cast<unsigned char*>(m_lpCmdLine), reinterpret_cast<unsigned char*>("/c"), 2) == 0) {
OnAppAbout();
return TRUE;
}
if (_mbsnicmp(reinterpret_cast<unsigned char*>(m_lpCmdLine), reinterpret_cast<unsigned char*>("/p"), 2) == 0) {
return TRUE;
}
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CCview_basicDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame
window
RUNTIME_CLASS(CCview_basicView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE,
file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has
been initialized, so show and update it.
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual
function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV
support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CCview_basicApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CCview_basicApp message handlers
// cview_basicDoc.cpp
: implementation of the CCview_basicDoc class
//
#include "stdafx.h"
#include "cview_basic.h"
#include "cview_basicDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCview_basicDoc
IMPLEMENT_DYNCREATE(CCview_basicDoc, CDocument)
BEGIN_MESSAGE_MAP(CCview_basicDoc, CDocument)
//{{AFX_MSG_MAP(CCview_basicDoc)
// NOTE - the ClassWizard will
add and remove mapping macros here.
// DO NOT EDIT
what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCview_basicDoc construction/destruction
CCview_basicDoc::CCview_basicDoc()
{
// TODO: add one-time construction code here
}
CCview_basicDoc::~CCview_basicDoc()
{
}
BOOL CCview_basicDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CCview_basicDoc serialization
void CCview_basicDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CCview_basicDoc diagnostics
#ifdef _DEBUG
void CCview_basicDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CCview_basicDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCview_basicDoc commands
// cview_basicView.cpp
: implementation of the CCview_basicView class
//
#include "stdafx.h"
#include "cview_basic.h"
#include "cview_basicDoc.h"
#include "cview_basicView.h"
#include "gl\gl.h"
#include "gl\glu.h"
#include <gl\glaux.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
unsigned char threeto8[8] =
{
0,
0111>>1, 0222>>1, 0333>>1, 0444>>1, 0555>>1,
0666>>1, 0377
};
unsigned char twoto8[4] =
{
0,
0x55, 0xaa, 0xff
};
unsigned char oneto8[2] =
{
0, 255
};
static int defaultOverride[13]
=
{
0, 3,
24, 27, 64, 67, 88, 173, 181, 236, 247, 164, 91
};
static PALETTEENTRY defaultPalEntry[20]
=
{
{ 0, 0, 0, 0 },
{ 0x80,0, 0, 0 },
{ 0, 0x80,0, 0 },
{ 0x80,0x80,0, 0 },
{ 0, 0, 0x80, 0 },
{ 0x80,0, 0x80, 0 },
{ 0, 0x80,0x80, 0 },
{ 0xC0,0xC0,0xC0, 0 },
{ 192, 220, 192, 0 },
{ 166, 202, 240, 0 },
{ 255, 251, 240, 0 },
{ 160, 160, 164, 0 },
{ 0x80,0x80,0x80, 0 },
{ 0xFF,0, 0, 0 },
{ 0, 0xFF,0, 0 },
{ 0xFF,0xFF,0, 0 },
{ 0, 0, 0xFF, 0 },
{ 0xFF,0, 0xFF, 0 },
{ 0, 0xFF,0xFF, 0 },
{ 0xFF,0xFF,0xFF, 0 }
};
/////////////////////////////////////////////////////////////////////////////
// CCview_basicView
IMPLEMENT_DYNCREATE(CCview_basicView, CView)
BEGIN_MESSAGE_MAP(CCview_basicView, CView)
//{{AFX_MSG_MAP(CCview_basicView)
ON_WM_TIMER()
ON_WM_DESTROY()
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_KEYDOWN()
ON_WM_SIZE()
ON_WM_CREATE()
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCview_basicView construction/destruction
CCview_basicView::CCview_basicView()
{
// TODO: add construction code here
m_pDC = NULL;
m_pOldPalette = NULL;
m_xRot = 90.0f;
m_yRot = 0.0f;
m_zRot = 0.0f;
m_texWrap = GL_CLAMP;
m_texMode = GL_DECAL;
m_texFilter = GL_NEAREST;
x =
0.0f;
y =
0.0f;
z =
1.0f;
r =
0.0f;
r_radius = 0.02f;
srand( (unsigned)time( NULL ) );
if (rand() < 16383)
xbounce = 0.01f;
else
xbounce = -0.01f;
if (rand() < 16383)
ybounce = 0.01f;
else
ybounce = -0.01f;
if (rand() < 16383)
zbounce = 0.01f;
else
zbounce = -0.01f;
rotatex = false;
rotatey = false;
rotatez = false;
HBITMAP hBmp = NULL;
}
CCview_basicView::~CCview_basicView()
{
DeleteObject((HGDIOBJ) hBmp); //avoid memory leak (Windows)
DeleteObject(&BM);
}
BOOL CCview_basicView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by
modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCview_basicView drawing
void CCview_basicView::OnDraw(CDC* pDC)
{
CCview_basicDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if (rotatex)
m_xRot = m_xRot + 1.0f;
if (m_xRot > 359)
m_xRot = 0;
if (rotatey)
m_yRot = m_yRot + 1.0f;
if (m_yRot > 359)
m_yRot = 0;
if (rotatez)
m_zRot = m_zRot + 1.0f;
if (m_zRot > 359)
m_zRot = 0;
// Clear out the color & depth buffers
::glClear( GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT );
glPushMatrix();
DrawScene();
glPopMatrix();
// Tell OpenGL to flush its
pipeline
::glFinish();
// Now Swap the buffers
::SwapBuffers( m_pDC->GetSafeHdc() );
}
/////////////////////////////////////////////////////////////////////////////
// CCview_basicView diagnostics
#ifdef _DEBUG
void CCview_basicView::AssertValid() const
{
CView::AssertValid();
}
void CCview_basicView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCview_basicDoc* CCview_basicView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCview_basicDoc)));
return (CCview_basicDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCview_basicView message handlers
/////////////////////////////////////////////////////////////////////////////
// GL helper functions
BOOL CCview_basicView::SetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit 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, // accum bits ignored
16, // 16-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0,
0 // layer masks ignored
};
int m_nPixelFormat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
if ( m_nPixelFormat == 0 )
{
return FALSE;
}
if ( ::SetPixelFormat(m_pDC->GetSafeHdc(), m_nPixelFormat, &pfd) ==
FALSE)
{
return FALSE;
}
return TRUE;}
void CCview_basicView::DrawScene(void)
{
glTranslatef(x,y,z);
glRotatef(m_xRot,1.0f,0.0f,0.0f);
glRotatef(m_yRot,0.0f,1.0f,0.0f);
glRotatef(m_zRot,0.0f,0.0f,1.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,m_Texture[0]);
//Front Face
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(-1.0f,-1.0f,1.0f + r);
glTexCoord2f(1,0);
glVertex3f( 1.0f,-1.0f,1.0f + r);
glTexCoord2f(1,1);
glVertex3f( 1.0f, 1.0f,1.0f + r);
glTexCoord2f(0,1);
glVertex3f(-1.0f, 1.0f,1.0f + r);
glEnd();
glBindTexture(GL_TEXTURE_2D,m_Texture[1]);
//Back Face
glBegin(GL_QUADS);
glTexCoord2f(1,0);
glVertex3f(-1.0f,-1.0f,-1.0f - r);
glTexCoord2f(1,1);
glVertex3f(-1.0f, 1.0f,-1.0f - r);
glTexCoord2f(0,1);
glVertex3f( 1.0f, 1.0f,-1.0f - r);
glTexCoord2f(0,0);
glVertex3f( 1.0f,-1.0f,-1.0f - r);
glEnd();
glBindTexture(GL_TEXTURE_2D,m_Texture[2]);
//Left Face
glBegin(GL_QUADS);
glTexCoord2f(1,0);
glVertex3f(-1.0f - r,-1.0f, 1.0f);
glTexCoord2f(1,1);
glVertex3f(-1.0f - r, 1.0f, 1.0f);
glTexCoord2f(0,1);
glVertex3f(-1.0f - r, 1.0f,-1.0f);
glTexCoord2f(0,0);
glVertex3f(-1.0f - r,-1.0f,-1.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D,m_Texture[3]);
//Right Face
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(1.0f + r,-1.0f, 1.0f);
glTexCoord2f(1,0);
glVertex3f(1.0f + r,-1.0f,-1.0f);
glTexCoord2f(1,1);
glVertex3f(1.0f + r, 1.0f,-1.0f);
glTexCoord2f(0,1);
glVertex3f(1.0f + r, 1.0f, 1.0f);
glEnd();
/*
glBindTexture(GL_TEXTURE_2D,m_Texture[0]);
//Top
Face
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2f(0,1);
glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(1,1);
glVertex3f( 1.0f, 1.0f, -1.0f);
glTexCoord2f(1,0);
glVertex3f(-1.0f, 1.0f, -1.0f);
glEnd();
glBindTexture(GL_TEXTURE_2D,m_Texture[0]);
//Botton Face
glBegin(GL_QUADS);
glTexCoord2f(0,1);
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(0,0);
glVertex3f(-1.0f, -1.0f, -1.0f);
glTexCoord2f(1,0);
glVertex3f( 1.0f, -1.0f, -1.0f);
glTexCoord2f(1,1);
glVertex3f( 1.0f, -1.0f, 0.0f);
glEnd();
*/
glDisable(GL_TEXTURE_2D);
}
void CCview_basicView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call
default
static int counter = 0;
switch(counter) {
case 0:
if (z > -10.0f)
z
= z - 0.02f;
else counter = 1;
break;
case 1:
if (m_xRot > 0)
m_xRot--;
else counter = 2;
break;
case 2:
rotatey = true;
counter = 3;
break;
case 3:
if (r > 4.0f)
r_radius = -0.02f;
if (r < 0.0f) {
r
= 0;
counter = 4;
break;
}
r
= r + r_radius;
break;
case 4:
if (x > 4.0f)
xbounce = -0.02f;
if (x < -4.0f)
xbounce = 0.02f;
if (y > 2.7f)
ybounce = -0.02f;
if (y < -2.7f)
ybounce = 0.02f;
/* if
(z > -8.0f)
zbounce = -0.02f;
if (z < -18.0f)
zbounce = 0.02f;
*/
x
= x + xbounce;
y
= y + ybounce;
// z
= z + zbounce;
}
InvalidateRect(NULL,
FALSE);
CView::OnTimer(nIDEvent);
}
void CCview_basicView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
//Make the RC non-current
if(::wglMakeCurrent (0,0) == FALSE)
{
MessageBox("Could not make RC non-current");
}
//Delete the rendering context
if(::wglDeleteContext (m_hRC)==FALSE)
{
MessageBox("Could not delete RC");
}
//Delete the DC
if(m_pDC)
{
delete m_pDC;
}
//Set it to NULL
m_pDC = NULL;
//Delete the timer
KillTimer(1);
glDeleteTextures(3, m_Texture);
}
void CCview_basicView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call
default
CView::OnLButtonDown(nFlags, point);
ASSERT(AfxGetMainWnd() != NULL);
AfxGetMainWnd()->SendMessage(WM_CLOSE);
}
void CCview_basicView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call
default
CView::OnRButtonDown(nFlags, point);
ASSERT(AfxGetMainWnd() != NULL);
AfxGetMainWnd()->SendMessage(WM_CLOSE);
}
void CCview_basicView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call
default
CView::OnKeyDown(nChar, nRepCnt, nFlags);
ASSERT(AfxGetMainWnd() != NULL);
AfxGetMainWnd()->SendMessage(WM_CLOSE);
}
BOOL CCview_basicView::InitializeOpenGL()
{
//Get a DC for the Client Area
m_pDC = new CClientDC(this);
//Failure to Get DC
if(m_pDC == NULL)
{
MessageBox("Error Obtaining DC");
return FALSE;
}
//Failure to set the pixel format
if(!SetupPixelFormat())
{
return FALSE;
}
//Create Rendering Context
m_hRC = ::wglCreateContext (m_pDC->GetSafeHdc ());
//Failure to Create Rendering Context
if(m_hRC == 0)
{
MessageBox("Error Creating RC");
return FALSE;
}
//Make the RC Current
if(::wglMakeCurrent (m_pDC->GetSafeHdc (), m_hRC)==FALSE)
{
MessageBox("Error making RC Current");
return FALSE;
}
//Specify Black as the clear color
::glClearColor(0.0f,0.0f,0.0f,0.0f);
//Specify the back of the buffer as clear depth
::glClearDepth(1.0f);
//Enable Depth Testing
::glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
LoadGLTextures();
// SetupLighting();
return TRUE;
}
void CCview_basicView::SetupLighting ()
{
//Material Properties
GLfloat matSpecular[] = { 1.0f, 0.0f, 0.0f, 1.0f};
GLfloat matShininess[] = { 50.0f};
GLfloat matAmbient[] = { 0.25f, 0.25f, 0.25f, 1.0f};
GLfloat matDiffuse[] = { 0.5f, 0.5f, 0.5f, 1.0f};
glMaterialfv(GL_FRONT,
GL_SPECULAR, matSpecular);
glMaterialfv(GL_FRONT,
GL_SHININESS, matShininess);
glMaterialfv(GL_FRONT,
GL_DIFFUSE, matDiffuse);
glMaterialfv(GL_FRONT,
GL_AMBIENT, matAmbient);
//Lighting Parameters
//Enable Lighting
glEnable(GL_LIGHTING);
//Specify a single directional light
GLfloat ambient1[] = {
0.5f,0.5f,0.5f};
GLfloat diffuse1[] = {
0.5f,0.5f,0.5f};
GLfloat specular1[] = {
1.0f,0.0f,0.0f};
GLfloat position1[] = {
0.0f,0.0f,5.0f,0.0};
glLightfv(GL_LIGHT0,
GL_AMBIENT, ambient1);
glLightfv(GL_LIGHT0,
GL_DIFFUSE, diffuse1);
glLightfv(GL_LIGHT0,
GL_SPECULAR, specular1);
glLightfv(GL_LIGHT0,
GL_POSITION, position1);
glEnable(GL_LIGHT0);
//Specify a single positional spotlight
GLfloat ambient2[] = {
1.0f,1.0f,0.0f};
GLfloat diffuse2[] = {
1.0f,0.0f,0.0f};
GLfloat position2[] = {
1.0f,0.0f,5.0f,1.0};
GLfloat direction2[] =
{0.0f,0.0f,-5.0f};
glLightfv(GL_LIGHT1,
GL_AMBIENT, ambient2);
glLightfv(GL_LIGHT1,
GL_DIFFUSE, diffuse2);
glLightfv(GL_LIGHT1,
GL_POSITION, position2);
glLightfv(GL_LIGHT1,
GL_SPOT_DIRECTION, direction2);
glLightf(GL_LIGHT1,
GL_SPOT_CUTOFF, 15.0f);
glEnable(GL_LIGHT1);
}
void CCview_basicView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
GLdouble aspect_ratio; // width/height ratio
if ( 0 >= cx || 0 >=
cy )
{
return;
}
// select the full client area
::glViewport(0, 0, cx, cy);
// compute the aspect ratio
// this will keep all dimension scales equal
aspect_ratio = (GLdouble)cx/(GLdouble)cy;
// select the projection matrix and clear it
::glMatrixMode(GL_PROJECTION);
::glLoadIdentity();
// select the viewing volume
::gluPerspective(45.0f, aspect_ratio, 0.01f, 200.0f);
// switch back to the modelview matrix and clear it
::glMatrixMode(GL_MODELVIEW);
::glLoadIdentity();
}
int CCview_basicView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
InitializeOpenGL();
SetTimer(1,
15, NULL);
return 0;
}
BOOL CCview_basicView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call
default
return CView::OnEraseBkgnd(pDC);
}
void CCview_basicView::LoadTexture (int bitmapName, int texName)
{
hBmp = (HBITMAP) ::LoadImage(AfxGetResourceHandle(),
MAKEINTRESOURCE(bitmapName),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
::GetObject(hBmp, sizeof(BM), &BM);
glBindTexture(GL_TEXTURE_2D, m_Texture[texName]);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S, m_texWrap);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T, m_texWrap);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MAG_FILTER, m_texFilter);
glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER, m_texFilter);
glTexEnvf(GL_TEXTURE_ENV,
GL_TEXTURE_ENV_MODE, m_texMode);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, BM.bmWidth,BM.bmHeight,
GL_BGR_EXT, GL_UNSIGNED_BYTE, BM.bmBits);
}
void CCview_basicView::LoadGLTextures()
{
//Create Texture Names
glGenTextures(4, m_Texture);
LoadTexture(IDB_TEST,0);
LoadTexture(IDB_TUG,1);
LoadTexture(IDB_CAROUSEL,2);
LoadTexture(IDB_BMS,3);
}
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "cview_basic.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_WM_GETMINMAXINFO()
ON_WM_PAINT()
ON_WM_MOUSEWHEEL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by
modifying
// the CREATESTRUCT cs
cs.style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
return CFrameWnd::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
lpMMI->ptMaxSize.y = m_FullScreenWindowRect.Height() + 1;
lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;
lpMMI->ptMaxSize.x = m_FullScreenWindowRect.Width()
+ 1;
lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;
}
void CMainFrame::OnPaint()
{
CPaintDC dc(this); // device context
for painting
RECT rectDesktop;
WINDOWPLACEMENT wpNew;
GetWindowPlacement (&m_wpPrev);
m_wpPrev.length = sizeof m_wpPrev;
//Adjust RECT to new size of window
::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
::AdjustWindowRectEx(&rectDesktop, GetStyle(), TRUE, GetExStyle());
// Remember this
for OnGetMinMaxInfo()
m_FullScreenWindowRect = rectDesktop;
wpNew = m_wpPrev;
wpNew.showCmd = SW_SHOWNORMAL;
wpNew.rcNormalPosition = rectDesktop;
SetWindowPlacement ( &wpNew );
::ShowCursor(FALSE);
}
BOOL CMainFrame::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call
default
PostMessage(WM_CLOSE);
return CFrameWnd::OnMouseWheel(nFlags, zDelta, pt);
}
// stdafx.cpp : source file that includes just the standard includes
// cview_basic.pch
will be the pre-compiled header
// stdafx.obj
will contain the pre-compiled type information
#include "stdafx.h"