Esempio n. 1
0
/**************************
 * Sets up Dialogs
 * as well as GUI code
 **************************/
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;        
    MSG msg;
    BOOL bQuit = FALSE;
    /* register window class */
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLTEST";
    RegisterClass (&wc);
    hWnd = CreateWindow ("GLTEST", "", WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
    0, 0, 0,0, //a quick kludge to stop a window being shown, only main DLG is shown
    NULL, NULL, hInstance, NULL); //as we need a OpenGL window
    EnableOpenGL ();
	LoadBASS();
	InitSoundSystem(hWnd);
    DialogBox (hInstance, MAKEINTRESOURCE(IDD_DLG1 ), hWnd, TestDlgProc);
	return true;
}
Esempio n. 2
0
int WinAPIInit(char * WndTitle, int Width, int Height)
{
	HINSTANCE hInstance = GetModuleHandle(NULL);

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_OWNDC;
	wcex.lpfnWndProc = WindowProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = hInstance;
	wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wcex.lpszMenuName = NULL;
	wcex.lpszClassName = APPTITLE;
	wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

	if(!RegisterClassEx(&wcex)) return EXIT_SUCCESS;

	hwnd = CreateWindowEx(0, APPTITLE, WndTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, Width, Height, NULL, NULL, hInstance, NULL);
	ShowWindow(hwnd, true);

	EnableOpenGL(hwnd, &hDC, &hRC);

	// resize window for OpenGL area itself to be ex. 640x480, not the actual window
	WinAPISetWindowSize((Width + GetSystemMetrics(SM_CXSIZEFRAME) + GetSystemMetrics(SM_CXFRAME)), (Height + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYSIZEFRAME) + GetSystemMetrics(SM_CYFRAME)));

	return EXIT_SUCCESS;
}
Esempio n. 3
0
//---------------------------------------------------------------------------
__fastcall TFormMapper::TFormMapper(TComponent* Owner)
        : TForm(Owner)
{
  Application->OnIdle=IdleLoop;
  hDC=GetDC(ViewBox->Handle);
  EnableOpenGL(ViewBox->Handle,&hDC,&hRC);

  obj=gluNewQuadric();			// Create A Pointer To The Quadric Object ( NEW )
  gluQuadricNormals(obj, GLU_SMOOTH);	// Create Smooth Normals ( NEW )
  gluQuadricTexture(obj, GL_TRUE);	// Create Texture Coords ( NEW )

}
Esempio n. 4
0
void PlotWindow::show(void) {

	if(isInit) {
	
		ShowWindow(hWnd, 1);
		EnableOpenGL(hWnd, &hDC, &hRC);
		
		isShowing = true;
		
	}

}
Esempio n. 5
0
void Cgreven::createWindow()
{

    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = NULL;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor =  LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "greven";
    RegisterClass (&wc);

    if (fullScreen)
    {
        dwExStyle=WS_EX_APPWINDOW;
        dwStyle=WS_VISIBLE |WS_POPUP | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
        //ShowCursor(FALSE);
        DEVMODE dmScreenSettings; // Device Mode
        memset(&dmScreenSettings,0,sizeof(dmScreenSettings)); // Makes Sure Memory's Cleared
        dmScreenSettings.dmSize=sizeof(dmScreenSettings); // Size Of The Devmode Structure
        dmScreenSettings.dmPelsWidth = width; // Selected Screen Width
        dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
        dmScreenSettings.dmBitsPerPel = 32; // Selected Bits Per Pixel
        dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
        if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
            MessageBox(hWnd,"Fullscreen Error","Fullscreen Error",0);


    }
    else
    {
        dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
        dwStyle=WS_VISIBLE | WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
    }



    hWnd = CreateWindowEx(dwExStyle,
    wc.lpszClassName, "greven",
    dwStyle,
    0, 0, width, height,
    NULL, NULL, NULL, NULL);
    //MessageBox(hWnd,"a","a",0);

    EnableOpenGL ();

};
int Game_Init(void *parms = NULL, int num_parms = 0)
{
	// this is called once after the initial window is created and
	// before the main event loop is entered, do all your initialization
	// here
	ghDC = GetDC(ghWnd);

	EnableOpenGL();
	SceneInit(WIDTH, HEIGHT);

	// return success or failure or your own return code here
	return(1);

} // end Game_Init
void SceneRenderer::onInit(HWND hWnd)
{
	hwnd = hWnd;
	EnableOpenGL(hwnd);
	glClearColor(0.5f, 0.5f, 1.0f, 0.0f);
	glEnable(GL_DEPTH_TEST);
	glShadeModel(GL_SMOOTH);

	glClearDepth(1.0f);
	glDepthFunc(GL_LEQUAL);

	shader = SM.loadfromFile("vert_shader.vs","frag_shader.fs"); // load (and compile, link) shaders from file
		if (shader==0) 
			std::cout << "Error Loading, compiling or linking shader\n";
}
Esempio n. 8
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	
	MSG msg;
	HACCEL hAccelTable;
	
	vec.push_back(new Points);
	vec.push_back(new Lines);
