예제 #1
0
void InitializeOpenGL(int width, int height)
{
    glEnable( GL_DEPTH_TEST );                             // Enables Depth Test i.e enables use of depth buffer for drawing
    glEnable( GL_TEXTURE_2D );                             // Enable Texture Mapping 

    SizeOpenGLScreen(width, height);                       // resize the OpenGL Viewport to the given height and width
}
예제 #2
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_KEYDOWN:
		switch(wParam) {								// Check if we hit a key
			case VK_ESCAPE:								// If we hit the escape key
				PostQuitMessage(0);						// Send a QUIT message to the window
				break;
		}
		break;
 
    case WM_DESTROY:									// If the window is destroyed
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break; 
     
    default:											// Return by default
        lRet = (long)DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
예제 #3
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);					// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

	case WM_KEYDOWN:
		if(wParam == VK_ESCAPE)	DeInit();				// Quit if we pressed ESCAPE
		break;
 
    case WM_DESTROY:									// If the window is destroyed
        DeInit();										// Release memory and restore settings
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
예제 #4
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	case WM_LBUTTONDOWN:								// If the left mouse button was clicked
		
		// We want to be able to turn wire frame on and off, so let's switch it
		g_bRenderMode = !g_bRenderMode;

		// Change the rendering mode to and from lines or triangles
		if(g_bRenderMode) 				
		{
			// Render the triangles in fill mode		
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	
		}
		else 
		{
			// Render the triangles in wire frame mode
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	
		}
		break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


	case WM_KEYDOWN:
		switch(wParam) 
		{
			case VK_ESCAPE:								// Check if we hit the ESCAPE key.
				PostQuitMessage(0);						// Tell windows we want to quit
				break;
		}
		break;
 
    case WM_CLOSE:										// If the window is closed
        PostQuitMessage(0);								// Tell windows we want to quit
        break; 
    } 
 
    return DefWindowProc (hWnd, uMsg, wParam, lParam); 	// Return the default
}
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are in window mode
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);					// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

	case WM_KEYDOWN:

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

		switch(wParam) {								// Check if we hit a key
			case VK_ESCAPE:
				PostQuitMessage(0);						// Send a QUIT message
				break;

			case VK_UP:									// If we hit the UP arrow key
				g_Camera.MoveCamera(kSpeed);			// Move our camera forward by a positive speed
				RenderScene();							// Redraw the screen to reflect changes
				break;

			case VK_DOWN:								// If we hit the DOWN arrow key
				g_Camera.MoveCamera(-kSpeed);			// Move our camera backward by a negative speed
				RenderScene();							// Redraw the screen to reflect changes
				break;
		}
		break;

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

    case WM_CLOSE:									// If the window is being closed
        PostQuitMessage(0);							// Post a QUIT message to the window;										// Release memory and restore settings
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
void InitializeOpenGL(int width, int height) 
{  
    g_hDC = GetDC(g_hWnd);								// This sets our global HDC
														// We don't free this hdc until the end of our program
    if (!bSetupPixelFormat(g_hDC))						// This sets our pixel format/information
        PostQuitMessage (0);							// If there's an error, quit

    g_hRC = wglCreateContext(g_hDC);					// This creates a rendering context from our hdc
    wglMakeCurrent(g_hDC, g_hRC);						// This makes the rendering context we just created the one we want to use

	SizeOpenGLScreen(width, height);					// Setup the screen translations and viewport
}
예제 #7
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 1; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// We check if the user hits the left mouse button, 
	// then change the draw style of the cylinder.

	case WM_LBUTTONDOWN:								// If the left mouse button was clicked
		if(g_RenderMode == GLU_FILL)						// Check if we were in GLU_FILL mode
			g_RenderMode = GLU_LINE;						// Then we need to switch to GLU_LINE mode
		else
			g_RenderMode = GLU_FILL;						// Otherwise, we want GLU_FILL now.
		break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	case WM_KEYDOWN:
		switch(wParam) {								// Check if we hit a key
			case VK_ESCAPE:								// If we hit the escape key
				PostQuitMessage(0);						// Send a QUIT message to the window
				break;
		}
		break;
 
    case WM_DESTROY:									// If the window is destroyed
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
예제 #8
0
void MainLoop(void)
{
    bool done = false;                                     // is our job done ? not yet !
    SDL_Event event;

    while(! done)                                          // as long as our job's not done
    {
        while( SDL_PollEvent(& event) )                    // look for events (like keystrokes, resizing etc.)
        {
            switch ( event.type )                          // what kind of event have we got ?
            {
                case SDL_QUIT :                                         // if user wishes to quit
                    done = true;                                        // this implies our job is done
                    break;

                case SDL_KEYDOWN :                                      // if the user has pressed a key
                    HandleKeyPressEvent( & event. key.keysym );         // callback for handling keystrokes, arg is key pressed
                    break;
                    
                case SDL_KEYUP :
                    HandleKeyReleaseEvent(& event.key.keysym) ;         // callback for handling keystrokes, arg is key released
                    break;

                case SDL_VIDEORESIZE :                                  // if there is a resize event
                    // request SDL to resize the window to the size and depth etc. that we specify
                    MainWindow = SDL_SetVideoMode( event.resize.w, event.resize.h, SCREEN_DEPTH, VideoFlags );
                    SizeOpenGLScreen(event.resize.w, event.resize.h);   // now resize the OpenGL viewport
    
                    if(MainWindow == NULL)                              // if window resize has failed
                    {
                        cerr << " Failed resizing SDL window : " << SDL_GetError() << endl;   // report error
                        Quit(0);
                    }
                    break;

                default:                                    // any other event
                    break;                                  // nothing to do
            } // switch
        } // while( SDL_ ...
//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////
            
            // Here we check for mouse and key movements every frame
            g_Camera.SetViewByMouse();                    // Move the camera by the mouse
            CheckForMovement();                           // Check if we pressed a key
            
            RenderScene();                                // Update the screen    
            
//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////
    } // while( ! done)
}
예제 #9
0
void InitializeOpenGL(int width, int height)
{
   glEnable( GL_DEPTH_TEST );                             // Enables Depth Test i.e enables use of depth buffer for drawing

 /////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // This allows us to use texture mapping, otherwise we just use colors.

    glEnable(GL_TEXTURE_2D);                            // Enable Texture Mapping

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    SizeOpenGLScreen(width, height);                       // resize the OpenGL Viewport to the given height and width
}
예제 #10
0
void GameWindow::InitOpenGL() 
{  
	GetClientRect(m_hwnd, &m_rDimensions);
	m_hdc = GetDC(m_hwnd);

	if (!SetupPixelFormat())
		PostQuitMessage (0);

	m_hrc = wglCreateContext(m_hdc);
	wglMakeCurrent(m_hdc, m_hrc);

	glEnable(GL_DEPTH_TEST);
	glEnable(GL_NORMALIZE);
	glEnable(GL_CULL_FACE);

	SizeOpenGLScreen(m_rDimensions.right, m_rDimensions.bottom);
}
예제 #11
0
void InitializeOpenGL(int width, int height) 
{  
    g_hDC = GetDC(g_hWnd);								// This sets our global HDC
														// We don't free this hdc until the end of our program
    if (!bSetupPixelFormat(g_hDC))						// This sets our pixel format/information
        PostQuitMessage (0);							// If there's an error, quit

    g_hRC = wglCreateContext(g_hDC);					// This creates a rendering context from our hdc
    wglMakeCurrent(g_hDC, g_hRC);						// This makes the rendering context we just created the one we want to use

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// This allows us to use texture mapping, otherwise we just use colors.

	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	SizeOpenGLScreen(width, height);					// Setup the screen translations and viewport
}
예제 #12
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0;
    PAINTSTRUCT    ps;

    switch (uMsg)
    {
    case WM_SIZE:										// If the window is resized
        if(!g_bFullScreen)								// Do this only if we are NOT in full screen
        {
            SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
            GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
        }
        break;

    case WM_PAINT:										// If we need to repaint the scene
        BeginPaint(hWnd, &ps);							// Init the paint struct
        EndPaint(hWnd, &ps);							// EndPaint, Clean up
        break;

    case WM_KEYDOWN:
        switch(wParam)  								// Check if we hit a key
        {
        case VK_ESCAPE:								// If we hit the escape key
            PostQuitMessage(0);						// Send a QUIT message to the window
            break;
        }
        break;

    case WM_CLOSE:										// If the window is being closes
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break;

    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
        break;
    }

    return lRet;										// Return by default
}
예제 #13
0
void InitializeOpenGL(int width, int height) 
{  
    g_hDC = GetDC(g_hWnd);								// This sets our global HDC
														// We don't free this hdc until the end of our program
    if (!bSetupPixelFormat(g_hDC))						// This sets our pixel format/information
        PostQuitMessage (0);							// If there's an error, quit

    g_hRC = wglCreateContext(g_hDC);					// This creates a rendering context from our hdc
    wglMakeCurrent(g_hDC, g_hRC);						// This makes the rendering context we just created the one we want to use

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////
	
	// Since we have more than ONE primative (shape), we need to do some depth testing.
	// If we do NOT have this line, you will see through all the shapes when you go behind them.
	// Comment out this line and then go behind all the triangles.  It's a cool effect though :)

	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	SizeOpenGLScreen(width, height);					// Setup the screen translations and viewport
}
예제 #14
0
파일: Main.cpp 프로젝트: 88er/tutorials
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are in window mode
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);					// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	case WM_LBUTTONDOWN:								// If we hit the left mouse button
		g_bLightmaps = !g_bLightmaps;					// Turn lightmaps on/off

		if(!g_bLightmaps)								// If we don't want lightmaps
		{	
			glActiveTextureARB(GL_TEXTURE1_ARB);		// Turn the second texture off
            glDisable(GL_TEXTURE_2D);
		}
		break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


	case WM_RBUTTONDOWN:								// If we hit the right mouse button
		g_bTextures = !g_bTextures;						// Turn texture mapping on/off

		if(!g_bTextures)								// If we don't want texture mapping
		{
			glActiveTextureARB(GL_TEXTURE0_ARB);
            glDisable(GL_TEXTURE_2D);					// Disable texture mapping
		}
		break;


	case WM_KEYDOWN:

		switch(wParam) {								// Check if we hit a key
			case VK_ESCAPE:								// If we hit the escape key
				PostQuitMessage(0);						// Send a QUIT message to the window
				break;

			case VK_SPACE:								// Check if we hit the space bar

				g_RenderMode = !g_RenderMode;			// Change the rendering mode

				// Change the rendering mode to and from lines or triangles
				if(g_RenderMode) 				
				{
					// Render the triangles in fill mode		
					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	
				}
				else 
				{
					// Render the triangles in wire frame mode
					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	
				}
				break;
		}
		break;

    case WM_CLOSE:										// If the window is being closes
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
예제 #15
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;


	case WM_LBUTTONDOWN:
	
		g_bDetail = !g_bDetail;
		break;

	case WM_RBUTTONDOWN:								// If the left mouse button was clicked
		
		g_bRenderMode = !g_bRenderMode;

		// Change the rendering mode to and from lines or triangles
		if(g_bRenderMode) 				
		{
			// Render the triangles in fill mode		
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	
		}
		else 
		{
			// Render the triangles in wire frame mode
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	
		}
		break;

	case WM_KEYDOWN:
		switch(wParam) 
		{
			case VK_ESCAPE:								// Check if we hit the ESCAPE key.
				PostQuitMessage(0);						// Tell windows we want to quit
				break;

			case VK_SPACE:								// Check if we hit the SPACE bar

				// To get a few different ideas of what a detail texture
				// could look like, we want to change it's scale value.

				// Times the current scale value by 2 and loop when it gets to 128
				g_DetailScale = (g_DetailScale * 2) % 128;

				// If the scale value is 0, set it to 1 again
				if(g_DetailScale == 0)
					g_DetailScale = 1;

				break;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

			// To make the tutorial more interesting, we add an option to increase
			// and decrease the height of the fog by using the + and - keys.

			case VK_ADD:								// Check if we hit the + key

				g_FogDepth += 1;						// Increase the fog height

				if(g_FogDepth > 200)					// Make sure we don't go past 200
					g_FogDepth = 200;

				break;

			case VK_SUBTRACT:							// Check if we hit the - key

				g_FogDepth -= 1;						// Decrease the fog height

				if(g_FogDepth < 0)						// Make sure we don't go below 0
					g_FogDepth = 0;

				break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


		}
		break;
 
    case WM_CLOSE:										// If the window is closed
        PostQuitMessage(0);								// Tell windows we want to quit
        break; 
    } 
 
    return DefWindowProc (hWnd, uMsg, wParam, lParam); 	// Return the default
}
예제 #16
0
void InitializeGL(int width, int height)
{
    SizeOpenGLScreen(width, height);                    // resize the OpenGL Viewport to the given height and width
}
예제 #17
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0;
    PAINTSTRUCT    ps;
    int objectID = 0;

    switch (uMsg)
    {
    case WM_SIZE:										// If the window is resized

        SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
        GetClientRect(hWnd, &g_rRect);					// Get the window rectangle
        break;

    case WM_PAINT:										// If we need to repaint the scene
        BeginPaint(hWnd, &ps);							// Init the paint struct
        EndPaint(hWnd, &ps);							// EndPaint, Clean up
        break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // If we click the left mouse button, we need to process our X and Y coordinates and
    // see if we hit any objects.  Remember, the LOWORD and HIWORD of the lParam are the (x,y)
    // coordinates of the mouse.  We call RetrieveObjectID() to get the object ID we clicked on.

    case WM_LBUTTONDOWN:								// If the left mouse button was clicked

        // Here we pass in the cursors X and Y coordinates to test for an object under the mouse.
        objectID = RetrieveObjectID(LOWORD(lParam), HIWORD(lParam));

        // Now we just do a switch on our object ID's to see if we hit one.

        switch(objectID)								// Check the objectID passed back
        {
        case SUN:										// We hit the Sun!
            MessageBox(NULL, "The Sun!", "Click", MB_OK);
            break;
        case EARTH:										// We hit the Earth!
            MessageBox(NULL, "The Earth!", "Click", MB_OK);
            break;
        case PLUTO:										// We hit Pluto!
            MessageBox(NULL, "Pluto!", "Click", MB_OK);
            break;
        }
        break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    case WM_KEYDOWN:
        switch(wParam)
        {
        case VK_ESCAPE:								// Check if we hit the ESCAPE key.
            PostQuitMessage(0);						// Tell windows we want to quit
            break;
        }
        break;

    case WM_CLOSE:										// If the window is closed
        PostQuitMessage(0);								// Tell windows we want to quit
        break;

    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
        break;
    }

    return lRet;										// Return by default
}
예제 #18
0
파일: Main.cpp 프로젝트: 88er/tutorials
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are in window mode
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);					// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

	case WM_LBUTTONDOWN:								// If we hit the left mouse button
		g_bLightmaps = !g_bLightmaps;					// Turn lightmaps on/off

		if(!g_bLightmaps)								// If we don't want lightmaps
		{	
			glActiveTextureARB(GL_TEXTURE1_ARB);		// Turn the second texture off
            glDisable(GL_TEXTURE_2D);
		}
		break;

	case WM_RBUTTONDOWN:								// If we hit the right mouse button
		g_bTextures = !g_bTextures;						// Turn texture mapping on/off

		if(!g_bTextures)								// If we don't want texture mapping
		{
			glActiveTextureARB(GL_TEXTURE0_ARB);
            glDisable(GL_TEXTURE_2D);					// Disable texture mapping
		}
		break;


	case WM_KEYDOWN:

		switch(wParam) {								// Check if we hit a key
			case VK_ESCAPE:								// If we hit the escape key
				PostQuitMessage(0);						// Send a QUIT message to the window
				break;

			case VK_F1:									// Check if we hit the space bar
		
				g_RenderMode = !g_RenderMode;			// Change the rendering mode

				// Change the rendering mode to and from lines or triangles
				if(g_RenderMode) 				
				{
					// Render the triangles in fill mode		
					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	
				}
				else 
				{
					// Render the triangles in wire frame mode
					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	
				}
				break;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

			case VK_SPACE:								// Check if the user hits the space bar

				// This is what will create our jump effect.  Before we add our jump
				// velocity, we make sure that we are on the ground.  This makes it
				// so we can't jump infinitely and keep ramming our head into the cieling.
				// This type of realism depends on your project of course.  If we are on
				// the ground, we can then set our velocity.y value to our jump velocity
				// which will be added to our camera (or player) every frame, until the
				// gravity eventually cancels it out.
				if(g_Level.IsOnGround())
					g_vVelocity.y = kJumpAcceleration;
				break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


		}
		break;

    case WM_CLOSE:										// If the window is being closes
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
예제 #19
0
void InitializeGL(int width, int height)
{
    glEnable(GL_DEPTH_TEST);                            // Enables Depth Testing
    SizeOpenGLScreen(width, height);                    // resize the OpenGL Viewport to the given height and width
}
예제 #20
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// Below we check what the user types in.  If they use the arrow keys
	// then we want to move the sphere around (LEFT RIGHT UP and DOWN keys)
	// The UP/DOWN keys increase the radius it rotates around the line, where
	// the LEFT/RIGHT keys move the sphere along the line.

	case WM_KEYDOWN:
		switch(wParam) 
		{
			case VK_ESCAPE:							// Check if we hit the ESCAPE key.
				PostQuitMessage(0);					// Tell windows we want to quit
				break;

			case VK_UP:								// Check if we hit the UP ARROW key.
				g_vPosition.y += 0.01f;				// Increase the rotation radius
				break;

			case VK_DOWN:							// Check if we hit the DOWN ARROW key.
				g_vPosition.y -= 0.01f;				// Decrease the rotation radius
				break;

			case VK_LEFT:							// Check if we hit the LEFT ARROW key.
				g_vPosition.x -= 0.01f;				// Move the sphere left along the line
				break;

			case VK_RIGHT:							// Check if we hit the RIGHT ARROW key.
				g_vPosition.x += 0.01f;				// Move the sphere right along the line
				break;
		}

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

		break;

    case WM_CLOSE:									// If the window is closed
        PostQuitMessage(0);							// Tell windows we want to quit
        break; 
     
    default:										// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;									// Return by default
}
예제 #21
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0;
    PAINTSTRUCT    ps;

    switch (uMsg)
    {
    case WM_SIZE:								// If the window is resized
        if(!g_bFullScreen)						// Do this only if we are NOT in full screen
        {
            SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
            GetClientRect(hWnd, &g_rRect);		// Get the window rectangle
        }
        break;

    case WM_PAINT:								// If we need to repaint the scene
        BeginPaint(hWnd, &ps);					// Init the paint struct
        EndPaint(hWnd, &ps);					// EndPaint, Clean up
        break;

    // Below we define our controls for this tutorial. The controls are:

    // Right Mouse Click - Cycles through the upper (torso) animations
    // Left Mouse Click  - Cycles through the lower (legs) animations
    // Left Arrow Key - Spins the model to the left
    // Right Arrow Key - Spins the model to the right
    // Up Arrow Key - Moves the camera closer to the model
    // Right Arrow Key - Moves the camera farther away from the model
    // W - Changes the Render mode from normal to wire frame.
    // Escape - Quits


//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

    case WM_LBUTTONDOWN:								// If the left mouse button was clicked

        // Increase the leg's current animation to the next animation
        IncreaseCharacterAnimation( &g_Model, kLower);
        break;

    case WM_RBUTTONDOWN:								// If the right mouse button was clicked

        // Increase the torso's current animation to the next animation
        IncreaseCharacterAnimation( &g_Model, kUpper );
        break;

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////


    case WM_KEYDOWN:							// If we pressed a key

        switch(wParam)							// Check if we hit a key
        {
        case VK_ESCAPE:						// If we hit the escape key
            PostQuitMessage(0);				// Send a QUIT message to the window
            break;

        case VK_LEFT:						// If the LEFT arrow key was pressed
            g_RotationSpeed -= 0.05f;		// Decrease the rotation speed (eventually rotates left)
            break;

        case VK_RIGHT:						// If the RIGHT arrow key is pressed
            g_RotationSpeed += 0.05f;		// Increase the rotation speed (rotates right)
            break;

        case VK_UP:							// If the UP arrow key was pressed
            g_TranslationZ += 2;			// Move the camera position forward along the Z axis
            break;

        case VK_DOWN:						// If the DOWN arrow key is pressed
            g_TranslationZ -= 2;			// Move the camera position back along the Z axis
            break;

        case 'W':

            g_RenderMode = !g_RenderMode;	// Change the rendering mode

            // Change the rendering mode to and from lines or triangles
            if(g_RenderMode)
            {
                // Render the triangles in fill mode
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
            }
            else
            {
                // Render the triangles in wire frame mode
                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
            }
            break;
        }
        break;

    case WM_CLOSE:										// If the window is being closed
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break;

    default:											// Return by default
        lRet = (LONG)DefWindowProc (hWnd, uMsg, wParam, lParam);
        break;
    }

    return lRet;										// Return by default
}
예제 #22
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	// Below we define our controls for this simple tutorial.
	// The controls are: 

	// Left Mouse Button - Changes the Render mode from normal to wireframe.
	// Right Mouse Button - Turns lighting On/Off
	// Left Arrow Key - Spins the model to the left
	// Right Arrow Key - Spins the model to the right
	// Escape - Quits

	case WM_LBUTTONDOWN:								// If the left mouse button was clicked
		
		if(g_ViewMode == GL_TRIANGLES) {				// We our drawing mode is at triangles
			g_ViewMode = GL_LINE_STRIP;					// Go to line stips
		} else {
			g_ViewMode = GL_TRIANGLES;					// Go to triangles
		}
		break;

	case WM_RBUTTONDOWN:								// If the right mouse button was clicked.
		
		g_bLighting = !g_bLighting;						// Turn lighting ON/OFF

		if(g_bLighting) {								// If lighting is ON
			glEnable(GL_LIGHTING);						// Enable OpenGL lighting
		} else {
			glDisable(GL_LIGHTING);						// Disable OpenGL lighting
		}
		break;

	case WM_KEYDOWN:									// If we pressed a key

		switch(wParam) {								// Check if we hit a key
			case VK_ESCAPE:								// If we hit the escape key
				PostQuitMessage(0);						// Send a QUIT message to the window
				break;

			case VK_LEFT:								// If the LEFT arrow key was pressed
				g_RotationSpeed += 0.01f;				// Decrease the rotation speed (eventually rotates left)
				break;

			case VK_RIGHT:								// If the RIGHT arrow key is pressed
				g_RotationSpeed -= 0.01f;				// Increase the rotation speed (rotates right)
				break;
		}
		break;

    case WM_CLOSE:										// If the window is being closed
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
예제 #23
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0;
    PAINTSTRUCT    ps;

    switch (uMsg)
    {
    case WM_SIZE:										// If the window is resized
        if(!g_bFullScreen)								// Do this only if we are NOT in full screen
        {
            SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
            GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
        }
        break;

    case WM_PAINT:										// If we need to repaint the scene
        BeginPaint(hWnd, &ps);							// Init the paint struct
        EndPaint(hWnd, &ps);							// EndPaint, Clean up
        break;

    case WM_LBUTTONDOWN:								// If we hit the left mouse button

        // Change the rendering mode to lines or triangles depending on it's current status
        g_bRenderMode = !g_bRenderMode;

        // Change the rendering mode to and from lines or triangles
        if(g_bRenderMode)
        {
            // Render the triangles in fill mode
            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
        }
        else
        {
            // Render the triangles in wire frame mode
            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        }
        break;

    case WM_RBUTTONDOWN:								// If the right mouse button was clicked.

        g_bLighting = !g_bLighting;						// Turn lighting ON/OFF

        if(g_bLighting)  								// If lighting is ON
        {
            glEnable(GL_LIGHTING);						// Enable OpenGL lighting
        }
        else
        {
            glDisable(GL_LIGHTING);						// Disable OpenGL lighting
        }
        break;

    case WM_KEYDOWN:									// If we hit a key
        switch (wParam)									// Check which key we hit
        {
        case VK_ESCAPE:								// If we hit ESCAPE
            PostQuitMessage(0);						// Tell windows we want to quit
            break;

        case VK_ADD:								// If we hit '+'
            g_MaxSubdivisions += 1;					// Increase the current max subdivisions

            // Make sure we don't go over 10 subdivisions, otherwise it will get crazy
            if(g_MaxSubdivisions  > 10) g_MaxSubdivisions   = 10;

            // Destroy the octree and debug lines and create a new one with the new info
            RecreateOctree();
            break;

        case VK_SUBTRACT:							// If we hit '-'
            g_MaxSubdivisions -= 1;					// Decrease the current max subdivisions

            // Make sure we don't go below zero subdivisions
            if(g_MaxSubdivisions < 0) g_MaxSubdivisions   = 0;

            // Destroy the octree and debug lines and create a new one with the new info
            RecreateOctree();
            break;

        case VK_F5:									// If we hit F5
            g_MaxTriangles += 20;					// Increase the max triangle count by 20

            // Make sure we don't go above 2000
            if(g_MaxTriangles > 2000) g_MaxTriangles  = 2000;

            // Destroy the octree and debug lines and create a new one with the new info
            RecreateOctree();
            break;

        case VK_F6:									// If we hit F6
            g_MaxTriangles -= 20;					// Decrease the max triangle count by 20

            // Make sure we don't go below 0 (0 would produce as many nodes as triangles)
            if(g_MaxTriangles < 0) g_MaxTriangles  = 0;

            // Destroy the octree and debug lines and create a new one with the new info
            RecreateOctree();
            break;
        }
        break;

    case WM_CLOSE:										// If the window is closed
        PostQuitMessage(0);								// Tell windows we want to quit
        break;

    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
        break;
    }

    return lRet;										// Return by default
}
예제 #24
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// Below we check what the user types in.  If they use the arrow keys
	// then we want to move the triangle around (LEFT RIGHT UP and DOWN keys)

	case WM_KEYDOWN:
		switch(wParam) 
		{
			case VK_ESCAPE:								// Check if we hit the ESCAPE key.
				PostQuitMessage(0);						// Tell windows we want to quit
				break;

			case VK_UP:									// Check if we hit the UP ARROW key.
				vTriangle[0].x += 0.01f;				// Move the left point of the triangle to the left
				vTriangle[1].x += 0.01f;				// Move the right point of the triangle to the left
				vTriangle[2].x += 0.01f;				// Move the top point of the triangle to the left
				break;

			case VK_DOWN:								// Check if we hit the DOWN ARROW key.
				vTriangle[0].x -= 0.01f;				// Move the left point of the triangle to the left
				vTriangle[1].x -= 0.01f;				// Move the right point of the triangle to the left
				vTriangle[2].x -= 0.01f;				// Move the top point of the triangle to the left
				break;


			case VK_LEFT:								// Check if we hit the LEFT ARROW key.
				vTriangle[0].z -= 0.01f;				// Move the left point of the triangle back
				vTriangle[1].z -= 0.01f;				// Move the right point of the triangle back
				vTriangle[2].z -= 0.01f;				// Move the top point of the triangle back
				break;

			case VK_RIGHT:								// Check if we hit the RIGHT ARROW key.
				vTriangle[0].z += 0.01f;				// Move the left point of the triangle forward
				vTriangle[1].z += 0.01f;				// Move the right point of the triangle forward
				vTriangle[2].z += 0.01f;				// Move the top point of the triangle forward
				break;
		}

		break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *
 
    case WM_CLOSE:										// If the window is closed
        PostQuitMessage(0);								// Tell windows we want to quit
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}
예제 #25
0
void InitializeOpenGL(int width, int height)
{
    g_hDC = GetDC(g_hWnd);								// This sets our global HDC
    // We don't free this hdc until the end of our program
    if (!bSetupPixelFormat(g_hDC))						// This sets our pixel format/information
        PostQuitMessage (0);							// If there's an error, quit

    g_hRC = wglCreateContext(g_hDC);					// This creates a rendering context from our hdc
    wglMakeCurrent(g_hDC, g_hRC);						// This makes the rendering context we just created the one we want to use

    glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // It's a good idea to have the color of our background the same color as our darkness.
    // Since we are using white as our light color, we will set our background color to black.

    glClearColor(0, 0, 0, 1);							// Set our background color to black (0, 0, 0)

    // Below we create 2 arrays of color.  The first one, ambience[], is the default color
    // when there is no light shinning on the polygon.  If we didn't have an ambience, the
    // polygon's would be extremely dark so you couldn't see them.  Since we are using pure white
    // as our light color, we will set the ambience half of that, so it's not TOO dark when the light
    // isn't shinning on the surface of a polygon.  The second array, "diffuse", is the color
    // of the light that is shinning.  We chose pure white.  The first 3 are the R G B values.
    // (0, 0, 0) is pure black, where (1, 1, 1) is pure white. The last index is the alpha value.
    // Don't worry about that now.  For our ambience color we choose a dark grey light source.
    // For our diffuse color, we chose a half and half between full black light and full white.

    float ambience[4] = {0.3f, 0.3f, 0.3f, 1.0};		// The color of the light in the world
    float diffuse[4] = {0.5f, 0.5f, 0.5f, 1.0};			// The color of the positioned light

    // To set the ambience of our world, we need to give OpenGL our array of values.
    // OpenGL allows us to have multiple lights.  The number of lights is dependant on GL_MAX_LIGHTS.
    // We will use a OpenGL define for the first usable light, GL_LIGHT0.  After we specify a
    // light to use, we pass in the flag that tells OpenGL we are setting the ambience, followed
    // by our ambience array.  To set the diffuse color, we do the same thing but use GL_DIFFUSE
    // and our diffuse array.

    glLightfv( GL_LIGHT0, GL_AMBIENT,  ambience );		// Set our ambience values (Default color without direct light)
    glLightfv( GL_LIGHT0, GL_DIFFUSE,  diffuse );		// Set our diffuse color (The light color)

    // Next, we need to set the POSITION of our light.  We can have many lights at many positions.
    // In this tutorial, we will just do one light, but feel free to add more.  Use GL_LIGHT1 next.
    // We have our light position global so we can change it with the '+' and '-' keys.
    // Our default posiiton stored in g_LightPosition is (0, 1, 0, 1).  This should place our
    // light position directly above the middle pyramid.  The last value in the g_LightPosition array
    // tells OpenGL if we want our light position to be a DIRECTION or a POSITION.  If the
    // value is a 1, that means it is just a position, otherwise it's a direction from our camera.
    // If we have it a direction , it lights up everything in that direction (or vector) from
    // our eye, or in other words our camera.  If we say it's a position, it takes the values
    // as an X Y and Z position in the world.  Then it lights up everything around it.  That is
    // what we want, so we have a 1 to say that.  Once again, we pass in the light we are setting,
    // then GL_POSITION to let OpenGL we are setting the light position, the pass in our array
    // holding the position values.

    glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition );	// This Sets our light position

    // After we initialize a particular light, we need to turn it on.
    // We use the glEnable() function to do so, then pass in the light to turn on.

    glEnable(  GL_LIGHT0   );								// Turn this light on

    // That is enough though, we still need to allow lighting to take place.
    // Just because the light switch is on, doesn't mean we have power :)
    // This works just like fog, once you init everything, you need to allow it to be displayed.

    glEnable(  GL_LIGHTING );								// This turns on lighting

    // This next line allows us to use colors on our polygons during lighting.
    // If we did not have this line it would turn our pyramids white.

    glEnable(GL_COLOR_MATERIAL);							// Allow color to show during lighting

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    SizeOpenGLScreen(width, height);					// Setup the screen translations and viewport
}
예제 #26
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0;
    PAINTSTRUCT    ps;

    switch (uMsg)
    {
    case WM_SIZE:								// If the window is resized
        if(!g_bFullScreen)						// Do this only if we are NOT in full screen
        {
            SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
            GetClientRect(hWnd, &g_rRect);		// Get the window rectangle
        }
        break;

    case WM_PAINT:								// If we need to repaint the scene
        BeginPaint(hWnd, &ps);					// Init the paint struct
        EndPaint(hWnd, &ps);					// EndPaint, Clean up
        break;


    case WM_KEYDOWN:							// If we pressed a key

        switch(wParam)							// Check if we hit a key
        {
        case VK_ESCAPE:						// If we hit the escape key
            PostQuitMessage(0);				// Send a QUIT message to the window
            break;

        case VK_LEFT:						// If the LEFT arrow key was pressed
            g_RotationSpeed -= 0.05f;		// Decrease the rotation speed (eventually rotates left)
            break;

        case VK_RIGHT:						// If the RIGHT arrow key is pressed
            g_RotationSpeed += 0.05f;		// Increase the rotation speed (rotates right)
            break;

        case VK_UP:							// If the UP arrow key was pressed
            g_TranslationZ += 2;			// Move the camera position forward along the Z axis
            break;

        case VK_DOWN:						// If the DOWN arrow key is pressed
            g_TranslationZ -= 2;			// Move the camera position back along the Z axis
            break;

        case 'W':

            g_RenderMode = !g_RenderMode;	// Change the rendering mode

            // Change the rendering mode to and from lines or triangles
            if(g_RenderMode)
            {
                // Render the triangles in fill mode
                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
            }
            else
            {
                // Render the triangles in wire frame mode
                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
            }
            break;
        }
        break;

    case WM_CLOSE:										// If the window is being closed
        PostQuitMessage(0);								// Send a QUIT Message to the window
        break;

    default:											// Return by default
        lRet = (LONG)DefWindowProc (hWnd, uMsg, wParam, lParam);
        break;
    }

    return lRet;										// Return by default
}
예제 #27
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0;
    PAINTSTRUCT    ps;

    switch (uMsg)
    {
    case WM_SIZE:										// If the window is resized
        if(!g_bFullScreen)								// Do this only if we are NOT in full screen
        {
            SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
            GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
        }
        break;

    case WM_PAINT:										// If we need to repaint the scene
        BeginPaint(hWnd, &ps);							// Init the paint struct
        EndPaint(hWnd, &ps);							// EndPaint, Clean up
        break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // We added some more controls to increase the spheres and turn frustum
    // culling ON/OFF.

    case WM_LBUTTONDOWN:								// If the left mouse button was clicked
        g_bIgnoreFrustum = !g_bIgnoreFrustum;
        break;

    case WM_KEYDOWN:									// If we hit a key
        switch (wParam)									// Check which key we hit
        {
        case VK_ESCAPE:								// If we hit ESCAPE
            PostQuitMessage(0);						// Tell windows we want to quit
            break;

        case VK_ADD:								// If we hit '+'
            g_MaxSpheres += 10;						// Increase the amount of spheres

            if(g_MaxSpheres > MAX_SPHERES)			// If we went over the limit
            {
                g_MaxSpheres = MAX_SPHERES;			// Set the max back to the limit
            }
            break;

        case VK_SUBTRACT:							// if we hit '-'
            g_MaxSpheres -= 10;						// Decrease the amount of spheres

            if(g_MaxSpheres < 0)					// If we went below zero
            {
                g_MaxSpheres = 0;					// Set the amount of spheres back to zero
            }
            break;

        case 'c':
        case 'C':
        case VK_SPACE:			// If we hit 'C' or the Space bar
            g_bIgnoreFrustum = !g_bIgnoreFrustum;		// Turn frustum culling on and off
            break;
        }
        break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    case WM_CLOSE:										// If the window is closed
        PostQuitMessage(0);								// Tell windows we want to quit
        break;

    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
        break;
    }

    return lRet;										// Return by default
}
예제 #28
0
LRESULT CALLBACK WinProc(HWND hWnd,UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    LONG    lRet = 0; 
    PAINTSTRUCT    ps;

    switch (uMsg)
	{ 
    case WM_SIZE:										// If the window is resized
		if(!g_bFullScreen)								// Do this only if we are NOT in full screen
		{
			SizeOpenGLScreen(LOWORD(lParam),HIWORD(lParam));// LoWord=Width, HiWord=Height
			GetClientRect(hWnd, &g_rRect);				// Get the window rectangle
			if(g_hDC) RenderScene();					// Redraw the scene if we have a valid hdc
		}
        break; 
 
	case WM_PAINT:										// If we need to repaint the scene
		BeginPaint(hWnd, &ps);							// Init the paint struct		
		if(g_hDC) RenderScene();						// Redraw the scene
		EndPaint(hWnd, &ps);							// EndPaint, Clean up
		break;

	case WM_LBUTTONDOWN:								// If we hit the left mouse button
		
		g_RenderMode = !g_RenderMode;					// Change the rendering mode

		// Change the rendering mode to lines or triangles, depending on it's current status
		if(g_RenderMode) {				
			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);	// Render the triangles in fill mode		
		}
		else {
			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);	// Render the triangles in wire frame mode
		}
		break;

	case WM_RBUTTONDOWN:								// If the right mouse button was clicked.
		
		g_bLighting = !g_bLighting;						// Turn lighting ON/OFF

		if(g_bLighting) {								// If lighting is ON
			glEnable(GL_LIGHTING);						// Enable OpenGL lighting
		} else {
			glDisable(GL_LIGHTING);						// Disable OpenGL lighting
		}
		break;

	case WM_KEYDOWN:									// If we hit a key
		switch (wParam)									// Check which key we hit
		{
			case VK_ESCAPE:								// If we hit ESCAPE
				PostQuitMessage(0);						// Tell windows we want to quit
				break;


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

			case VK_SPACE:								// If we hit the space bar

				g_bDisplayNodes = !g_bDisplayNodes;		// Turn the debug lines on/off
				break;

			case 'F':									// Check if hit the 'F' key
				
				g_bFog = !g_bFog;						// Turn fog on/off

				if( g_bFog )							// If fog is turned on
				{
					// Set the background color to grey and enable fog
					glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
					glEnable(GL_FOG);
				}
				else
				{
					// Turn the color back to blue'ish purple and disable fog
					glClearColor(0.5f, 0.5f, 1.0f, 1.0f);
					glDisable(GL_FOG);
				}
				break;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


		}
		break;

    case WM_DESTROY:									// If the window is destroyed
        PostQuitMessage(0);								// Tell windows we want to quit
        break; 
     
    default:											// Return by default
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
        break; 
    } 
 
    return lRet;										// Return by default
}