GLUT or wgl which one

This is a discussion on GLUT or wgl which one within the Game Programming forums, part of the General Programming Boards category; No that's not true RoD the code just doesn't work. I fixed the PeekMessage function and made the order of ...

  1. #16
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    No that's not true RoD the code just doesn't work. I fixed the PeekMessage function and made the order of things 'proper' (i.e if there is a message, if it's quit then done equals true, otherwise translate/dispatch message, otherwise draw the scene) but I still could not get it to work. I put a messagebox function in the draw scene part saying "this is the drawscene function" to see if it was even getting to the drawing part, and in fact it was. This leads me to believe there was something wrong with the way the pixel format was set up, but I don't care to take the time to fix that code properly

  2. #17
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I typed the code in EXACT to the book, and it runs. When i had that problem i merely made sure my opengl files (from opengl.org) were placed right, which they weren't. After i fixed them i have had NO problems.

  3. #18
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    i just copied and pasted the code that SAMSAM posted and tried it and it didn't work. I fixed the errors I mentioned with no success and decided the error was elsewhere.

  4. #19
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    I tried the code and adjusted it here and there (code's a mess),
    but it seems to just reject flipping the backbuffer.

  5. #20
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I think you're right Trav, but I am not sure why it would skip the call to swapbuffers, and I do not mind because nehes basecode works

  6. #21
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Oke, I think i fixed, The problem was it din't created a rendering
    context whatsoever.

    Code:
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glaux.h>
    
    float angle = 0.0f;
    
    HDC g_HDC;
    
    void SetupPixelFormat(HDC hdc)
    {
    	int npixelformat;
    
    	static PIXELFORMATDESCRIPTOR pfd = 
    	{
    		sizeof(PIXELFORMATDESCRIPTOR),
    			1,
    			PFD_DRAW_TO_WINDOW |
    			PFD_SUPPORT_OPENGL |
    			PFD_DOUBLEBUFFER,
    			PFD_TYPE_RGBA,
    			32,
    			0, 0, 0, 0, 0, 0,
    			0,
    			0, 
    			0,
    			0, 0, 0, 0,
    			16,
    			0,
    			0,
    			PFD_MAIN_PLANE,
    			0, 
    			0, 0, 0
    	};
    	
    	npixelformat = ChoosePixelFormat(hdc, &pfd);
    	SetPixelFormat(hdc, npixelformat, &pfd);
    	
    	HGLRC hRC=wglCreateContext(g_HDC);
    	wglMakeCurrent(g_HDC,hRC);
    }
    
    LRESULT  CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static HGLRC hRC;
    	
    	char  hello[] = "HELLO SARA";
    	int width, height;
    
    
    	switch(message){
    
    	case WM_CREATE:
    
    		g_HDC = GetDC(hwnd);
    
    		SetupPixelFormat(g_HDC);
    
    		hRC = wglCreateContext(g_HDC);
    		return 0;
    		break;
    
        case WM_CLOSE:
    
    		wglMakeCurrent(g_HDC, NULL);
    		wglDeleteContext(hRC);
    		PostQuitMessage(0);
    		return 0;
    		break;
    
    	case WM_SIZE:
    		height = HIWORD (lParam);
    		width  = LOWORD (lParam);
    		if(height == 0)
    		{
    			height = 1;
    		}
    
    		glViewport(0, 0, width, height);
    		glMatrixMode(GL_PROJECTION);
    		glLoadIdentity();
    		gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 1.0f, 1000.0f);
    		glMatrixMode(GL_MODELVIEW);
    		glLoadIdentity();
    		return 0;
    		break;
    	default:
    		break;
    	}
    	return (DefWindowProc(hwnd, message, wParam, lParam));
    }
    
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
    
    
    
    	
    	
    	
         static char szAppName[] = TEXT ("opengl") ;
    	  BOOL  done;
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASSEX     wndclass ;
         wndclass.cbSize        = sizeof(wndclass); 
         wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = NULL;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;
         wndclass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);
    
         RegisterClassEx(&wndclass);
    
    	
    
    hwnd = CreateWindow ( szAppName,                  // window class name
                              TEXT ("opengl"), // window caption
                              WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN|WS_CLIPSIBLINGS,       // window style
                              100,              // initial x position
                              100,              // initial y position
                              400,              // initial x size
                              400,              // initial y size
                              NULL,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;  
    
                  if(!hwnd)
    		 return 0;   
         
         ShowWindow (hwnd, iCmdShow) ;
         UpdateWindow (hwnd) ;
         done = FALSE;
    
    	 while(!done)
    	 {
    		 if(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE))
    		 {
    			if(msg.message == WM_QUIT)
    			{
    				done  = TRUE;
    			}
    			else
    			{
    				TranslateMessage(&msg);
    				DispatchMessage(&msg);
    			}
    		}
    		else
    		{
    			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    			glLoadIdentity();
    			angle = angle + 0.1f;
    
    			if(angle >= 360.0f)
    				angle = 0.0f;
    			
    			glTranslatef(0.0f, 0.0f, -5.0f);
    			glRotatef(angle, 0.0f, 0.0f, 1.0f);
    			glColor3f(1.0f, 0.0f, 0.0f);
    						
    			glBegin(GL_TRIANGLES);
    
    				glVertex3f(0.0f, 0.0f, 0.0f);
    				glVertex3f(1.0f, 0.0f, 0.0f);
    				glVertex3f(1.0f, 1.0f, 0.0f);
    
    			glEnd();
    
    			SwapBuffers(g_HDC);
    		}
    	 }
    	 return  (int)msg.wParam;
    }

  7. #22
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    lmao no rendering context? AHAHAHA, where was that code from again? That's pretty sad, I didn't even look for a rc because i figured it would've been in there.

  8. #23
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    Only diff is i pragma'd some setting instead of doing it by hand.

    Code:
    /*	Steven Billington
    */
    
    /*	Here we set the libraries to be used in the program, and
    	trim some of the excess off of windows
    */
    
    #define WIN32_LEAN_AND_MEAN
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")
    #pragma comment(lib, "glaux.lib")
    #pragma comment(linker, "/subsystem:windows")
    
    
    /*	Include all needed headers for the project. Windows brings in
    	everything needed for the basic application, and the other three
    	bring in OpenGL related functions.
    */
    
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glaux.h>
    
    
    /*	These are our global variables. These are ok in this program,
    	but i wouldn't reccomend making a habit out of using global
    	variables. 
    
    	angle:	Holds current angle of rotating triangle
    	g_HDC:	Global Device Context
    */
    
    float angle = 0.0f;		
    HDC g_HDC;	
    			
    
    /*	Function:	SetupPixelFormat
    	
    	Purpose:	This function gets the setup for the pixel format,
    				go figure right?
    */
    
    void SetupPixelFormat(HDC hDC)
    {
    	int nPixelFormat;	/*	Pixel format index*/
    
    	static PIXELFORMATDESCRIPTOR pfd = {
    		sizeof(PIXELFORMATDESCRIPTOR),				//size of structure
    		1,											//version, always set to one
    		PFD_DRAW_TO_WINDOW |						//support window
    		PFD_SUPPORT_OPENGL |						//support opengl
    		PFD_DOUBLEBUFFER,							//support double buffering
    		PFD_TYPE_RGBA,								//RGBA color mode
    		32,											//32bit color mode
    		0,0,0,0,0,0,								//ignore color bits, not used
    		0,											//no alpha buffer
    		0,											//ignore shift bit
    		0,											//no accumulation buffer
    		0,0,0,0,									//ignore accumulation buffers
    		16,											//16 bit zbuffer size
    		0,											//no stencil buffer
    		0,											//no auxiliary buffer
    		PFD_MAIN_PLANE,								//main drawing plane
    		0,											//reserved
    		0,0,0 };									//layer masks ignored
    
    	/*	Choose best matching pixel format, return index*/
    	nPixelFormat = ChoosePixelFormat(hDC,&pfd);
    
    	/*	Set pixel format to device context*/
    	SetPixelFormat(hDC,nPixelFormat,&pfd);
    }
    
    /*	Function:	WndProc
    
    	Purpose:	This is our Windows Procedure Event Handler
    */
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static HGLRC hRC;						//rendering context
    	static HDC hDC;							//device context
    	char string[] = "Hello World!";			//display text
    	int width, height;						//window width, height
    
    	switch(message)
    	{
    		case WM_CREATE:						//window is being created
    
    			hDC = GetDC(hwnd);				//get current windows device context
    			g_HDC = hDC;
    			SetupPixelFormat(hDC);			//call your pixel format setup function
    
    			//create rendering context and make it current
    			hRC = wglCreateContext(hDC);
    			wglMakeCurrent(hDC,hRC);
    
    			return 0;
    			break;
    
    		case WM_CLOSE:						//window is closing
    
    			//deselect rendering context and delete it
    			wglMakeCurrent(hDC,NULL);
    			wglDeleteContext(hRC);
    
    			//send WM_QUIT to messagr queue
    			PostQuitMessage(0);
    
    			return 0;
    			break;
    
    		case WM_SIZE:
    
    			height = HIWORD(lParam);	//get height and width
    			width = LOWORD(lParam);
    
    			if (height == 0)			//don't want a divide by 0
    			{
    				height = 1;
    			}
    
    			//reset the viewport to new dimensions
    			glViewport(0,0,width,height);
    			glMatrixMode(GL_PROJECTION);		//set projection matrix
    			glLoadIdentity();					//reset proj matrix
    
    			//calculate aspect ratio of window
    			gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,1.0f,1000.0f);
    
    			glMatrixMode(GL_MODELVIEW);			//set modelview matrix
    			glLoadIdentity();					//reset mdeolv matrix
    
    			return 0;
    			break;
    
    		default:
    			break;
    
    
    	}
    
    	return (DefWindowProc(hwnd,message,wParam,lParam));
    }
    
    /*	Function:	WinMain
    
    	Purpose:	Do i need to state this? Ok, its the main function.
    */
    
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
     	WNDCLASSEX  windowClass;		//window class
    	HWND		hwnd;				//window handle
    	MSG			msg;				//message
    	bool		done;				//flag saying when app is complete
    
    	/*	Fill out the window class structure*/
    	windowClass.cbSize = sizeof(WNDCLASSEX);
    	windowClass.style = CS_HREDRAW | CS_VREDRAW;
    	windowClass.lpfnWndProc = WndProc;
    	windowClass.cbClsExtra = 0;
    	windowClass.cbWndExtra = 0;
    	windowClass.hInstance = hInstance;
    	windowClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    	windowClass.hbrBackground = NULL;
    	windowClass.lpszMenuName = NULL;
    	windowClass.lpszClassName = "MyClass";
    	windowClass.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
    
    	/*	Register window class*/
    	if (!RegisterClassEx(&windowClass))
    	{
    		return 0;
    	}
    
    	/*	Class registerd, so now create window*/
    	hwnd = CreateWindowEx(NULL,						//extended style
    						  "MyClass",				//class name
    						  "A Real OGL Win App",		//app name
    						  WS_OVERLAPPEDWINDOW |		//window style
    						  WS_VISIBLE |
    						  WS_SYSMENU |
    						  WS_CLIPCHILDREN |
    						  WS_CLIPSIBLINGS,
    						  100,100,					//x/y coords
    						  400,400,					//width,height
    						  NULL,						//handle to parent
    						  NULL,						//handle to menu
    						  hInstance,				//application instance
    						  NULL);					//no extra parameter's
    
    	/*	Check if window creation failed*/
    	if (!hwnd)
    	{
    		return 0;
    	}
    
    	ShowWindow(hwnd,SW_SHOW);		//displays window
    	UpdateWindow(hwnd);				//update window
    
    	done = false;					//inititalize condition variable
    
    	//main message loop
    	while(!done)
    	{
    		PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE);
    
    		if (msg.message == WM_QUIT)
    		{
    			done = true;
    		}
    
    		else
    		{
    			//do rendering here
    			//clear screen and depth buffer
    			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    			glLoadIdentity();		//reset modelview matrix
    
    			angle = angle + 0.1f;		//increase rotation angle counter
    
    			if (angle >= 360.0f)		//reset angle counter
    			{
    				angle = 0.0f;
    			}
    
    			glTranslatef(0.0f,0.0f,-5.0f);			//move back 5 units
    			glRotatef(angle,0.0f,0.0f,1.0f);		//rotate along z-axis
    
    			glColor3f(1.0,0.0f,0.0f);				//set color to red
    			glBegin(GL_TRIANGLES);					//draw the triangle
    				glVertex3f(0.0f,1.0f,0.0f);
    				glVertex3f(0.0f,0.0f,0.0f);			
    				glVertex3f(1.0f,0.0f,0.0f);
    			glEnd();
    
    			SwapBuffers(g_HDC);						//bring back buffer to foreground
    
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    
    		}
    
    	}
    
    
    	return msg.wParam;;
    }

  9. #24
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by Silvercord
    I didn't even look for a rc because i figured it would've been in there.
    That's what i thought .

  10. #25
    Banned
    Join Date
    Jan 2003
    Posts
    1,708

    Thumbs up

    well I've gotta hand it to you trav, I was too quick to make assumptions and you weren't. That's probably a very good quality to have (not making assumptions).

  11. #26
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    hi i checked my vc++6 include files :
    it has these files

    gl.h
    glu.h
    glaux.h
    glut.h

    in my libs it has;

    glut32
    glu32
    glaux
    opengl32

    in my setting\links i have;

    kernel32.lib user32.lib gdi32.lib glu32.lib GLAUX.lib opengl32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/sia3d0019.pdb" /debug /machine:I386 /out:"Debug/sia3d0019.exe" /pdbtype:sept


    so i think i have all the files .

    by the way at first when i got warning about PeekMessage i changed NULL to 0 .in the book its NULL,



    question?

    should i continue reding this book or giveit up for another one before it starts me in opengl on the wrong foot?

    i hope petzold would write a book about opengl everything he writes is so solid and full of details. does he know opengl?heh

    $89 ahhhhh
    Last edited by SAMSAM; 02-14-2003 at 05:59 PM.

  12. #27
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    >>should i continue reding this book or giveit up for another one before it starts me in opengl on the wrong foot?


    theres nothing wrong with the book.

  13. #28
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    Rod gote say i typed the whole code without pasting because this source is not in the cd its suppose to be in chapter 2 and its not there. that one line i missed was the problem but i guess the compiler cant warn me about it.

    it is a good book no question but its just the cd which in my case i have to install chapters one at the time.

    anyway i forgot to say thx to you for finding that dumb mistake by me so how come all that define :
    #define WIN32_LEAN_AND_MEAN
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")
    #pragma comment(lib, "glaux.lib")
    #pragma comment(linker, "/subsystem:windows")

    was missing in the book and is it necessary?

    I like opengl already ,10 functions and 20 something extra line of code will give u a opengl window "WOW"

    i checked the similar code with directdraw7 "just the parts related to directdraw"u compare yourself;

    Code:
    #define INITGUID
    
    #define WINDOW_WIDTH  800           
    #define WINDOW_HEIGHT 600
    #define SCREEN_WIDTH  800             
    #define SCREEN_HEIGHT 600
    
    int G_Init(void *parms=NULL);
    int G_Shutdown(void *parms=NULL);
    int G_Main(void *parms=NULL);
    
    LPDIRECTDRAW7        lpdd         = NULL;
    LPDIRECTDRAWSURFACE7 lpddsprimary = NULL;  
    LPDIRECTDRAWSURFACE7 lpddsback    = NULL; 
    LPDIRECTDRAWPALETTE  lpddpal      = NULL;  
    DDSURFACEDESC2       ddsd;                
    DDSCAPS2             ddscaps;             
    HRESULT              ddrval;   
    
    
        int G_Init(void *parms)
    {
    
    
    
    // create object and test for error
    if (DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)!=DD_OK)
       return(0);
    
    // set cooperation level to windowed mode normal
    if (lpdd->SetCooperativeLevel(main_window_handle,
               DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN | 
               DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)!=DD_OK)
        return(0);
    
    // set the display mode
    if (lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,0,0)!=DD_OK)
       return(0);
    
    // Create the primary surface
    memset(&ddsd,0,sizeof(ddsd));
    ddsd.dwSize         = sizeof(ddsd);
    ddsd.dwFlags        = DDSD_CAPS;
    ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
    
    if (lpdd->CreateSurface(&ddsd,&lpddsprimary,NULL)!=DD_OK)
       return(0);
    
    // return success
    return(1);
    } // end Game_Init
    
    ///////////////////////////////////////////////////////////
    
    int G_Shutdown(void *parms)
    {
    
    
    
    // first release the primary surface
    if (lpddsprimary!=NULL)
       lpddsprimary->Release();
           
    // release the directdraw object
    if (lpdd!=NULL)
       lpdd->Release();
    
    // return success
    return(1);
    } // end Game_Shutdown
    
    ///////////////////////////////////////////////////////////
    
    int G_Main(void *parms)
    {
    
    
    UCHAR *video_buffer = NULL; // used to draw
    
    // check of user is trying to exit
    if (KEY_DOWN(VK_ESCAPE) || KEY_DOWN(VK_SPACE))
        PostMessage(main_window_handle, WM_DESTROY,0,0);
    
    
    
    // set up the surface description to lock the surface
    memset(&ddsd,0,sizeof(ddsd)); 
    ddsd.dwSize = sizeof(ddsd);
    
    
    
    lpddsprimary->Lock(NULL,&ddsd, 
                 DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
    
    
    
    video_buffer = (UCHAR *)ddsd.lpSurface;
    
    
    
    
    
    for (int index=0; index<100; index++)
        {
        // get random x,y
        int x = rand()%SCREEN_WIDTH;
        int y = rand()%SCREEN_HEIGHT;
    
        
        video_buffer[x + y*ddsd.lPitch] = rand()%256;
        } 
    
    
    lpddsprimary->Unlock(NULL);
    
    // return success
    return(1);
    } // end G_Main
    
    ///////////////////////////////////////////////////////////
    may be d3d8 is even longer i dont know.
    Last edited by SAMSAM; 02-14-2003 at 07:29 PM.

  14. #29
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    #define WIN32LEANANDMEAN trims down the windows libraries used

    #pragma comment(lib, "libname.lib") is another way of telling your compiler what libraries to link to (instead of manually going to project, settings, link, and then typing it in everytime). I.e I have a single heaer file in MainGL in my Include directory that has all of the necessary links to necessary library files as well as header files. I.e when I want to start a new opengl project I just do
    #include <MainGL\Main.h>
    and maingl has
    #pragma comment(lib, "libnam.lib") for all of the named opengl library files

    this is (a part of) my main.h header file which I include in every opengl project

    Code:
    #include <windows.h>
    #include <gl\gl.h>			
    #include <gl\glu.h>			
    #include <gl\glaux.h>		
    #include <fstream.h>
    #include <stdio.h>
    #include <time.h>
    #include <math.h>
    typedef unsigned char byte;
    typedef unsigned short word;
    
    #pragma comment(lib, "opengl32.lib")
    #pragma comment(lib, "glu32.lib")
    #pragma comment(lib, "glaux.lib")
    Oh and SAMSAM, you are going fast with this stuff, so don't start thinking to yourself things like "oh man this is such a big book, I absolutely must go fast so I can get really really good" because you are going at a good pace. Just make sure you take enough time to learn something, and have fun!

    EDIT:
    and yes, i know, fstream.h isn't the standard There are good reasons for that, actually
    EDIT1: OpenGL Game Programming is an awesome book, I like it a lot. I would recommend getting at least one other opengl book, though, because personally I never ever buy just one book on a particular topic.
    Last edited by Silvercord; 02-14-2003 at 07:33 PM.

  15. #30
    Registered User SAMSAM's Avatar
    Join Date
    Nov 2001
    Posts
    218
    Ok i made this small code few days ago out of bordom in GDI .that you can move in the tunnel with up arrow and down arrow "i know its pointless and not refined" by the way i couldnt attach the bitmap DDB so in the code please delete few lines related to bitmap and u get white color instead of bitmap at the end of the tunnel.

    but can anyone do this(if u get the time) in opengl, i be very curious and interested to see it done that way.

    thank u all for your comments. i think this thread has gone long enough.


    [code]


    #include "resource.h"
    #include <stdio.h>
    #define ID_TIMER 1
    static HBITMAP hbitmap;
    LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
    PSTR szCmdLine, int iCmdShow)
    {
    static char szAppName[] = TEXT ("Hell0 Sara") ;

    HWND hwnd ;
    MSG msg ;
    WNDCLASSEX wndclass ;
    wndclass.cbSize = sizeof(wndclass);
    wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
    wndclass.lpfnWndProc = WndProc ;
    wndclass.cbClsExtra = 0 ;
    wndclass.cbWndExtra = 0 ;
    wndclass.hInstance = hInstance ;
    wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
    wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    wndclass.lpszMenuName = NULL ;
    wndclass.lpszClassName = szAppName ;
    wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    RegisterClassEx(&wndclass);






    hwnd = CreateWindow (szAppName, // window class name
    TEXT ("The, Hello Little Sara"), // window caption
    WS_OVERLAPPEDWINDOW, // window style
    CW_USEDEFAULT, // initial x position
    CW_USEDEFAULT, // initial y position
    CW_USEDEFAULT, // initial x size
    CW_USEDEFAULT, // initial y size
    NULL, // parent window handle
    NULL, // window menu handle
    hInstance, // program instance handle
    NULL) ; // creation parameters

    ShowWindow (hwnd, iCmdShow) ;
    UpdateWindow (hwnd) ;

    while (GetMessage (&msg, NULL, 0, 0))
    {
    TranslateMessage (&msg) ;
    DispatchMessage (&msg) ;
    }
    return msg.wParam ;
    }

    LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    BOOL b = TRUE;

    static HDC hdc, hdcmem;
    PAINTSTRUCT ps ;
    static HBRUSH hbrush;

    static BITMAP bitmap;

    static int cxchar, cychar, cxclient, cyclient, i, j = 0, p = 0, n = 255, m = 45, f = 50, d = 50, s = 130,
    cxs, cys;
    HINSTANCE hInstance;
    TEXTMETRIC tm;
    static RECT rect, rect1, rc, rect2;
    static HRGN ergn; //not utilized yet






    switch (message)
    {
    case WM_CREATE:
    // SetTimer(hwnd, ID_TIMER, 500, NULL); //not utilized yet



    hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
    hbitmap = LoadBitmap(hInstance, TEXT ("mojo2"));
    GetObject(hbitmap, sizeof(BITMAP), &bitmap);
    cxs = bitmap.bmWidth;
    cys = bitmap.bmHeight;






    hdc = GetDC(hwnd);



    GetTextMetrics(hdc, &tm);

    cxchar = tm.tmAveCharWidth;
    cychar = tm.tmHeight + tm.tmExternalLeading;
    ReleaseDC(hwnd, hdc);



    return 0;
    case WM_SIZE:

    cxclient = LOWORD(lParam);

    cyclient = HIWORD(lParam);

    return 0;
    case WM_PAINT:

    hdc = BeginPaint (hwnd, &ps) ;
    GetUpdateRect(hwnd, &rect, FALSE);

    for(i = 0; i < 130 ; i++){
    rect.left = i * cxclient / 255 ;
    rect.top = i * cyclient / 255 ;
    rect.right = cxclient - i * cxclient / 255 ;
    rect.bottom = cyclient - i * cyclient / 255 ;





    hbrush = CreateSolidBrush(RGB(255 - p, 255 - p, 255 - p));
    p += 2;

    FillRect(hdc, &rect, hbrush);

    }


    //extra tunnel not utilized yet

    /* for(i = 0; i < 130 ; i++){

    rect1.left = i ;
    rect1.top = cyclient / 2 + i ;
    rect1.right = (cxclient / 3) - i ;
    rect1.bottom = (cyclient) - i ;

    hbrush = CreateSolidBrush(RGB(255 - p, 255 - p, 255 - p));
    p += 2;
    FillRect(hdc, &rect1, hbrush);

    }*/


    hbrush = CreateSolidBrush(RGB(245, 245, 245));
    SelectObject(hdc, hbrush);

    rect2.left = s * cxclient / 255 ;
    rect2.top = s * cyclient / 255 ;
    rect2.right = cxclient - s * cxclient / 255 ;
    rect2.bottom = cyclient - s * cyclient / 255 ;





    Rectangle(hdc, rect2.left ,rect2.top ,rect2.right , rect2.bottom);





    hdcmem = CreateCompatibleDC(hdc);
    SelectObject(hdcmem, hbitmap);



    StretchBlt(hdc,s * cxclient / 255 , s * cyclient / 255,(cxclient - s * cxclient / 255) - s * cxclient / 255 ,
    (cyclient - s * cyclient / 255) - s * cyclient / 255 , hdcmem, 0, 0, cxs, cys,
    MERGECOPY);

    DeleteDC(hdcmem);


    DeleteObject(hbrush);
    hbrush = CreateSolidBrush(RGB(255, 0, 0));
    SelectObject(hdc, hbrush);
    rc.left =(cxclient / 2)- 5;
    rc.top = cyclient - (m + 25);
    rc.right = cxclient / 2 + f ;
    rc.bottom= (cyclient - m) + d + 20;
    Ellipse(hdc, (cxclient / 2)- 5, cyclient - m ,cxclient / 2 + f, (cyclient - m) + d);
    DeleteObject(hbrush);

    p = 0;
    EndPaint (hwnd, &ps) ;
    return 0 ;

    // case WM_TIMER:

    // b = !b; //not utilized yet
    // return 0;
    case WM_KEYDOWN:
    switch(wParam){
    case VK_UP:
    if(m < (cyclient / 2 ) && f > 0 && d > 0){
    m += 15;
    f -=2;
    d -=2;
    }else{

    f -=2;
    d -=2;
    }
    s--;
    break;
    case VK_DOWN:
    if( m >= 25 && f > 0 && d > 0){
    m -= 15;
    f +=2;
    d +=2;

    }
    s++;
    break;
    }


    InvalidateRect(hwnd, &rect2, TRUE);InvalidateRect(hwnd, &rc, FALSE);
    return 0;
    case WM_DESTROY:

    //KillTimer(hwnd, ID_TIMER);


    DeleteObject(hbrush);
    PostQuitMessage (0) ;
    return 0 ;
    }
    return DefWindowProc (hwnd, message, wParam, lParam) ;
    }

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get relative mouse coordinates when GLUT return absolute
    By joeprogrammer in forum Game Programming
    Replies: 14
    Last Post: 02-10-2009, 06:35 PM
  2. Running into trouble with GLUT.
    By Josh@Dreamland in forum C++ Programming
    Replies: 4
    Last Post: 12-29-2007, 09:32 PM
  3. Glut
    By Matty_Alan in forum C Programming
    Replies: 7
    Last Post: 07-16-2007, 08:01 AM
  4. GLUT and Dev-CPP
    By Canadian_coder in forum Game Programming
    Replies: 4
    Last Post: 12-22-2004, 03:12 AM
  5. Dis/Advantages of Glut?
    By Zeusbwr in forum Game Programming
    Replies: 1
    Last Post: 11-28-2004, 10:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21