//	vec.push_back(new Lines);

	MyRegisterClass(hInstance);
	if (!InitInstance (hInstance, nCmdShow)) 
	{
		return FALSE;
	}
	GetClientRect(g_hwnd,&g_clientRect);
	g_cliWidth = g_clientRect.right - g_clientRect.left;
	g_cliHeight = g_clientRect.bottom - g_clientRect.top;
	EnableOpenGL();
	SceneInit(g_clientRect.right, g_clientRect.bottom);
	GetWindowRect(g_hwnd, &g_rect);
	g_scrWidth = g_rect.right - g_rect.left;
	g_scrHeight = g_rect.bottom - g_rect.top;
	if(g_cliWidth > 0 && g_cliHeight > 0)
		SceneResizeViewport(g_cliWidth, g_cliHeight);
	hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_XY);
	SceneShow();
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}

	DisableOpenGL();
	DestroyWindow(g_hwnd);
	for(size_t i = 0; i != vec.size(); ++i)
		delete vec[i];
	vec.clear();
	ChangeDisplaySettings(NULL,0);
	
	return msg.wParam;
}
Esempio n. 9
0
int
poly3d_Init( HWND hWnd, int width, int height )
{
	mLogicalWidth = width;
	mLogicalHeight = height;
	printf( "logical size=%d,%d\n", width, height );

   EnableOpenGL( hWnd, &mhDC, &mhRC );

	poly3d_ResizeWindow( width, height );

   glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
   glEnable( GL_DEPTH_TEST );
// glEnable(GL_CULL_FACE);
	glCullFace( GL_BACK );
   return 0;
} /* poly3d_Init */
Esempio n. 10
0
void glutCreateWindow(char *title)
{
	// Convert title to szTitle!
	#define MAX_LOADSTRING 100
	TCHAR szTitle[MAX_LOADSTRING];					// The title bar text
    int size_needed = MultiByteToWideChar(CP_UTF8, 0, &title[0], strlen(title), NULL, 0);
    MultiByteToWideChar(CP_UTF8, 0, &title[0], strlen(title), &szTitle[0], size_needed);
	szTitle[size_needed] = 0; // Zero terminate

	// create main window
	hWnd = CreateWindow( 
		"GLSample" /*This is really wrong, should be 16-bit text like the title!*/, szTitle, 
		WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE | WS_OVERLAPPEDWINDOW, // WS_OVERLAPPEDWINDOW gives rescalable window
		gWindowPosX, gWindowPosY, gWindowWidth, gWindowHeight,
		NULL, NULL, hInstance, NULL );
//	hWnd = CreateWindow( 
//		"GLSample" /*This is really wrong, should be 16-bit text like the title!*/, szTitle, 
//		WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE | WS_OVERLAPPEDWINDOW, // WS_OVERLAPPEDWINDOW gives rescalable window
//		0, 0, 256, 256,
//		NULL, NULL, hInstance, NULL );
	
	// enable OpenGL for the window
	EnableOpenGL( hWnd, &hDC, &hRC );
}
// WinMain
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int cmdShow){
	argv =CommandLineToArgvW(GetCommandLineW(),&argc);

	directory = getDirectory();
	srand(time(0));
#ifdef _DEBUG
	console();
#endif
	loadSaves();
	int height=768,width =1024;
	calcSizes(768-menuHeight,1024-border);

	WNDCLASSEX wc;

	//HDC hDC;
	HGLRC hRC;

	// register window class
	//definere et vindues classe og dens parametre/udsende
	wc.cbSize		 = sizeof(WNDCLASSEX);
	wc.style = 0;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	//alt tab icon + windows linie icon
	wc.hIcon = LoadIcon( GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1) );
	//look of the cursor
	wc.hCursor = LoadCursor( NULL, IDC_ARROW );
	//background color
	wc.hbrBackground = (HBRUSH)GetSysColorBrush(COLOR_3DFACE);
	//menu bar
	wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
	wc.lpszClassName = "main";
	//icon venstre top hjørne
	//følgende virker også, loader dog default 32x32 icon
	//LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON1));
	wc.hIconSm		 = (HICON)LoadImage(GetModuleHandle(NULL),MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 16, 16, 0);
	if(!RegisterClassEx(&wc)){
		MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	// create main window
	hWnd = CreateWindowEx( WS_EX_CLIENTEDGE,
		"main", "Walking With Dinosaurs",
		WS_THICKFRAME | WS_CAPTION | WS_VISIBLE | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX |WS_CLIPCHILDREN |WS_MAXIMIZEBOX,
		GetSystemMetrics(SM_CXMAXIMIZED)/2-SM_CXFIXEDFRAME/2-width/2-listWidth, GetSystemMetrics(SM_CYMAXIMIZED)/2-SM_CYFIXEDFRAME/2-height/2, 1024, 768,
		NULL, NULL, hInstance, NULL );

	//simulations window
	// register window class
	wc.cbSize		 = sizeof(WNDCLASSEX);
	//cs_owndc svaes the cach, used for painting outside normal routine
	wc.style = CS_OWNDC;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	wc.hCursor = LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "blank";
	if(!RegisterClassEx(&wc)){
		MessageBox(NULL, "Window Registration Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK);
		return 0;
	}

	blank = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("blank"), "", WS_CHILD | WS_VISIBLE ,listWidth,bAreaHeight,simWidth,simHeight, hWnd,(HMENU)IDC_SIM, GetModuleHandle(NULL), NULL);

	EnableOpenGL( blank, &hDC, &hRC );

	//selection listbox
	hWndList = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("listbox"), "", WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_AUTOVSCROLL|LBS_NOTIFY,0, 0, listWidth, listHeight, hWnd,  (HMENU)IDC_LISTBOX, GetModuleHandle(NULL), NULL);
	for(int i=0;i<(int)saves.size();i++){
		SendMessage(hWndList, LB_ADDSTRING, 0, (LPARAM)saves.at(i)->name.c_str());
	}
	SendMessage(hWndList,LB_SETCURSEL,0,0);

	//init creature/world
	WWDPhysics = new Physics();
	readDNA(&saves.at(0)->dna,WWDPhysics);
	WWDPhysics->runSimStartUp();
	WWDPhysics->reshape(simWidth,simHeight);

	//settings area
	int row1=10,row2=35, row3 =60;
	int col1 =160,col2=col1+170,col3=500,col4=col3+170, col5=340,col6=col5+170;
	HWND hWndFitS=CreateWindowEx(NULL,TEXT("STATIC"),	"Fitness Test",WS_CHILD|WS_VISIBLE,	col1, row1, 100, 18, hWnd, (HMENU)IDC_TEST_STATIC, GetModuleHandle(NULL),	NULL);
	HWND hwndCombo = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("combobox"), "", WS_CHILD | WS_VISIBLE| CBS_DROPDOWNLIST ,col2, row1-5, 150, 24, hWnd,  (HMENU)IDC_FITNESSTYPE_COMBOBOX, GetModuleHandle(NULL), NULL);

	SendMessage(hwndCombo,CB_ADDSTRING, 0, (LPARAM)"Move");
	SendMessage(hwndCombo,CB_SETITEMDATA, 0, move);

	SendMessage(hwndCombo,CB_ADDSTRING, 0, (LPARAM)"Iterative Move");
	SendMessage(hwndCombo,CB_SETITEMDATA, 1, iterateMove);

	SendMessage(hwndCombo,CB_ADDSTRING, 0, (LPARAM)"Dwarfslayer Move");
	SendMessage(hwndCombo,CB_SETITEMDATA, 2, dwarfslayerMove);

	SendMessage(hwndCombo,CB_ADDSTRING, 0, (LPARAM)"Fat Loving Move");
	SendMessage(hwndCombo,CB_SETITEMDATA, 3, fatLovingMove);

	SendMessage(hwndCombo,CB_ADDSTRING, 0, (LPARAM)"Box Loving Move");
	SendMessage(hwndCombo,CB_SETITEMDATA, 4, boxLovingMove);

	SendMessage(hwndCombo,CB_ADDSTRING, 0, (LPARAM)"Jump");
	SendMessage(hwndCombo,CB_SETITEMDATA, 5, jump);

	SendMessage(hwndCombo,CB_ADDSTRING, 0, (LPARAM)"Combi");
	SendMessage(hwndCombo,CB_SETITEMDATA, 6, combi);

	SendMessage(hwndCombo,CB_ADDSTRING, 0, (LPARAM)"None");
	SendMessage(hwndCombo,CB_SETITEMDATA, 7, none);

	SendMessage(hwndCombo,CB_SETCURSEL,0,0);
	WWDPhysics->addFitnessFunction(move,1);

	HWND hWndButton=CreateWindowEx(NULL,TEXT("BUTTON"),	"RUN", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
		col1, row3, 100, 24,
		hWnd, (HMENU)IDC_RUN_BUTTON, GetModuleHandle(NULL),	NULL);

	HWND hWndResetButton=CreateWindowEx(NULL,TEXT("BUTTON"),	"Reset Simulation", WS_TABSTOP|WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
		col3, row3, 150, 24,
		hWnd, (HMENU)IDC_RESET_BUTTON, GetModuleHandle(NULL),	NULL);

	HGDIOBJ hfDefault=GetStockObject(DEFAULT_GUI_FONT);
	SendMessage(hWndButton,WM_SETFONT, (WPARAM)hfDefault, MAKELPARAM(FALSE,0));

	HWND hWndNoG=CreateWindowEx(NULL,TEXT("STATIC"),"Number of Generations",WS_CHILD|WS_VISIBLE,	col1, row2, 150, 18,
		hWnd, (HMENU)IDC_NOG_STATIC, GetModuleHandle(NULL),	NULL);

	HWND hWndNoGS=CreateWindowEx(NULL,TEXT("EDIT"),	"50",WS_CHILD|WS_VISIBLE|ES_NUMBER,	col2, row2, 42, 18,
		hWnd, (HMENU)IDC_NOG_EDIT, GetModuleHandle(NULL),	NULL);

	HWND hWndPopS=CreateWindowEx(NULL,TEXT("STATIC"),	"Population Size",WS_CHILD|WS_VISIBLE,	col3, row1, 150, 18,
		hWnd, (HMENU)IDC_POP_STATIC, GetModuleHandle(NULL),	NULL);
	HWND hWndPop=CreateWindowEx(NULL,TEXT("EDIT"),	"100",WS_CHILD|WS_VISIBLE |ES_NUMBER,	col4, row1, 42, 18,
		hWnd, (HMENU)IDC_POP_EDIT, GetModuleHandle(NULL),	NULL);

	HWND hWndViewRate=CreateWindowEx(NULL,TEXT("STATIC"),	"Simulation view precision",WS_CHILD|WS_VISIBLE,	col3, row2, 200, 18,
		hWnd, (HMENU)IDC_VIEW_STATIC, GetModuleHandle(NULL),	NULL);

	HWND hWndViewRateB=CreateWindowEx(NULL,TEXT("BUTTON"),	"",WS_CHILD|WS_VISIBLE | BS_CHECKBOX,	col4, row2, 100, 18,
		hWnd, (HMENU)IDC_VIEW_CHECKBOX, GetModuleHandle(NULL),	NULL);
	SendMessage(hWndViewRateB, BM_SETCHECK, BST_CHECKED,0);
	fixedSteps=true;
	EnableWindow(hWndViewRateB,false);


	MSG msg = messageLoop(hDC, hRC);
	return msg.wParam;
}
Esempio n. 12
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    wcex.hCursor = LoadCursor(NULL, IDC_CROSS);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = "sss";
    wcex.lpszClassName = "visualFeng";
    wcex.hIconSm =LoadIcon(NULL, IDI_WINLOGO);


    if (!RegisterClassEx(&wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          "visualFeng",
                          "visualFeng_v1.0",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          800,
                          800,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &hDC, &hRC);

    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            /* OpenGL animation code goes here */

            glClearColor(0.2f, 0.2f, 0.2f, 0.2f);
            glShadeModel(GL_FLAT);
            glShadeModel(GL_SMOOTH);
            glClear(GL_COLOR_BUFFER_BIT);
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            GLfloat lightIntensity=3.4;

            //-----------------------light
            GLfloat LightAmbient[]= { 0.0f, 0.1f, 0.1f, 1.0f };
            GLfloat LightDiffuse[]=     {lightIntensity,lightIntensity, lightIntensity, 1.0f };
            GLfloat LightPosition[]=    { 0.5f, 0.30f, 0.5f, 1.0f };
            GLfloat Light_Model_Ambient[] = { -1.0f, -1.0f, -1.0f, 1.0f };
            GLfloat LightSpecular[]=    { 1.0f, 1.0f, 1.0f, 1.0f };
            GLfloat MaterialSpecular[] = { 1.0f,1.0f,1.0f,1.0f };


            glLightfv(GL_LIGHT1,GL_SPECULAR, LightSpecular);//光源的反射分量

            glMaterialfv(GL_FRONT,GL_SPECULAR,MaterialSpecular);//材质的反射分量

            glMaterialf(GL_FRONT,GL_SHININESS,128);//后面的值越大,光线越集中

            glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
            glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
            glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
            glLightModelfv(GL_LIGHT_MODEL_AMBIENT, Light_Model_Ambient);


            glEnable(GL_LIGHT1);
            glEnable(GL_LIGHTING);
            glEnable(GL_COLOR_MATERIAL);
            //-----------------------light

            //gluLookAt(10,10,10,0,0,0,0,0,1);
            //glFrustum(-1,1,-1,1,1,900);
            //glMatrixMode(GL_MODELVIEW);


            //glClearDepth(1.0f);
            //glEnable(GL_DEPTH_TEST);
            GLfloat fogColor [4]={0,0.2,0.99,1};
            glEnable(GL_FOG);
            glFogfv(GL_FOG_COLOR,fogColor);


//            //------------------------------draw model
            glPushMatrix();
            glRotated(40,0,1,0);
            //glutSolidCube(1.0f);
            glBegin(GL_QUADS);
                glColor3f(0.5f,0.5f,0.5f);
                glVertex2f( -0.5f,-0.5f);
                //glColor3f(0.9f,0.0f,0.2f);
                glVertex2f(0.5f,-0.5f);
                //glColor3f(0.2f,0.9f,0.2f);
                glVertex2f(0.5f,0.5f);
                //glColor3f(0.2f,0.0f,0.2f);
                glVertex2f( -0.5f,0.5f);

            glEnd();
            //glRotated(40,0,0,1);
            glRotated(80,1,0,0);
            //glutSolidSphere(1.0,40,40);
            glBegin(GL_QUADS);
                glColor3f(0.5f,0.5f,0.5f);
                glVertex2f( -0.5f,-0.5f);
                //glColor3f(0.9f,0.0f,0.2f);
                glVertex2f(0.5f,-0.5f);
                //glColor3f(0.2f,0.9f,0.2f);
                glVertex2f(0.5f,0.5f);
                glColor3f(0.2f,0.0f,0.2f);
                glVertex2f( -0.5f,0.5f);

            glEnd();
            glPopMatrix();
            //glPushMatrix();

            //glRotated(40,1,0,0);
            //glRotated(40,0,0,1);

            grid(1);
            //xyz grid
            int xyzL=10;
            glBegin(GL_LINES);
            glColor3f(0.0f, 0.0f, 1.0f);
            glVertex3f(0.0f, 0.0f, -xyzL);
            glColor3f(0.0f, 1.0f, 0.0f);
            glVertex3f(0.0f, 0.0f, xyzL);
            glColor3f(0.0f, 1.0f, 0.0f);
            glVertex3f(xyzL, 0.0f, 0.0f);
            glColor3f(1.0f, 0.0f, 0.0f);
            glVertex3f(-xyzL, 0.0f, 0.0f);
            glColor3f(1.0f, 0.0f, 0.0f);
            glVertex3f(0.0f, -xyzL, 0.0f);
            glColor3f(0.0f, 0.0f, 1.0f);
            glVertex3f(0.0f, xyzL, 0.0f);
            glEnd();
            //grid(0);

            //glPopMatrix();

            //glFlush();
            //------------------------------draw model




            SwapBuffers(hDC);
            // printf("opengl li  %d\n",fengx);
            theta += 1.0f;
            Sleep (1);



        }
    }

    /* shutdown OpenGL */
    DisableOpenGL(hwnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow(hwnd);

    return msg.wParam;
}
Esempio n. 13
0
File: main.c Progetto: jeaf/balles
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL quit = FALSE;

    // register window class
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wc.hCursor = LoadCursor( NULL, IDC_ARROW );
    wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLSample";
    RegisterClass( &wc );

    // create main window
    hWnd = CreateWindow("GLSample", "OpenGL Sample",
                        WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
                        0, 0, 1100, 700,
                        NULL, NULL, hInstance, NULL);

    if (!CenterWindow(hWnd))
    {
        MessageBox(0, "CenterWindow fail", "Caption", 0);
    }

    // enable OpenGL for the window
    EnableOpenGL(hWnd, &hDC, &hRC);

    // Allocate a console for debugging purposes
    //AllocConsole();
    //freopen("CONOUT$", "wb", stdout);

    gameloop_init();

    // program main loop
    while (!quit)
    {
        // check for messages
        if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )  )
        {
            // handle or dispatch messages
            if (msg.message == WM_QUIT)
            {
                quit = TRUE;
            }
            else
            {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
        }
        else
        {
            gameloop_update();
            gameloop_draw(hDC);
            SwapBuffers(hDC);
            Sleep(1);
        }
    }

    // shutdown OpenGL
    DisableOpenGL(hWnd, hDC, hRC);

    // destroy the window explicitly
    DestroyWindow(hWnd);

    return msg.wParam;
}
Esempio n. 14
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;


    if (!RegisterClassEx(&wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "Tomas testar OpenGL",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          1366,
                          768,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &hDC, &hRC);

    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            /* OpenGL animation code goes here */

            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT);

            glPushMatrix();
            glRotatef(theta, 0.25f, 0.25f, 0.25f);

