Esempio n. 1
0
void Context::draw(HDC hdc) {
    // DEBUG
    // sm->bDebug = true;

    clock_t t = clock();
    float elapsed = static_cast<float>(t - timeT) / CLOCKS_PER_SEC;
    ++frameCount;
    if (elapsed > OVERLAY_FPS_INTERVAL) {
        OverlayMsg om;
        om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
        om.omh.uiType = OVERLAY_MSGTYPE_FPS;
        om.omh.iLength = sizeof(OverlayMsgFps);
        om.omf.fps = frameCount / elapsed;

        sendMessage(om);

        frameCount = 0;
        timeT = t;
    }

    unsigned int width, height;

    width = oGetDeviceCaps(hdc, HORZRES);
    height = oGetDeviceCaps(hdc, VERTRES);

    HWND hwnd = WindowFromDC(hdc);
    if (hwnd) {
        RECT r;
        if (GetClientRect(hwnd, &r)) {
            width = r.right - r.left;
            height = r.bottom - r.top;
        }
    }

    ods("OpenGL: DrawStart: Screen is %d x %d", width, height);

    checkMessage(width, height);

    oglViewport(0, 0, width, height);

    oglMatrixMode(GL_PROJECTION);
    oglLoadIdentity();
    oglOrtho(0, width, height, 0, -100.0, 100.0);

    oglMatrixMode(GL_MODELVIEW);

    oglBindTexture(GL_TEXTURE_2D, texture);
    oglPushMatrix();
    oglLoadIdentity();

    float w = static_cast<float>(uiWidth);
    float h = static_cast<float>(uiHeight);

    float left   = static_cast<float>(uiLeft);
    float top    = static_cast<float>(uiTop);
    float right  = static_cast<float>(uiRight);
    float bottom = static_cast<float>(uiBottom);

    float xm = (left) / w;
    float ym = (top) / h;
    float xmx = (right) / w;
    float ymx = (bottom) / h;

    oglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    oglBegin(GL_QUADS);

    oglTexCoord2f(xm, ymx);
    oglVertex2f(left, bottom);

    oglTexCoord2f(xm, ym);
    oglVertex2f(left, top);

    oglTexCoord2f(xmx, ym);
    oglVertex2f(right, top);

    oglTexCoord2f(xmx, ymx);
    oglVertex2f(right, bottom);
    oglEnd();

    oglPopMatrix();

}
Esempio n. 2
0
int main(void)
{
	int height=480,width=640;
	bool fullscreen=false,freeze=false,up=false,close=false;
	double camangle=0,camangle2=0,var_r=0;
	SDL_Init( SDL_INIT_VIDEO );
	SDL_WM_SetCaption( "Test 2 - Clipping, Graphics Made By Pawan Harish", NULL );
	int nFlags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_HWSURFACE | SDL_HWACCEL;
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,1);
	SDL_Surface *pSDLSurface = SDL_SetVideoMode(width,height,16, nFlags );

	oglViewport(width/4, height/4, width/2, height/2);
	glViewport(width/4, height/4, width/2, height/2);
		glMatrixMode( GL_PROJECTION );
			glLoadIdentity();
			gluOrtho2D ( width/4, width/2, width/4, width/2 );
			glMatrixMode( GL_MODELVIEW );
				glLoadIdentity();
	GLfloat x = (GLfloat)width / height;

	double cx=20,cy=150,cz=350;

	double r=sqrt(pow(cx,2)+pow(cz,2)+pow(cz,2));
	double th=double(atan(double(cy)/double(r))*180)/double(PI);
	double phi=double(atan(double(cx)/double(-cz))*180)/double(PI);
	oglMLoadIdentity();
	oglVLoadIdentity();
	oglPLoadIdentity();
	bool Done = false;
	SDL_Event Event;
	while(!Done)
	{
		SDL_PollEvent(&Event);
		switch(Event.type)
		{
			case SDL_QUIT:
				Done=true;
				break;
			case SDL_KEYDOWN:
				if(Event.key.keysym.sym==SDLK_ESCAPE)
					Done=true;
				else
					if(Event.key.keysym.sym=='s'&&!freeze)
					{
						if(!fullscreen)
						{
							pSDLSurface=SDL_SetVideoMode(width,height,16, nFlags|SDL_FULLSCREEN);
							fullscreen=true;
						}	
						else
						{
							pSDLSurface=SDL_SetVideoMode(width,height,16, nFlags);
							fullscreen=false;
						}
					}
					else
						if(Event.key.keysym.sym=='f')freeze=true;
						else
							if(Event.key.keysym.sym=='r')freeze=false;
				break;
		}
		if(!freeze)
		{
			oglClear(0,0,0);
			//My drawings
			camangle+=2;
			if(camangle>360)camangle=0;

			if(up)camangle2+=0.25;
			else
				camangle2-=0.25;
			if(camangle2>=30)up=false;
			if(camangle2<=-30)up=true;

			if(close)var_r+=2;
			else
				var_r-=2;
			if(var_r>=200)close=false;
			if(var_r<=-200)close=true;


			oglVLoadIdentity();
		//	oglOCamera(-x, x, -1.0, 1.0, 4.0, 2000.0); 
			//oglOCamera(-60, 130, -60, 130, -60, 130); 
			oglPCamera(45,x,60,130);
			oglVTranslate(0,0,-r+var_r);
			oglVRotate(-camangle2+th,1);
			oglVRotate(-camangle+phi,2);


			drawplane();
			oglMPushMatrix();
			oglMLoadIdentity();
			oglMTranslate(0,0,-50);
			DrawHome();
			oglMPopMatrix();

			oglShow(); //show everything made up till now in IGL.
			SDL_GL_SwapBuffers(); 
		}
	}
	SDL_Quit();
	return 0;
}