glBegin(GL_QUADS);                // Begin drawing the color cube with 6 quads
// Back face (z = -1.0f)
      glColor3f(1.0f, 1.0f, 0.0f);     // Yellow
      glVertex3f( 0.5f, -0.5f, -0.5f);
      glVertex3f(-0.5f, -0.5f, -0.5f);
      glVertex3f(-0.5f,  0.5f, -0.5f);
      glVertex3f( 0.5f,  0.5f, -0.5f);

            // Bottom face (y = -1.0f)
      glColor3f(1.0f, 0.5f, 0.0f);     // Orange
      glVertex3f( 0.5f, -0.5f,  0.5f);
      glVertex3f(-0.5f, -0.5f,  0.5f);
      glVertex3f(-0.5f, -0.5f, -0.5f);
      glVertex3f( 0.5f, -0.5f, -0.5f);

      // Right face (x = 1.0f)
      glColor3f(1.0f, 0.0f, 1.0f);     // Magenta
      glVertex3f(0.5f,  0.5f, -0.5f);
      glVertex3f(0.5f,  0.5f,  0.5f);
      glVertex3f(0.5f, -0.5f,  0.5f);
      glVertex3f(0.5f, -0.5f, -0.5f);

      // Front face  (z = 1.0f)
      glColor3f(1.0f, 0.0f, 0.0f);     // Red
      glVertex3f( 0.5f,  0.5f, 0.5f);
      glVertex3f(-0.5f,  0.5f, 0.5f);
      glVertex3f(-0.5f, -0.5f, 0.5f);
      glVertex3f( 0.5f, -0.5f, 0.5f);

      // Left face (x = -1.0f)
      glColor3f(0.0f, 0.0f, 1.0f);     // Blue
      glVertex3f(-0.5f,  0.5f,  0.5f);
      glVertex3f(-0.5f,  0.5f, -0.5f);
      glVertex3f(-0.5f, -0.5f, -0.5f);
      glVertex3f(-0.5f, -0.5f,  0.5f);

      // Top face (y = 1.0f)
      // Define vertices in counter-clockwise (CCW) order with normal pointing out
      glColor3f(0.0f, 1.0f, 0.0f);     // Green
      glVertex3f( 0.5f, 0.5f, -0.5f);
      glVertex3f(-0.5f, 0.5f, -0.5f);
      glVertex3f(-0.5f, 0.5f,  0.5f);
      glVertex3f( 0.5f, 0.5f,  0.5f);

         glEnd();  // End of drawing color-cube
/*            glBegin(GL_TRIANGLES);

                glColor3f(1.0f, 1.0f, 0.0f);   glVertex2f(0.0f,   1.0f);
                glColor3f(0.0f, 1.0f, 1.0f);   glVertex2f(0.47f,  -0.5f);
                glColor3f(1.0f, 0.0f, 1.0f);   glVertex2f(-0.87f, -0.5f);

            glEnd();
*/
            glPopMatrix();

            SwapBuffers(hDC);

            theta += 0.2f;
            Sleep (1);
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL(hwnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow(hwnd);

    return msg.wParam;
}
Esempio n. 15
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    // register window class
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);


    if (!RegisterClassEx(&wcex))
        return 0;

    // create main window
    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "SOIL Sample",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          512,
                          512,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    //	check my error handling
    /*
    SOIL_load_OGL_texture( "img_test.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, 0 );
    std::cout << "'" << SOIL_last_result() << "'" << std::endl;
    */


    // enable OpenGL for the window
    EnableOpenGL(hwnd, &hDC, &hRC);

    glEnable( GL_BLEND );
    //glDisable( GL_BLEND );
    //	straight alpha
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
    //	premultiplied alpha (remember to do the same in glColor!!)
    //glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA );

    //	do I want alpha thresholding?
    glEnable( GL_ALPHA_TEST );
    glAlphaFunc( GL_GREATER, 0.5f );

    //	log what the use is asking us to load
    std::string load_me = lpCmdLine;
    if( load_me.length() > 2 )
    {
		//load_me = load_me.substr( 1, load_me.length() - 2 );
		load_me = load_me.substr( 0, load_me.length() - 0 );
    } else
    {
    	//load_me = "img_test_uncompressed.dds";
    	//load_me = "img_test_indexed.tga";
    	//load_me = "img_test.dds";
    	load_me = "img_test.png";
    	//load_me = "odd_size.jpg";
    	//load_me = "img_cheryl.jpg";
    	//load_me = "oak_odd.png";
    	//load_me = "field_128_cube.dds";
    	//load_me = "field_128_cube_nomip.dds";
    	//load_me = "field_128_cube_uc.dds";
    	//load_me = "field_128_cube_uc_nomip.dds";
    	//load_me = "Goblin.dds";
    	//load_me = "parquet.dds";
    	//load_me = "stpeters_probe.hdr";
    	//load_me = "VeraMoBI_sdf.png";

    	//	for testing the texture rectangle code
    	//load_me = "test_rect.png";
    }
	std::cout << "'" << load_me << "'" << std::endl;

	//	1st try to load it as a single-image-cubemap
	//	(note, need DDS ordered faces: "EWUDNS")
	GLuint tex_ID;
    int time_me;

    std::cout << "Attempting to load as a cubemap" << std::endl;
    time_me = clock();
	tex_ID = SOIL_load_OGL_single_cubemap(
			load_me.c_str(),
			SOIL_DDS_CUBEMAP_FACE_ORDER,
			SOIL_LOAD_AUTO,
			SOIL_CREATE_NEW_ID,
			SOIL_FLAG_POWER_OF_TWO
			| SOIL_FLAG_MIPMAPS
			//| SOIL_FLAG_COMPRESS_TO_DXT
			//| SOIL_FLAG_TEXTURE_REPEATS
			//| SOIL_FLAG_INVERT_Y
			| SOIL_FLAG_DDS_LOAD_DIRECT
			);
	time_me = clock() - time_me;
	std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;
    if( tex_ID > 0 )
    {
    	glEnable( GL_TEXTURE_CUBE_MAP );
		glEnable( GL_TEXTURE_GEN_S );
		glEnable( GL_TEXTURE_GEN_T );
		glEnable( GL_TEXTURE_GEN_R );
		glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP );
		glBindTexture( GL_TEXTURE_CUBE_MAP, tex_ID );
		//	report
		std::cout << "the loaded single cube map ID was " << tex_ID << std::endl;
		//std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;
    } else
    {
    	std::cout << "Attempting to load as a HDR texture" << std::endl;
		time_me = clock();
		tex_ID = SOIL_load_OGL_HDR_texture(
				load_me.c_str(),
				//SOIL_HDR_RGBE,
				//SOIL_HDR_RGBdivA,
				SOIL_HDR_RGBdivA2,
				0,
				SOIL_CREATE_NEW_ID,
				SOIL_FLAG_POWER_OF_TWO
				| SOIL_FLAG_MIPMAPS
				//| SOIL_FLAG_COMPRESS_TO_DXT
				);
		time_me = clock() - time_me;
		std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;

		//	did I fail?
		if( tex_ID < 1 )
		{
			//	loading of the single-image-cubemap failed, try it as a simple texture
			std::cout << "Attempting to load as a simple 2D texture" << std::endl;
			//	load the texture, if specified
			time_me = clock();
			tex_ID = SOIL_load_OGL_texture(
					load_me.c_str(),
					SOIL_LOAD_AUTO,
					SOIL_CREATE_NEW_ID,
					SOIL_FLAG_POWER_OF_TWO
					| SOIL_FLAG_MIPMAPS
					//| SOIL_FLAG_MULTIPLY_ALPHA
					//| SOIL_FLAG_COMPRESS_TO_DXT
					| SOIL_FLAG_DDS_LOAD_DIRECT
					//| SOIL_FLAG_NTSC_SAFE_RGB
					//| SOIL_FLAG_CoCg_Y
					//| SOIL_FLAG_TEXTURE_RECTANGLE
					);
			time_me = clock() - time_me;
			std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;
		}

		if( tex_ID > 0 )
		{
			//	enable texturing
			glEnable( GL_TEXTURE_2D );
			//glEnable( 0x84F5 );// enables texture rectangle
			//  bind an OpenGL texture ID
			glBindTexture( GL_TEXTURE_2D, tex_ID );
			//	report
			std::cout << "the loaded texture ID was " << tex_ID << std::endl;
			//std::cout << "the load time was " << 0.001f * time_me << " seconds (warning: low resolution timer)" << std::endl;
		} else
		{
			//	loading of the texture failed...why?
			glDisable( GL_TEXTURE_2D );
			std::cout << "Texture loading failed: '" << SOIL_last_result() << "'" << std::endl;
		}
    }

    // program main loop
    const float ref_mag = 0.1f;
    while (!bQuit)
    {
        // check for messages
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            // handle or dispatch messages
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            // OpenGL animation code goes here
            theta = clock() * 0.1;

            float tex_u_max = 1.0f;//0.2f;
            float tex_v_max = 1.0f;//0.2f;

            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT);

            glPushMatrix();
            glScalef( 0.8f, 0.8f, 0.8f );
            //glRotatef(-0.314159f*theta, 0.0f, 0.0f, 1.0f);
			glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
			glNormal3f( 0.0f, 0.0f, 1.0f );
            glBegin(GL_QUADS);
				glNormal3f( -ref_mag, -ref_mag, 1.0f );
                glTexCoord2f( 0.0f, tex_v_max );
                glVertex3f( -1.0f, -1.0f, -0.1f );

                glNormal3f( ref_mag, -ref_mag, 1.0f );
                glTexCoord2f( tex_u_max, tex_v_max );
                glVertex3f( 1.0f, -1.0f, -0.1f );

                glNormal3f( ref_mag, ref_mag, 1.0f );
                glTexCoord2f( tex_u_max, 0.0f );
                glVertex3f( 1.0f, 1.0f, -0.1f );

                glNormal3f( -ref_mag, ref_mag, 1.0f );
                glTexCoord2f( 0.0f, 0.0f );
                glVertex3f( -1.0f, 1.0f, -0.1f );
            glEnd();
            glPopMatrix();

			tex_u_max = 1.0f;
            tex_v_max = 1.0f;
            glPushMatrix();
            glScalef( 0.8f, 0.8f, 0.8f );
            glRotatef(theta, 0.0f, 0.0f, 1.0f);
			glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
			glNormal3f( 0.0f, 0.0f, 1.0f );
            glBegin(GL_QUADS);
                glTexCoord2f( 0.0f, tex_v_max );		glVertex3f( 0.0f, 0.0f, 0.1f );
                glTexCoord2f( tex_u_max, tex_v_max );		glVertex3f( 1.0f, 0.0f, 0.1f );
                glTexCoord2f( tex_u_max, 0.0f );		glVertex3f( 1.0f, 1.0f, 0.1f );
                glTexCoord2f( 0.0f, 0.0f );		glVertex3f( 0.0f, 1.0f, 0.1f );
            glEnd();
            glPopMatrix();

            {
				/*	check for errors	*/
				GLenum err_code = glGetError();
				while( GL_NO_ERROR != err_code )
				{
					printf( "OpenGL Error @ %s: %i", "drawing loop", err_code );
					err_code = glGetError();
				}
			}

            SwapBuffers(hDC);

            Sleep (1);
        }
    }

    //	and show off the screenshot capability
    /*
    load_me += "-screenshot.tga";
    SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_TGA, 0, 0, 512, 512 );
    //*/
    //*
    load_me += "-screenshot.bmp";
    SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_BMP, 0, 0, 512, 512 );
    //*/
    /*
    load_me += "-screenshot.dds";
    SOIL_save_screenshot( load_me.c_str(), SOIL_SAVE_TYPE_DDS, 0, 0, 512, 512 );
    //*/

    // shutdown OpenGL
    DisableOpenGL(hwnd, hDC, hRC);

    // destroy the window explicitly
    DestroyWindow(hwnd);

    return msg.wParam;
}
Esempio n. 16
0
File: main.c Progetto: Chuvi-w/cpp
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow) {
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;


    if (!RegisterClassEx(&wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "OpenGL Sample",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          256,
                          256,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &hDC, &hRC);

    /* program main loop */
    while (!bQuit) {
        /* check for messages */
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
                bQuit = TRUE;
            else {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        } else {
            /* OpenGL animation code goes here */

            glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            glClear(GL_COLOR_BUFFER_BIT);

            glPushMatrix();
            glRotatef(theta, 0.0f, 0.0f, 1.0f);

            glBegin(GL_TRIANGLES);

            glColor3f(1.0f, 0.0f, 0.0f);
            glVertex2f(0.0f,   1.0f);
            glColor3f(0.0f, 1.0f, 0.0f);
            glVertex2f(0.87f,  -0.5f);
            glColor3f(0.0f, 0.0f, 1.0f);
            glVertex2f(-0.87f, -0.5f);

            glEnd();

            glPopMatrix();

            SwapBuffers(hDC);

            theta += 1.0f;
            Sleep (1);
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL(hwnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow(hwnd);

    return msg.wParam;
}
Esempio n. 17
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
				   LPSTR lpCmdLine, int iCmdShow)
{
	WNDCLASS wc;
	HGLRC hRC;
	MSG msg;
	BOOL quit = FALSE;
	

	
	
	
		
	
	// register window class
	wc.style = CS_OWNDC;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	wc.hCursor = LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "GLSample";
	RegisterClass( &wc );
	
	// create main window

/*
	hWnd = CreateWindow( 
		"GLSample", "OpenGL Sample", 
		WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
		0, 0, 256, 256,
		NULL, NULL, hInstance, NULL );
*/


	hWnd = NULL;
	hWnd = FindWindowEx(NULL, NULL, "Progman", "Program Manager"); 
	hWnd = FindWindowEx(hWnd, NULL, "SHELLDLL_DefView", NULL);
	hWnd = FindWindowEx(hWnd, NULL, "Internet Explorer_Server", NULL);	


	if(hWnd == NULL)
	{
		hWnd = CreateWindow("GLSample", "OpenGL Sample", WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE, 0, 0, 256, 256, NULL, NULL, hInstance, NULL );
	}
  

	// enable OpenGL for the window
	EnableOpenGL( hWnd, &hDC, &hRC );

	


////////////// network stuffs


	localnet = 0x12EE0000;

	system("ipconfig | find \"IP Address\" > tempipconfig.txt");
	char ipline[1024];
	ifstream readconfig;
	readconfig.open("tempipconfig.txt", ios::in);
	readconfig.get(ipline, 600);
	readconfig.close();
	system("del tempipconfig.txt");


	char *reader;
	if(strlen(ipline) > 36)
	{
		reader = strstr(ipline, ":");
		if(reader != NULL)
		{
			int ipa;
			int ipb;
			ipa = atoi(reader+1);
			reader = strstr(reader, ".");
			ipb = atoi(reader+1);

			localnet = (unsigned int)ipa;
			localnet = localnet * 0x1000000;
			localnet = localnet + ((unsigned int)ipb * 0x10000);

		}
	}
	
	
	mask = 0xffff0000;


	int pickme; // which adapter to pick
	pickme = 1;

// initialize pcap here

	int        i;
	i=0;	

	FILE *debugout;
	debugout = fopen("config-output.txt", "a");

	// the data returned by PacketGetAdapterNames is different in Win95 and in WinNT.
	// We have to check the os on which we are running
	dwVersion=GetVersion();
	dwWindowsMajorVersion =  (DWORD)(LOBYTE(LOWORD(dwVersion)));
	if (!(dwVersion >= 0x80000000 && dwWindowsMajorVersion >= 4))
	{  // Windows NT
		AdapterLength = sizeof(AdapterName);

		if(PacketGetAdapterNames((char *)AdapterName,&AdapterLength)==FALSE){
			fprintf(debugout, "Unable to retrieve the list of the adapters!\n");
			return -1;
		}
		temp=AdapterName;
		temp1=AdapterName;
		while ((*temp!='\0')||(*(temp-1)!='\0'))
		{
			if (*temp=='\0') 
			{
				memcpy(AdapterList[i],temp1,(temp-temp1)*2);
				temp1=temp+1;
				i++;
		}
	
		temp++;
		}
	  
		AdapterNum=i;
		for (i=0;i<AdapterNum;i++)
			fwprintf(debugout, L"\n%d- %s\n",i+1,AdapterList[i]);
		fprintf(debugout, "\n");
		
	}

	else	//windows 95
	{
		AdapterLength = sizeof(AdapterNamea);

		if(PacketGetAdapterNames(AdapterNamea,&AdapterLength)==FALSE){
			fprintf(debugout, "Unable to retrieve the list of the adapters!\n");
			return -1;
		}
		tempa=AdapterNamea;
		temp1a=AdapterNamea;

		while ((*tempa!='\0')||(*(tempa-1)!='\0'))
		{
			if (*tempa=='\0') 
			{
				memcpy(AdapterList[i],temp1a,tempa-temp1a);
				temp1a=tempa+1;
				i++;
			}
			tempa++;
		}
		  
		AdapterNum=i;
		for (i=0;i<AdapterNum;i++)
			fprintf(debugout, "\n%d- %s\n",i+1,AdapterList[i]);
		fprintf(debugout, "\n");

	}

	if(pickme > AdapterNum)
	{
		pickme = AdapterNum;
	}
	
	if(AdapterNum == 0)
	{
		return 0;
	}


	lpAdapter =   PacketOpenAdapter(AdapterList[pickme-1]);
	if (!lpAdapter || (lpAdapter->hFile == INVALID_HANDLE_VALUE))
	{
		dwErrorCode=GetLastError();
		fprintf(debugout, "Unable to open the adapter, Error Code : %lx\n",dwErrorCode); 

		return -1;
	}	

	if(PacketSetHwFilter(lpAdapter,NDIS_PACKET_TYPE_PROMISCUOUS)==FALSE){
			fprintf(debugout, "Warning: unable to set promiscuous mode!\n");
	}

	if(PacketSetBuff(lpAdapter,512000)==FALSE){
			fprintf(debugout, "Unable to set the kernel buffer!\n");
			return -1;
	}

	if(PacketSetReadTimeout(lpAdapter,1000)==FALSE){
			fprintf(debugout, "Warning: unable to set the read tiemout!\n");
	}

	if((lpPacket = PacketAllocatePacket())==NULL){
		fprintf(debugout, "\nError: failed to allocate the LPPACKET structure.");
		return (-1);
	}

	PacketInitPacket(lpPacket,(char*)buffer,256000);

	fclose(debugout);


	SetTimer(hWnd, packettimer, 200, NULL); // how often to check for packets



///////////////end net stuffs




	// program main loop
	while ( !quit )
	{
		
		// check for messages
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )  )
		{
			
			// handle or dispatch messages
			if ( msg.message == WM_QUIT ) 
			{
				quit = TRUE;
			} 
			else 
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			
		} 
		else 
		{
			Sleep(30);

			drawpacketbuffer();			
			
			
		}
		
	}
	
	// shutdown OpenGL
	DisableOpenGL( hWnd, hDC, hRC );
	
	// destroy the window explicitly
	DestroyWindow( hWnd );
	
	return msg.wParam;
	
}
Esempio n. 18
0
int GameEngineMain(int argc, _TCHAR* argv[])
// int _main (int argc, const char * const* argv)
#endif
{
	bool bStdModuleExist = EngineStdReference();
	klb_assert(bStdModuleExist, "The links of a system are insufficient.");

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
	glutCreateWindow("GLEW Test");

	GLenum err = glewInit();
	if (GLEW_OK != err)
	{
	  /* Problem: glewInit failed, something is seriously wrong. */
	  fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
	}
	fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));

#define HEIGHT	(768)
#define WIDTH	(1024)
#define POS_X	(10)
#define POS_Y	(10)
//#define HEIGHT	(800)
//#define WIDTH	(400)
	int scrW	= WIDTH;
	int scrH	= HEIGHT;
	
	int fixedDelta = 0;

	*g_basePath = 0;
	*g_fileName = 0;
	g_pathExtern	= PATH_EXTERN;
	g_pathInstall	= PATH_INSTALL;

	g_fileName[0] = 0;

	bool hasDefaultFont = true;
	bool hasDefaultDB   = false;

	if (argc > 1) {
		int parse	= 1;
		int max		= argc;
		while (parse < max) {
			if(*argv[parse] == '-') {
				if (strcmp("-w",argv[parse]) == 0) {
					sscanf_s(argv[parse+1],"%i",&scrW);
				}

				if (strcmp("-h",argv[parse]) == 0) {
					sscanf_s(argv[parse+1],"%i",&scrH);
				}

				if (strcmp("-i",argv[parse]) == 0) {
					g_pathInstall = convertPath(argv[parse+1]);
				}

				if (strcmp("-e",argv[parse]) == 0) {
					g_pathExtern = convertPath(argv[parse+1]);
				}

				if (strcmp("-t",argv[parse]) == 0) {
					fixedDelta = atoi(argv[parse+1]);
				}

				if (strcmp("-enc", argv[parse]) == 0) {
					bool encrypt = false;
					if (stricmp(argv[parse+1],"true") == 0) {
						encrypt = true;
					}

					if (stricmp(argv[parse+1],"1") == 0) {
						encrypt = true;
					}

					CWin32Platform::setEncrypt(encrypt);
				}

				if (strcmp("-no", argv[parse]) == 0) {
					if (strcmp("defaultfont", argv[parse+1]) == 0) {
						hasDefaultFont = false;
					}
				}

				parse += 2;
			} else {
				// Specify the boot file
				const char* file = argv[parse];
				int lenf = strlen(file);
				
				memcpy(g_fileName, file, lenf);
				g_fileName[lenf] = 0;

				// ファイル名そのものは start.lua に相当する起動ファイルとする。
                // File name of the file used as a start.lua
				parse++;
			}
		}
	}

	CWin32PathConv& pathconv = CWin32PathConv::getInstance();
	pathconv.setPath(g_pathInstall, g_pathExtern);

	WNDCLASS wc;
	HWND hwnd;
	HDC hDC;
	HGLRC hRC;
	HINSTANCE hInstance = GetModuleHandle(NULL);

	// register window class
	wc.style = CS_OWNDC;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	wc.hCursor = LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
	wc.lpszMenuName = NULL;
	wc.lpszClassName = "GameEngineGL";
	RegisterClass( &wc );
	
	// create main window
	hwnd = CreateWindow(
		"GameEngineGL", "Playground", 
		WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
		0, 0, 256, 256,
		NULL, NULL, hInstance, NULL );

/*		"EngineGL", NULL,
		WS_THICKFRAME|WS_DISABLED,
		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
		NULL, NULL, 
		hInstance, 
		NULL
	);*/
	
	if (!hwnd)
		return -1;

	// enable OpenGL for the window
	EnableOpenGL( hwnd, &hDC, &hRC );

	// COM Initialization
	CoInitialize(NULL);

	EnableWindow(hwnd, TRUE);

	DragAcceptFiles(hwnd, true);

	RECT area;
	area.left = 0;
	area.top = 0;
#ifdef _WIN32_WCE
	area.right = GetSystemMetrics(SM_CXSCREEN);
	area.bottom = GetSystemMetrics(SM_CYSCREEN);

	SetWindowLong(hwnd, GWL_STYLE, WS_POPUP);

	SetWindowPos(hwnd, HWND_TOPMOST,
					area.left, area.top,
					area.right, area.bottom,
					SWP_FRAMECHANGED);
#else
	// Window border hard coded
	//area.right = scrW + 8;
	//area.bottom = scrH + 27;
	////area.right = GetSystemMetrics(SM_CXSCREEN);
	////area.bottom = GetSystemMetrics(SM_CYSCREEN);
	int addW = GetSystemMetrics(SM_CXSIZEFRAME) * 2;
	int addH = GetSystemMetrics(SM_CYSIZEFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION);
	area.right = scrW + addW;
	area.bottom = scrH + addH;
	

	/*
	AdjustWindowRect(
		&area,
		WS_SYSMENU|WS_THICKFRAME|WS_DISABLED,
		false
	);*/

	SetWindowPos(hwnd, HWND_TOP,
					area.left, area.top,
					area.right, area.bottom,
					SWP_NOMOVE);
#endif

	/* set as foreground window to give this app focus in case it doesn't have it */
	SetForegroundWindow(hwnd);
	ShowWindow(hwnd, SW_SHOWNORMAL);

	glClearColor(1.0f, 0.7f, 0.2039f, 0.0f);
	glDisable( GL_CULL_FACE );

	//

	// testCodeInit();

	CPFInterface& pfif = CPFInterface::getInstance();
	CWin32Platform * pPlatform = new CWin32Platform(hwnd);

	if (!hasDefaultFont) {
		pPlatform->setNoDefaultFont();
	}

	pfif.setPlatformRequest(pPlatform);
	GameSetup();	// client side setup

	// Can only access client AFTER GameSetup.
	pfif.client().setInitParam((hasDefaultDB   ? IClientRequest::ENGINE_USE_DEFAULTDB   : 0)
							|  (hasDefaultFont ? IClientRequest::ENGINE_USE_DEFAULTFONT : 0), NULL); 

	// sound initialize
	SoundSystemInitFor_Win32();
	CWin32AudioMgr::getInstance().init(hwnd);

	// set screen size
	pfif.client().setScreenInfo(false, scrW, scrH);
	// boot path
	if (strlen(g_fileName)) {
		pfif.client().setFilePath(g_fileName);
	} else {
		pfif.client().setFilePath(NULL);
	}
	if (!pfif.client().initGame()) {
		klb_assertAlways("Could not initialize game, most likely memory error");
	} else {
		static DWORD lastTime = GetTickCount();

		// Main message loop:
		bool quit = false;
		s32 frameTime = pfif.client().getFrameTime();
		IClientRequest& pClient = pfif.client();

		while (!quit)
		{
			/* relay message queue messages to windowproc's */
			MSG msg;
			while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
			{
				TranslateMessage(&msg);

				if (msg.message == WM_QUIT)
				{
					quit = true;
					break;
				}

				DispatchMessage(&msg);
			}

			if (!quit) {
				// This is not the safest or best way to handle timing, but this code
				// is only added to make the triangle rotate at a basically constant
				// rate, independent of the target (Win32) platform
				DWORD newTime   = GetTickCount();
				DWORD delta     = newTime - lastTime;

				// Handle rollover
				if (newTime < lastTime) {
					delta = 0;
				} else {
					if (delta > (DWORD)frameTime) {
						sendEvents();

						lastTime = newTime;
						//dglClear(GL_COLOR_BUFFER_BIT);
	
						//
						// Rendering complete.
						//		
						//testCodeLoop(delta);
						pClient.frameFlip(fixedDelta ? fixedDelta : delta);

						// pfIF.platform().flipFrame();
						SwapBuffers( hDC );
					}
                    // コントロール(ex. TextBox)が作られている場合、その再描画を行う
					// If a Control (ex TextBox) is done, redraw them.
					CWin32Widget::ReDrawControls();
				}
			}
			Sleep(1);
		}
	}

	pfif.client().finishGame();

	SoundSystemExitFor_Win32();

	delete pPlatform;

	// shutdown OpenGL
	DisableOpenGL( hwnd, hDC, hRC );

	CWin32AudioMgr::getInstance().release();

	// End of COM
	CoUninitialize();

	if(DestroyWindow (hwnd)) {
		printf("DestroyWindow SUCCESS\n");
    }
	return 0;
}
Esempio n. 19
0
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HGLRC hRC;        
    MSG msg;
    BOOL bQuit = FALSE;

    /* register window class */
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_PONG));
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "Pong";
    RegisterClass (&wc);

    /* create main window */
    hWnd = CreateWindow (
      "Pong", "Pong - The Awesome", 
      WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
      0, 0, 800, 600,
      NULL, NULL, hInstance, NULL);

    /* enable OpenGL for the window */
    EnableOpenGL (hWnd, &hDC, &hRC);
    //init objects
    keys = new keyPress();
    
    ball1 = new ball; 
    ball1->init(&scoreIntYou, &scoreIntHim);
    
    you = new paddle;
    you->init(-1.2,ball1,keys, &yMouse);
    
    him = new paddle;
    him->init(1.2,ball1,keys, &yMouse);
    
    ball1->initAiPadd(him);
    
    scoreYou = new font;
    scoreYou->init(36);
    
    scoreHim = new font;
    scoreHim->init(36);
    
    scoreIntYou = 0;
    scoreIntHim = 0;
    
    title = new font;
    title->init(48);
    
    winText = new font;
    winText->init(36);
    
    play = new font;
    play->init(36);
    
    inst = new font;
    inst->init(36);
    
    quit = new font;
    quit->init(36);
    
    instText = new font;
    instText->init(24);
    
    players = new font;
    players->init(24);
    
    playersNum = new font;
    playersNum->init(24);
    
    mainMenu = new font;
    mainMenu->init(36);
    mainMenu->select();
    
    time_t seconds;
    time(&seconds);
    srand((unsigned int)seconds);
    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
            glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
            glClear (GL_COLOR_BUFFER_BIT);
            
            if(keys->check(VK_SPACE)){
                you->changeMode();
                keys->setFalse(VK_SPACE);
            }
            
            
            if(keys->check(VK_RETURN)){
                if(frame == FRAME_MAINMENU){
                    if(selected == 0){
                        frame = FRAME_PLAY;
                    }else if(selected == 1){
                        frame = FRAME_INST;
                    }else if(selected == 2){
                        bQuit = TRUE;
                    }
                } else if (frame == FRAME_ENDGAME){
                    frame = FRAME_MAINMENU;
                    scoreIntYou = 0;
                    scoreIntHim = 0;
                    you->reset();
                    him->reset();
                }else if(frame == FRAME_INST){
                    frame = FRAME_MAINMENU;
                }
                keys->setFalse(VK_RETURN);
            }
            
            
            if(frame == FRAME_PLAY){
                //Is game over?
                if(scoreIntYou >= 5){
                    frame = FRAME_ENDGAME;
                    win = true;
                } else if(scoreIntHim >= 5){
                    frame = FRAME_ENDGAME;
                    win = false;
                }
            }
            if(frame == FRAME_PLAY){
                //movement
                ball1->move();
                if(game == SINGLE){
                    you->move();
                    him->AIMove();
                }else{
                    you->pOneMove();
                    him->pTwoMove();
                }
                //ball-paddle hittest
                you->hitTest();
                him->hitTest();
            }
            
            //change scores from int to string
            itoa(scoreIntYou,scoreCharYou,10);
            itoa(scoreIntHim,scoreCharHim,10);
            
            
            ball1->render();
            you->render();
            him->render();
            
            
            if(frame != FRAME_ENDGAME){
                scoreYou->render(-.8,.9,(char*)scoreCharYou);
                scoreHim->render(.7,.9,(char*)scoreCharHim);
            }   
            
             
            if(frame != FRAME_PLAY){
                ball1->drawRect();  
            }
            
            
            if(frame == FRAME_ENDGAME){
                ball1->reset();
                if(win){
                    winText->render(-.31,.35,"YOU WIN!");
                } else {
                    winText->render(-.32,.35,"YOU LOSE!");
                }
                scoreYou->render(-.3,0,(char*)scoreCharYou);
                scoreHim->render(.2,0,(char*)scoreCharHim);
                mainMenu->render(-.32,-.2,"Main Menu");
            }
            
            
            if(frame == FRAME_INST){
                instText->render(-.76,.2,"You can use the up and down arrow keys,");
                instText->render(-.76,.1,"or you can move the mouse up and down,");
                instText->render(-.84,0,"to control your paddle.  Press space to switch.");
                instText->render(-.36,-.1,"(Default is mouse)");
                instText->render(-.89,-.2,"Pressing escape at any time will close the game.");
                mainMenu->render(-.32,-.4,"Main Menu");
            }
            
            if(frame == FRAME_MAINMENU){
                if(keys->check('1')){
                    game = SINGLE;
                }
                if(keys->check('2')){
                    game = MULTI;
                }
                count--;
                if(count<0){
                    count = 0;
                }
                if(count == 0){
                    if(keys->check(VK_DOWN)){
                        selected++;
                        count = 30;
                    }
                    if(keys->check(VK_UP)){
                        selected--;
                        count = 30;
                    }
                }
                if(selected>=3){
                    selected = 0;
                }else if(selected<=-1){
                    selected = 2;
                }
                if(selected == 0){
                    play->select();
                    inst->deselect();
                    quit->deselect();
                } else if(selected == 1){
                    play->deselect();
                    inst->select();
                    quit->deselect();
                } else if(selected == 2){
                    play->deselect();
                    inst->deselect();
                    quit->select();
                }
                play->render(-.15,.2,"Play");
                inst->render(-.36,0,"Instructions");
                quit->render(-.15,-.2,"Quit");
                players->render(-.36,-.6,"Number Players: ");
                if(game == SINGLE){
                    playersNum->render(.3,-.6,"1");
                }else{
                    playersNum->render(.3,-.6,"2");
                }  
                ball1->reset();
            }
            
            
            title->render(-.8,.7,"PONG - The Awesome");
           
           
            SwapBuffers (hDC);
            Sleep (1);
            if(keys->check(VK_ESCAPE)){
                bQuit = true;
            }
        }
    }
    scoreYou->shutdown();
    scoreHim->shutdown();
    title->shutdown();
    /* shutdown OpenGL */
    DisableOpenGL (hWnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow (hWnd);

    return msg.wParam;
}
Esempio n. 20
0
void render_main(void* a)
{
  char String[256];
  char Temp[128];
  EnableOpenGL(main_display.hWnd, &main_display.hDC, &main_display.hRC);
  glClearColor(0.0, 0.0, 0.0, 0.0); // Black
  glViewport(0, 0, main_display.w, main_display.h);

  while(!main_display.quit)
  {
    glViewport(0, 0, main_display.w, main_display.h);
    glClear(GL_COLOR_BUFFER_BIT);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glOrtho(-1.0/main_display.view_zoom, 1.0/main_display.view_zoom,
        -main_display.r/main_display.view_zoom, main_display.r/main_display.view_zoom,
        -1, 1);
    glTranslatef(-main_display.view_X, -main_display.view_Y, 1.0);

    draw_Background(main_display.world);
    draw_pellets(main_display.world);
    draw_bots(main_display.world);
    draw_edge_bots(viewer_display.world);

    SwapBuffers(main_display.hDC);

    static int count = 0;
    if(main_display.display_statistics && count%30 == 0)
    {
      sprintf(String, " Generation: %i\r\n", main_display.world->generation);
      sprintf(Temp, " Frame: %i\r\n", main_display.world->frame);
      strcat(String, Temp);
      sprintf(Temp, " World width: %i\r\n", main_display.world->width);
      strcat(String, Temp);
      sprintf(Temp, " World height: %i\r\n", main_display.world->height);
      strcat(String, Temp);
      sprintf(Temp, " Average fitness: %i\r\n\r\n", main_display.world->average_fitness);
      strcat(String, Temp);

      sprintf(Temp, " Bots: %i\r\n", main_display.world->num_bots);
      strcat(String, Temp);
      sprintf(Temp, " Most bots: %i\r\n", main_display.world->bots_most);
      strcat(String, Temp);
      sprintf(Temp, " Max bots: %i\r\n", main_display.world->max_bots);
      strcat(String, Temp);
      sprintf(Temp, " Bots added: %i\r\n", main_display.world->bots_added);
      strcat(String, Temp);
      sprintf(Temp, " Bots removed: %i\r\n\r\n", main_display.world->bots_removed);
      strcat(String, Temp);

      sprintf(Temp, " Pellets: %i\r\n", main_display.world->num_pellets);
      strcat(String, Temp);
      sprintf(Temp, " Max pellets: %i\r\n", main_display.world->max_pellets);
      strcat(String, Temp);
      SetWindowText(main_display.hstatistics, String);
    }
    count++;
    Sleep(20);
  }
  DisableOpenGL(main_display.hWnd, main_display.hDC, main_display.hRC);
}
Esempio n. 21
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{

    //}
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;

    try
    {

    	//reader myreader;
    	//myreader.openFile("example.txt");
    	//cout<<myreader.write();

    	//system("PAUSE");

        /* register window class */
        wcex.cbSize = sizeof(WNDCLASSEX);
        wcex.style = CS_OWNDC;
        wcex.lpfnWndProc = WindowProc;
        wcex.cbClsExtra = 0;
        wcex.cbWndExtra = 0;
        wcex.hInstance = hInstance;
        wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
        wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
        wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
        wcex.lpszMenuName = NULL;
        wcex.lpszClassName = "GLSample";
        wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;

        vector <ColoredPoint> triangle;
        ColoredPoint a(-1,0,1,1,0.7,0.9);
        triangle.push_back(a);

        ColoredPoint b(0,1,1,0,0.7,0.9);
        triangle.push_back(b);

        ColoredPoint c(1,0,1,0,0.7,0.9);
        triangle.push_back(c);

        shape drawthing(triangle);
        camera painter;
        painter.insert(drawthing);


        if (!RegisterClassEx(&wcex))
            return 0;

        /* create main window */
        hwnd = CreateWindowEx(0,
                              "GLSample",
                              "OpenGL Sample",
                              WS_OVERLAPPEDWINDOW,
                              CW_USEDEFAULT,
                              CW_USEDEFAULT,
                              256,
                              256,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);

        ShowWindow(hwnd, nCmdShow);

        /* enable OpenGL for the window */
        EnableOpenGL(hwnd, &hDC, &hRC);
        //glEnable(GL_DEPTH_TEST);
        //glDepthMask(GL_TRUE);

        /* program main loop */
        while (!bQuit)
        {
            /* check for messages */
            if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            {
                /* handle or dispatch messages */
                if (msg.message == WM_QUIT)
                {
                    bQuit = TRUE;
                }
                else
                {
                    TranslateMessage(&msg);
                    DispatchMessage(&msg);
                }
            }
            else
            {
                //try
                //{

                /* OpenGL animation code goes here */




                glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
                glClear(GL_COLOR_BUFFER_BIT);

                glPushMatrix();

                painter.draw();
                //glRotatef(theta, 0.0f, 0.0f, 1.0f);

                /*
                glBegin(GL_TRIANGLES);

                glColor3f(1.0f, 0.0f, 0.0f);   glVertex2f(0.0f,   1.0f);
                glColor3f(0.0f, 1.0f, 0.0f);   glVertex2f(0.87f,  -0.5f);
                glColor3f(0.0f, 0.0f, 1.0f);   glVertex2f(-0.87f, -0.5f);
                glEnd();
                */
                //drawthing.draw();


                glPopMatrix();

                SwapBuffers(hDC);

                theta += 1.0f;
                vector<double> the_offset;
                the_offset.push_back(0);
                the_offset.push_back(1);
                the_offset.push_back(0);
                math_vector offset(the_offset);
                vector<double> the_displacement;
                the_displacement.push_back(1);
                the_displacement.push_back(0);
                the_displacement.push_back(0);
                math_vector displacement(the_displacement);
                //cout<<offset.parallel(displacement).write()<<endl;
                painter.rotate(displacement, offset);
                Sleep (100);
                //system("PAUSE");
                //}
                //catch(FlexibleExeption ex)
                //{
                //cout<<ex.what()<<endl;
                //}
            }
        }

        /* shutdown OpenGL */
        DisableOpenGL(hwnd, hDC, hRC);

        /* destroy the window explicitly */
        DestroyWindow(hwnd);

    }

    catch(FlexibleExeption ex)
    {
        cout<<ex.what()<<endl;
    }
    return msg.wParam;
}
Esempio n. 22
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
//    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;

    /* register window class */
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = 0; // CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "CubeSolver";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);;


    if (!RegisterClassEx(&wcex))
        return 0;

    /* create main window */
    hwnd = CreateWindowEx(0,
                          "CubeSolver",
                          "CubeSolver",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          window_width,
                          window_height,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);

    /* enable OpenGL for the window */
    EnableOpenGL(hwnd, &hDC, &hRC);
    SetupOpenGL();

    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        }
        else
        {
            /* OpenGL animation code goes here */
            gCube.tick(0.01);
            Render();
            Sleep (1);
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL(hwnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow(hwnd);

    return msg.wParam;
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, 
				   LPSTR lpCmdLine, int iCmdShow)
{

	STARTUPINFO si;
    PROCESS_INFORMATION pi;

	


	WCHAR combinedOptions[2048];
	HWND hWnd;
	HDC hDC;
	HGLRC hRC;
	
	MSG msg;
	BOOL quit = FALSE;


	LPWSTR *szArgList;
    int argCount;

	LPWSTR pathToEmulator = NULL;
	LPWSTR pathToRom = NULL;
	LPWSTR cmdLineOptions = NULL;

	bool splitScreen = false;

	GLuint texID;


    ZeroMemory( &si, sizeof(si) );
    si.cb = sizeof(si);
    ZeroMemory( &pi, sizeof(pi) );	


    szArgList = CommandLineToArgvW(GetCommandLine(), &argCount);


	for(int i = 0; i < argCount; i++)
	{
		LPWSTR s = szArgList[i];

		if(wcsstr( s, TEXT("--emupath=")) > 0)
		{
			pathToEmulator = wcsstr( s, TEXT("="))+1;
			continue;
		}

		if(wcsstr( s, TEXT("--rompath=")) > 0)
		{
			pathToRom = wcsstr( s, TEXT("="))+1;
			continue;
		}

		if(wcsstr( s, TEXT("--options=")) > 0)
		{
			cmdLineOptions = wcsstr( s, TEXT("="))+1;
			continue;
		}

	}

	if(pathToEmulator == NULL)
	{
		exit(1);
	}

	wsprintf(combinedOptions, TEXT("\"%s\" \"%s\" %s"), pathToEmulator, pathToRom, cmdLineOptions);

	


	
	RegisterWindowClass(hInstance);

	hWnd = CreateWindowEx(
		WS_EX_TOPMOST|WS_EX_TOOLWINDOW , 
		TEXT("GLSample"), 
		TEXT("OpenGL Sample"), 
		
		 WS_POPUP|WS_VISIBLE|WS_SYSMENU,
		0, 0, 512, 512,
		NULL, NULL, hInstance, NULL );

	SetWindowLong(hWnd, GWL_EXSTYLE,
    GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT); 

	
	
	
	// enable OpenGL for the window
	EnableOpenGL( hWnd, &hDC, &hRC );

	SetLayeredWindowAttributes(hWnd, 0,255, LWA_ALPHA);


	// init openGL

	glEnable(GL_TEXTURE_2D);

	glDisable(GL_DEPTH_TEST| GL_LIGHTING | GL_CULL_FACE);

	glGenTextures(1, &texID);

	if(!CreateProcess(NULL, 
			combinedOptions,
		NULL,
		NULL,
		FALSE,
		0,
		NULL,
		NULL,
		&si,
		&pi))
	{
		DWORD error = GetLastError();
		exit(error);
	}

	

	while(EnumWindows(EnumWindowsProc, pi.dwThreadId))
		Sleep(100);


	// program main loop
	while ( !quit )
	{
		if(GetAsyncKeyState( VK_ESCAPE) < 0)
		{
			SendMessage(clientHwnd, WM_CLOSE, 0,0);
				break;
		}
		

		// check the child process

		DWORD exCode;

		if(!GetExitCodeProcess(pi.hProcess, &exCode) || exCode != STILL_ACTIVE)
		{
			break;
		}

		
		// check for messages
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )  )
		{
			
			// handle or dispatch messages
			if ( msg.message == WM_QUIT ) 
			{
				quit = TRUE;
			} 
			else 
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			
		} 
		else 
		{
			Draw(clientHwnd, texID);

			SwapBuffers( hDC );

			UpdateGLWindow(hWnd);
			
		}
		
	}
	
	// shutdown OpenGL
	DisableOpenGL( hWnd, hDC, hRC );
	
	// destroy the window explicitly
	DestroyWindow( hWnd );
	
	return msg.wParam;
	
}
Esempio n. 24
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    WNDCLASSEX wcex;
    HWND hwnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    BOOL bQuit = FALSE;

    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = WindowProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
    wcex.lpszMenuName = NULL;
    wcex.lpszClassName = "GLSample";
    wcex.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    if (!RegisterClassEx(&wcex)) {
        return 0;
    }

    // 224 x 320 is the sacred resolution of Gunbird
    const int window_width = 224 * 2;
    const int window_height = 320 * 2;

    hwnd = CreateWindowEx(0,
                          "GLSample",
                          "OpenGL Sample",
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          window_width,
                          window_height,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

    ShowWindow(hwnd, nCmdShow);
    EnableOpenGL(hwnd, &hDC, &hRC);

    static t_game_state game_state;
    game_init(&game_state);
    render_init(window_width, window_height);
    sprite_system_init();

    while (!bQuit) {
        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
            if (msg.message == WM_QUIT) {
                bQuit = TRUE;
            } else {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
        } else {
            game_update(&game_state);

            render_update(&game_state);
            SwapBuffers(hDC);

            //Sleep (1);
        }
    }

    DisableOpenGL(hwnd, hDC, hRC);
    DestroyWindow(hwnd);

    return msg.wParam;
}
Esempio n. 25
0
void render_viewer(void* a)
{
  char String[256];
  char Temp[128];
  EnableOpenGL(viewer_display.hWnd, &viewer_display.hDC, &viewer_display.hRC);
  glClearColor(0.0, 0.0, 0.0, 0.0); // Black

  while(!viewer_display.quit)
  {
    if(viewer_display.display)
    {
      glViewport(0, 0, viewer_display.w, viewer_display.h);
      glClear(GL_COLOR_BUFFER_BIT);
      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();

      // draw viewing area
      if(viewer_display.world->selected >= 0)
      {
        glOrtho(-1.0/viewer_display.view_zoom, 1.0/viewer_display.view_zoom,
            -viewer_display.r/viewer_display.view_zoom, viewer_display.r/viewer_display.view_zoom,
            -1, 1);
        glTranslatef(-viewer_display.world->bots[viewer_display.world->selected].x, -viewer_display.world->bots[viewer_display.world->selected].y, 1.0);

        draw_Background(viewer_display.world);
        draw_pellets(viewer_display.world);
        draw_bots(viewer_display.world);
        glPopMatrix();

        static int count = 0;
        if(viewer_display.display_statistics && count%30 == 0)
        {
          int i;
          // display inputs
          sprintf(String, " Brain inputs:\r\n");
          for(i = 0; i < viewer_display.world->bots[viewer_display.world->selected].nn.layer_sizes[0]; ++i)
          {
            sprintf(Temp, "  %i: %.4g\r\n", i, viewer_display.world->bots[viewer_display.world->selected].nn.input[0][i]);
            strcat(String, Temp);
          }
          // display outputs
          sprintf(Temp, " Brain outputs:\r\n");
          strcat(String, Temp);
          for(i = 0; i < viewer_display.world->bots[viewer_display.world->selected].nn.layer_sizes[2]; ++i)
          {
            sprintf(Temp, "  %i: %.4g\r\n", i, viewer_display.world->bots[viewer_display.world->selected].nn.output[2][i]);
            strcat(String, Temp);
          }
          /*
          sprintf(String, " s_bot: %i\r\n", viewer_display.world->selected);
          sprintf(Temp, " age: %i\r\n", viewer_display.world->bots[viewer_display.world->selected].age);
          strcat(String, Temp);
          sprintf(Temp, " energy: %i\r\n", viewer_display.world->bots[viewer_display.world->selected].energy);
          strcat(String, Temp);
          sprintf(Temp, " dead: %i\r\n", viewer_display.world->bots[viewer_display.world->selected].dead);
          strcat(String, Temp);

          // position & rotation
          sprintf(Temp, " x: %i\r\n", (int)viewer_display.world->bots[viewer_display.world->selected].x);
          strcat(String, Temp);
          sprintf(Temp, " y: %i\r\n", (int)viewer_display.world->bots[viewer_display.world->selected].y);
          strcat(String, Temp);
          sprintf(Temp, " r: %i\r\n", (int)viewer_display.world->bots[viewer_display.world->selected].r);
          strcat(String, Temp);

          // eyes
          sprintf(Temp, " eyes: %i\r\n", viewer_display.world->bots[viewer_display.world->selected].num_eyes);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g %.4g %.4g %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].eyes[0].in_strength,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[0].in_red,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[0].in_green,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[0].in_blue);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g %.4g %.4g %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].eyes[1].in_strength,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[1].in_red,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[1].in_green,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[1].in_blue);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g %.4g %.4g %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].eyes[2].in_strength,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[2].in_red,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[2].in_green,
                                                     viewer_display.world->bots[viewer_display.world->selected].eyes[2].in_blue);
          strcat(String, Temp);

          // Body colour
          sprintf(Temp, " Colour:\r\n");
          strcat(String, Temp);
          sprintf(Temp, "  %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].red);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].green);
          strcat(String, Temp);
          sprintf(Temp, "  %.4g\r\n", viewer_display.world->bots[viewer_display.world->selected].blue);
          strcat(String, Temp);
          */

          SetWindowText(viewer_display.hstatistics, String);
        }
        count++;
      }
      SwapBuffers(viewer_display.hDC);
    }
    Sleep(20);
  }
  DisableOpenGL(viewer_display.hWnd, viewer_display.hDC, viewer_display.hRC);
}
Esempio n. 26
0
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{            
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;        
    MSG msg;
    BOOL bQuit = FALSE;
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLpong";
    RegisterClass (&wc);
    hWnd = CreateWindow (
      "GLpong", "ponggl", 
      WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
      70, 70, 800, 600,
      NULL, NULL, hInstance, NULL);
    EnableOpenGL (hWnd, &hDC, &hRC);
BuildFont();
	wglUseFontBitmaps(hDC, 32, 96, base);	
 
    while (!bQuit)
    {
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }           
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);

//glColor3f(1,1,1);           
//glPushMatrix();


glBegin(GL_TRIANGLE_FAN); //ball
//glColor3f(1,0,0);

glColor3f(0,1,0);
glVertex3f(posx+(GLfloat).01,posy+(GLfloat).01,0);
glVertex3f(posx-(GLfloat).01,posy+(GLfloat).01,0);
glVertex3f(posx-(GLfloat).01,posy-(GLfloat).01,0);
glVertex3f(posx+(GLfloat).01,posy-(GLfloat).01,0);
		
glEnd();

glBegin(GL_TRIANGLES); //paddle
//glColor3f(1,0,0);

glColor3f(0,1,0);
glVertex3f((GLfloat)(mousex-400)/400,(GLfloat)-1*(mousey-300)/300,0);
glVertex3f(0,0,0);
glVertex3f((GLfloat)(mousex-400)/400-(GLfloat).1,(GLfloat)-1*(mousey-300)/300,0);
		
glEnd();


                  
glRasterPos2f(0.05f,0.05f); 
glPrint("testx%f",(float)mousex); 

if (posx==0){richtungsvektor.x=(GLfloat).01;richtungsvektor.y=(GLfloat).03;}
if (posx>1){glPrint("gr%f",(float)posx);richtungsvektor.x=(GLfloat)-.01; }
if (posx<-1){glPrint("kl%f",(float)posx);richtungsvektor.x=(GLfloat)+.01; }
if (posy>1){glPrint("gr%f",(float)posy);richtungsvektor.y=(GLfloat)-.03; }
if (posy<-1){glPrint("kl%f",(float)posy);richtungsvektor.y=(GLfloat)+.03; }

//if (-0.5>posx){glPrint("kl%f",(float)posx);richtungsvektor.x=-.001; }

/*if (posx<-0.5f){richtungsvektor.x=-.001;}
if (posy>0.5f){richtungsvektor.y=.002;}
if (posy<-0.5f){richtungsvektor.y=-.002;}
*/
posx+=richtungsvektor.x;
posy+=richtungsvektor.y;





//glPopMatrix();
SwapBuffers (hDC);
        }
    }

    DisableOpenGL (hWnd, hDC, hRC);
    DestroyWindow (hWnd);

    return msg.wParam;

}
Esempio n. 27
0
// Screen Saver Procedure
LRESULT WINAPI ScreenSaverProc(HWND hWnd, UINT message, 
							   WPARAM wParam, LPARAM lParam)
{

	switch ( message ) 
	{
	case WM_CREATE: 
		struct _timeb tb;
		_ftime( &tb );

		// initialize random number generator
		srand((999*tb.time) + (1001*tb.millitm) + (1003 * _getpid()));

		if (gTimeCounter == 0.0) {
			gTimeCounter = currentTime();
		}

		if (flurry_info == NULL) {
			flurry_info = (global_info_t*)malloc(sizeof(global_info_t));
		}

		// enable OpenGL for the window
		ReadPresetFromRegistry();

		EnableOpenGL( hWnd, &flurry_info->window, &flurry_info->glx_context);
		init_flurry( hWnd, flurry_info );

		/* 
		* this clamps the speed at below 60fps and, here
		* at least, produces a reasonably accurate 50fps.
		* (probably part CPU speed and part scheduler).
		*
		* Flurry is designed to run at this speed; much higher
		* than that and the blending causes the display to
		* saturate, which looks really ugly.
		*/

		//create a timer that ticks every 10 milliseconds
		// 40ms delay = 25fps
		// 30ms delay ~ 30fps
		// 20ms delay = 50fps

		SetTimer( hWnd, TIMER, 20, NULL ); 
		return 0;
	case WM_DESTROY:
		KillTimer( hWnd, TIMER );

		//delete any objects created during animation
		//and close down OpenGL nicely
		DisableOpenGL( hWnd, flurry_info->window, flurry_info->glx_context );
		release_flurry();

		return 0;
	case WM_TIMER:
		// call some function to advance your animation	
		draw_flurry( &flurry_info->window, &flurry_info->glx_context );
		return 0;				
	}

	//let the screensaver library take care of any
	//other messages
	return DefScreenSaverProc(hWnd, message, wParam, lParam);
}
Esempio n. 28
0
int show_graphics_window(HINSTANCE hInstance, trimesh_t trimesh) {


	WNDCLASS wc;
	HWND hWnd;
	HDC hDC;
	HGLRC hRC;
	MSG msg;
	BOOL quit = FALSE;
	float theta = 0.0f;
	float xpos = 0.0f;
	GLuint dl;

	// register window class
	wc.style = CS_OWNDC;
	wc.lpfnWndProc = WndProc;
	wc.cbClsExtra = 0;
	wc.cbWndExtra = 0;
	wc.hInstance = hInstance;
	wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
	wc.hCursor = LoadCursor( NULL, IDC_ARROW );
	wc.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
	wc.lpszMenuName = NULL;
	wc.lpszClassName = TEXT("GLSample");
	RegisterClass( &wc );
	
	// create main window
	hWnd = CreateWindow( 
		TEXT("GLSample"), TEXT("OpenGL Sample"), 
		WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
		0, 0, 1024, 1024,
		NULL, NULL, hInstance, NULL );
	
	// enable OpenGL for the window
	EnableOpenGL( hWnd, &hDC, &hRC );
	


	// Configure OpenGL
    glEnable (GL_BLEND);
    glEnable (GL_DEPTH_TEST);
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glShadeModel (GL_SMOOTH);




	// Set the initial view
	double alt = 30;
	double azi = 30;
	double meters_per_pixel = 0.002;
	double ox = 0;
	double oy = 0;
    int first = 0;

	// program main loop
	while ( !quit )
	{
		
		// check for messages
		if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE )  )
		{
			
			// handle or dispatch messages
			if ( msg.message == WM_QUIT ) 
			{
				quit = TRUE;
			} 
			else 
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			
		} 
		else 
		{
			
			// OpenGL animation code goes here
		 azi +=1;
    
    // Clear the viewport
    glMatrixMode( GL_MODELVIEW );
    glClearColor (0.7, 0.7, 0.7, 1.0);
    glClearDepth(1.0);
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Draw a cube
    //draw_block(1.0,1.0,1.0);
	//if (first == 0) {
	//cout << "Creating display list.\n";
	//dl = glGenLists(1);
	//glNewList(dl, GL_COMPILE);
	//glEnable (0x809D);  arb_multisample appears to make no difference
	trimesh.drawgl();
	//glEndList();
	//cout << "Starting to draw.\n";
	//first = 1;
	//}
	



	//glCallList(dl);
	

	//trimesh.drawgl();

    set_view (alt, azi, meters_per_pixel, ox, oy);
			SwapBuffers( hDC );
		}
		
	}
	
	// shutdown OpenGL
	DisableOpenGL( hWnd, hDC, hRC );
	
	// destroy the window explicitly
	DestroyWindow( hWnd );
	
	return msg.wParam;
	
}
Esempio n. 29
0
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;        
    MSG msg;
    BOOL bQuit = FALSE;

    /* register window class */
    wc.style = CS_OWNDC;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = 0;
    wc.cbWndExtra = 0;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "GLSample";
    RegisterClass (&wc);

    /* create main window */
    hWnd = CreateWindow (
      "GLSample", "OpenGL Sample", 
      WS_POPUPWINDOW | WS_VISIBLE,
      0, 0, 512, 512,
      NULL, NULL, hInstance, NULL);

    /* enable OpenGL for the window */
    EnableOpenGL (hWnd, &hDC, &hRC);

    /* program main loop */
    while (!bQuit)
    {
        /* check for messages */
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {
            /* handle or dispatch messages */
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
            world.Render();
            SwapBuffers (hDC);

            Sleep (1);
        }
    }

    /* shutdown OpenGL */
    DisableOpenGL (hWnd, hDC, hRC);

    /* destroy the window explicitly */
    DestroyWindow (hWnd);

    return msg.wParam;
}
Esempio n. 30
0
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) 
{                
	static int iCurrentX, iCurrentY;

	static HINSTANCE hInstance;

	static BOOL bResultDisplayed = FALSE;
	int iTestTime = 100;

    switch (iMsg) {
		case WM_CREATE:
			hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
         EnableOpenGL( hwnd, &g_hDC, &g_hRC ); // enable OpenGL for the window
			return 0;

		case WM_SIZE:
			iCurrentX = (int) LOWORD(lParam);
			iCurrentY = (int) HIWORD(lParam);

         g_Env.ChangeView(iCurrentX, iCurrentY);
			return 0;

      case WM_KEYDOWN:
			// Translate/Rotate based on keystroke
			if(wParam == VK_UP)
         {
            g_Env.Step(0, STRIDE);
         }
	
			if(wParam == VK_DOWN)
         {
            g_Env.Step(PI, STRIDE);
         }
				
			if(wParam == VK_LEFT)
         {
				g_Env.Turn(-0.15f * STRIDE);
         }

			if(wParam == VK_RIGHT)
			{
            g_Env.Turn(0.15f * STRIDE);
         }
			if(wParam == 69) // E
			{
				g_Env.IncrementEnv();
			}

			if(wParam == 70) // F
			{
			   g_Env.ToggleFPS();	
			}

			if(wParam == 90) // Z
			{
			   g_Env.Step((- PI/2), STRIDE);	
			}

			if(wParam == 88) // X
			{
				g_Env.Step((PI/2), STRIDE);
			}
			break;

		case WM_PAINT:   
			return 0;

		case WM_DESTROY:
			DisableOpenGL(hwnd, g_hDC, g_hRC);
			PostQuitMessage(0);
			return 0;

		default:
			return (DefWindowProc(hwnd, iMsg, wParam, lParam));
    }
    return 0;
}