Exemple #1
0
void Simulator::DrawRobot(void)
{
    DrawGeometry(m_robotGeomChassis);
    DrawGeometry(m_robotGeomWheels[0]);
    DrawGeometry(m_robotGeomWheels[1]);
    DrawGeometry(m_robotGeomWheels[2]);
}
Exemple #2
0
void wxGISMapView::Flash(wxGISEnumFlashStyle eFlashStyle)
{
    wxCriticalSectionLocker locker(m_FlashCritSect);
    //wait drawings end to flash
    if (GetThread() && GetThread()->IsRunning())
    {
        GetThread()->Wait();
    }

    //draw geometries
    m_pGISDisplay->SetDrawCache(m_pGISDisplay->GetFlashCacheID());

    switch(eFlashStyle)
    {
    case enumGISMapFlashWaves:
        {
            double dfX(10), dfY(10);
            m_pGISDisplay->DC2WorldDist(&dfX, &dfY);
            double dfDist = (std::fabs(dfX) + std::fabs(dfY)) * 0.5;
            for(size_t i = 0; i < m_staFlashGeoms.size(); ++i)
            {
                if(m_staFlashGeoms[i].nPhase < 1)
                {
                    m_staFlashGeoms.erase(m_staFlashGeoms.begin() + i);
                    i--;
                    continue;
                }
                else if(m_staFlashGeoms[i].nPhase == 1)
                {
                    DrawGeometry(m_staFlashGeoms[i].Geometry, m_staFlashGeoms[i].stFillColour, m_staFlashGeoms[i].stLineColour);
                }
                else
                {
                    WXGISRGBA fill = {0,0,0,0};
                    double dfBuff = dfDist * m_staFlashGeoms[i].nPhase;
                    DrawGeometry(m_staFlashGeoms[i].Geometry.Buffer(dfBuff, 7), fill, m_staFlashGeoms[i].stLineColour, 0.5 * m_staFlashGeoms[i].nPhase);
                }
                m_staFlashGeoms[i].nPhase--;
            }
        }
        break;
    default:
    case enumGISMapFlashNewColor:
        for(size_t i = 0; i < m_staFlashGeoms.size(); ++i)
        {
            if(m_staFlashGeoms[i].nPhase < 1)
            {
                m_staFlashGeoms.erase(m_staFlashGeoms.begin() + i);
                i--;
                continue;
            }
            else
            {
                DrawGeometry(m_staFlashGeoms[i].Geometry, m_staFlashGeoms[i].stFillColour, m_staFlashGeoms[i].stLineColour);
                m_staFlashGeoms[i].nPhase--;
            }
        }
        break;
    };
}
Exemple #3
0
void CVXS_SimGLView::Draw(int Selected, bool ViewSection, int SectionLayer)
{
	if (!pSim->IsInitalized()) return;

	if (CurViewMode == RVM_NONE) return;
	else if (CurViewMode == RVM_VOXELS){ 
		switch (CurViewVox){
		case RVV_DISCRETE: DrawGeometry(Selected, ViewSection, SectionLayer); break; //section view only currently enabled in voxel view mode
		case RVV_DEFORMED: DrawVoxMesh(Selected); break;
		case RVV_SMOOTH: DrawSurfMesh(); break;
		}
	}
	else { //CurViewMode == RVT_BONDS
		vfloat VoxScale=0.2;
		if (ViewForce){
			DrawForce();
			DrawGeometry(Selected, ViewSection, SectionLayer, VoxScale);

		}
		else {
			if (CurViewVox == RVV_SMOOTH) VoxScale=0.1;
			DrawBonds();
			DrawGeometry(Selected, ViewSection, SectionLayer, VoxScale);
		}
		DrawStaticFric();
	}
	if (ViewAngles)	DrawAngles();
	if (pSim->IsFeatureEnabled(VXSFEAT_FLOOR)) DrawFloor(); //draw the floor if its in use
//	if (pEnv->IsFloorEnabled()) DrawFloor(); //draw the floor if its in use

	NeedStatsUpdate=true;
}
	extern void DrawGeometry(RenderingContext*ctx, SkPath*path, PerspexBrush*fill, PerspexBrush* stroke, bool useEvenOdd)
	{
		if (fill != nullptr)
			DrawGeometry(ctx, path, fill, useEvenOdd);
		if (stroke != nullptr)
			DrawGeometry(ctx, path, stroke, false);
	}
Exemple #5
0
void DrawContext::DrawDrawNode(DrawNode* draw_node) {
  for (const Drawable::Ptr& drawable : draw_node->Drawables()) {
    geometry_ = drawable->Geometry();
    material_ = drawable->Material();
    shader_ = material_->Shader();

    // Activate the shader program
    if (!shader_) {
      continue;
    }
    program_ = shader_->Program();
    if (!program_) {
      continue;
    }

    ActivateMaterial();

    if (drawable->PreDraw()) {
      DrawGeometry();
    }

    drawable->PostDraw();

    GLenum gl_err = glGetError();
    if (gl_err != GL_NO_ERROR) {
      printf("OpenGL: %s\n", sv::glErrorString(gl_err));
    }

    // Done. Release resources
    program_->release();

    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  }
}
// Draw text layout
void STDMETHODCALLTYPE CFW1FontWrapper::DrawTextLayout(
	ID3D11DeviceContext *pContext,
	IDWriteTextLayout *pTextLayout,
	FLOAT OriginX,
	FLOAT OriginY,
	UINT32 Color,
	const FW1_RECTF *pClipRect,
	const FLOAT *pTransformMatrix,
	UINT Flags
) {
	IFW1TextGeometry *pTextGeometry = NULL;
	
	// If needed, get a text geometry to store vertices in
	if((Flags & FW1_ANALYZEONLY) == 0 && (Flags & FW1_CACHEONLY) == 0) {
		EnterCriticalSection(&m_textGeometriesCriticalSection);
		if(!m_textGeometries.empty()) {
			pTextGeometry = m_textGeometries.top();
			m_textGeometries.pop();
		}
		LeaveCriticalSection(&m_textGeometriesCriticalSection);
		
		if(pTextGeometry == NULL) {
			IFW1TextGeometry *pNewTextGeometry;
			HRESULT hResult = m_pFW1Factory->CreateTextGeometry(&pNewTextGeometry);
			if(FAILED(hResult)) {
			}
			else {
				pTextGeometry = pNewTextGeometry;
			}
		}
		
		if(pTextGeometry != NULL)
			pTextGeometry->Clear();
	}
	
	// Draw
	AnalyzeTextLayout(pContext, pTextLayout, OriginX, OriginY, Color, Flags, pTextGeometry);
	if((Flags & FW1_ANALYZEONLY) == 0 && (Flags & FW1_CACHEONLY) == 0) {
		DrawGeometry(pContext, pTextGeometry, pClipRect, pTransformMatrix, Flags);
	}
	
	if(pTextGeometry != NULL) {
		// Keep the text geometry for future use
		EnterCriticalSection(&m_textGeometriesCriticalSection);
		m_textGeometries.push(pTextGeometry);
		LeaveCriticalSection(&m_textGeometriesCriticalSection);
	}
}
Exemple #7
0
void Simulator::DrawEnvironment(void)
{    

//draw ground
    glColor3d(0.4, 0.5, 0.5);    
    glNormal3d(0, 0, 1);
    glBegin(GL_QUADS);
    glVertex3f(-30, -30, 0);
    glVertex3f( 30, -30, 0);
    glVertex3f( 30,  30, 0);
    glVertex3f(-30,  30, 0);
    glEnd();

//draw obstacles and terrain
    for(int i = 0; i < (int) m_geoms.size(); ++i)
	DrawGeometry(m_geoms[i]);
    
}
Exemple #8
0
	void Terrain::DrawShadowMap()
	{
		auto shader = ShaderStock::GetInstance()->GetTerrainShadowShader();
		auto renderState = Device::GetInstance()->GetRenderState();
		auto shaderPrev = renderState->GetCurrentShader();

		Matrix world;
		GetWorldMatrix(&world);
		Matrix mv = world * renderState->GetViewMatrix();

		shader->Use();
		shader->UsePass(0);
		shader->SetMatrix("g_mvMatrix", mv);
		shader->SetMatrix("g_projection", renderState->GetProjectionMatrix());
		shader->SetFloat("g_zscale", this->zScale);
		shader->SetTexture("g_heightMap", this->heightMap.Get());
		shader->CommitChanges();

		DrawGeometry();

		shaderPrev->Use();
	}
Exemple #9
0
void CVX_Sim::Draw(int Selected, bool ViewSection, int SectionLayer)
{
	if (!Initalized) return;

	if (CurViewMode == RVM_NONE) return;
	else if (CurViewMode == RVM_VOXELS){ 
		switch (CurViewVox){
		case RVV_DISCRETE: DrawGeometry(Selected, ViewSection, SectionLayer); break; //section view only currently enabled in voxel view mode
		case RVV_DEFORMED: DrawVoxMesh(Selected); break;
		case RVV_SMOOTH: DrawSurfMesh(); break;
		}
	}
	else { //CurViewMode == RVT_BONDS
		DrawBonds();
		DrawStaticFric();
	}
	if (ViewAngles)	DrawAngles();
	if (ViewForce) DrawForce();
	if (pEnv->IsFloorEnabled()) DrawFloor(); //draw the floor if its in use

	NeedStatsUpdate=true;
}
LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    static RECT rect,oldRect,invalidationRect;                                //The oldRect is used for window resizing handling , the invalidationRect for invalidating only the drawing area
    static BOOL drawing_circle=FALSE,drawing_square=TRUE,drawing_bezier=FALSE,//Checks what is being drawn at the moment
                first_point=TRUE,                                                         //Checks if the first point of the bezier is being drawn
                button_pressed_in_area=FALSE,                                             //Checks if the button was pressed and if it happened inside the drawing area
                mouse_moving=FALSE;                                                       //Checks if the mouse is moving in order to paint the tracing of the object

    static HDC hdc,
           hdcMem;
    static HBITMAP hBitmap;
    BITMAP bitmap;

    static int figureCount=0;                                                  //Counts the number of figures in the drawing area
    static POINT arrayPoints[100][5];                                          //The array that holds the data of the figures

    static float xDisp,yDisp,slope,displacement;                               //Used to move and resize the pictures drawn . The last two variables are used to calculate the function
    //that the points will move on when resizing (the resize is a convergence towards the center)
    static int xFin=0,yFin=0,xFinSecond=0,yFinSecond=0;                        //Used to draw the tracing of elemens with the last two needed for Bezier only
    static int resizeCount;                                                    //Used to limit the resize to a certain number of times


    switch (message)                  /* handle the messages */
    {
    case WM_CREATE:

        GetClientRect(hwnd,&rect);
        //oldRect gets the same value as current rect as to avoid division by 0 and unintended resizing at the beginning
        oldRect=rect;
        //Creates the needed switches
        CreateButtons(hwnd,rect);
        // Loads the bitmap from resources
        hBitmap = LoadBitmap(hInst,MAKEINTRESOURCE(LOGO));
        GetObject(hBitmap,sizeof(BITMAP),&bitmap);
        break;

    case WM_SIZE:

        GetClientRect(hwnd,&rect);
        //Resizes all buttons based on the window size
        MoveWindow(hwndSquareButton,rect.right*3/4,rect.bottom/32,rect.right/8,30,TRUE);
        MoveWindow(hwndCircleButton,rect.right*7/8,rect.bottom/32,rect.right/8,30,TRUE);
        MoveWindow(hwndBezierButton,rect.right*3/4,rect.bottom/8,rect.right/8,30,TRUE);
        //Set the displacement of the drawings inside the window to new , moved coordinates
        xDisp=(float)rect.right/oldRect.right;
        yDisp=(float)rect.bottom/oldRect.bottom;

        oldRect.bottom=rect.bottom;
        oldRect.right=rect.right;

        for(int i=0; i<figureCount; i++) {
            for(int j=0; j<4; j++) {
                arrayPoints[i][j].x*=xDisp;
                arrayPoints[i][j].y*=yDisp;
            }
        }

        InvalidateRect(hwnd,NULL,TRUE);
        break;

    case WM_COMMAND:
        //Sets the buttons to active and puts the flags in the needed positions
        switch(wParam)
        {
        case ID_SWITCH_CIRCLE:
            SendMessage(hwndCircleButton,BM_SETCHECK,1,0);
            SendMessage(hwndBezierButton,BM_SETCHECK,0,0);
            SendMessage(hwndSquareButton,BM_SETCHECK,0,0);
            drawing_bezier=drawing_square=FALSE;
            drawing_circle=TRUE;
            break;

        case ID_SWITCH_SQUARE:
            SendMessage(hwndCircleButton,BM_SETCHECK,0,0);
            SendMessage(hwndBezierButton,BM_SETCHECK,0,0);
            SendMessage(hwndSquareButton,BM_SETCHECK,1,0);
            drawing_bezier=drawing_circle=FALSE;
            drawing_square=TRUE;
            break;

        case ID_SWITCH_BEZIER:
            SendMessage(hwndCircleButton,BM_SETCHECK,0,0);
            SendMessage(hwndBezierButton,BM_SETCHECK,1,0);
            SendMessage(hwndSquareButton,BM_SETCHECK,0,0);
            drawing_square=drawing_circle=FALSE;
            drawing_bezier=TRUE;
            break;

        }
        break;

    case WM_RBUTTONDOWN:
        //The setting up of invalidation region
        GetClientRect(hwnd,&rect);
        invalidationRect.right=rect.right*3/4-16;
        invalidationRect.top=rect.top+130;
        invalidationRect.bottom=rect.bottom-5;
        invalidationRect.left=rect.right*1/4+16;
        //The deletion a figure and refreshing the picture
        figureCount--;
        if(figureCount<0) figureCount=0;
        InvalidateRect(hwnd,&invalidationRect,TRUE);
        break;

    case WM_MOUSEMOVE:
        //Exits case in case the mouse is out of the needed area
        if(!button_pressed_in_area) break;
        mouse_moving=TRUE;
        //invalidation
        GetClientRect(hwnd,&rect);
        invalidationRect.right=rect.right*3/4-16;
        invalidationRect.top=rect.top+130;
        invalidationRect.bottom=rect.bottom-5;
        invalidationRect.left=rect.right*1/4+16;
        //Checks if the moving is being done in the drawing area and ends drawing in case it isn't
        if ((LOWORD(lParam)<rect.right/4+20) || (LOWORD(lParam)>rect.right*3/4-20) ||
                (HIWORD(lParam)<135) || (HIWORD(lParam)>rect.bottom-6)) {
            SendMessage(hwnd,WM_LBUTTONUP,NULL,lParam) ;
            break;
        }

        hdc=GetDC(hwnd);
        //Depending on the selected drawing sets the points for the tracing of figures
        if (drawing_circle) {
            xFin=LOWORD(lParam);
            yFin=HIWORD(lParam);
        }

        if (drawing_square) {
            xFin=LOWORD(lParam);
            yFin=HIWORD(lParam);
        }

        if (drawing_bezier && !first_point) {
            xFin=LOWORD(lParam);
            yFin=HIWORD(lParam);
        } else if (drawing_bezier) {
            xFinSecond=LOWORD(lParam);
            yFinSecond=HIWORD(lParam);
        }
        //Send message to repaint drawing area
        InvalidateRect(hwnd,&invalidationRect,TRUE);
        ReleaseDC(hwnd,hdc);

        break;

    case WM_LBUTTONDOWN:
        //Checks if the button clicking is being done in the drawing area and sets focus to main window
        SetFocus(hwnd);
        GetClientRect(hwnd,&rect);
        if ((LOWORD(lParam)<rect.right/4+14) || (LOWORD(lParam)>rect.right*3/4-14) ||
                (HIWORD(lParam)<125) || (HIWORD(lParam)>rect.bottom-6)) break;

        button_pressed_in_area=TRUE;
        hdc=GetDC(hwnd);
        //Gets initial points for the figure being drawn and sets a information value in order to read the right thing from the array afterwards
        if (drawing_square) {
            arrayPoints[figureCount][4].x=ID_SWITCH_SQUARE;
            arrayPoints[figureCount][0].x=LOWORD(lParam);
            arrayPoints[figureCount][0].y=HIWORD(lParam);
        }

        if (drawing_bezier && first_point) {
            arrayPoints[figureCount][4].x=ID_SWITCH_BEZIER;
            arrayPoints[figureCount][0].x=LOWORD(lParam);
            arrayPoints[figureCount][0].y=HIWORD(lParam);
            first_point=FALSE;
        } else if (drawing_bezier) {
            first_point=TRUE;
            figureCount--;
            arrayPoints[figureCount][2].x=LOWORD(lParam);
            arrayPoints[figureCount][2].y=HIWORD(lParam);
        }

        if (drawing_circle) {
            arrayPoints[figureCount][4].x=ID_SWITCH_CIRCLE;
            arrayPoints[figureCount][0].x=LOWORD(lParam);
            arrayPoints[figureCount][0].y=HIWORD(lParam);
        }
        ReleaseDC(hwnd,hdc);
        break;

    case WM_LBUTTONUP:
        //Makes sure the drawing started inside the canvas
        if(!button_pressed_in_area) break;
        mouse_moving=FALSE;
        //invalidation
        GetClientRect(hwnd,&rect);
        invalidationRect.right=rect.right*3/4-16;
        invalidationRect.top=rect.top+130;
        invalidationRect.bottom=rect.bottom-5;
        invalidationRect.left=rect.right*1/4+16;

        hdc=GetDC(hwnd);
        //Gets the end points of the figures
        if (drawing_square) {
            arrayPoints[figureCount][1].x=LOWORD(lParam);
            arrayPoints[figureCount][1].y=HIWORD(lParam);
        }

        if (drawing_bezier && !first_point) {
            arrayPoints[figureCount][1].x=LOWORD(lParam);
            arrayPoints[figureCount][1].y=HIWORD(lParam);

        } else if (drawing_bezier) {
            arrayPoints[figureCount][3].x=LOWORD(lParam);
            arrayPoints[figureCount][3].y=HIWORD(lParam);
            InvalidateRect(hwnd,&invalidationRect,TRUE);
        }

        if (drawing_circle) {
            arrayPoints[figureCount][1].x=LOWORD(lParam);
            arrayPoints[figureCount][1].y=HIWORD(lParam);
        }
        //Increments nr of figures
        figureCount++;
        button_pressed_in_area=FALSE;
        //The bezier uses 4 points instead of 2 like the others so different actions when invalidating
        if (!drawing_bezier) {
            InvalidateRect(hwnd,&invalidationRect,TRUE);
        }

        ReleaseDC(hwnd,hdc);

        break;

    case WM_KEYDOWN:
        //invalidation
        GetClientRect(hwnd,&rect);
        invalidationRect.right=rect.right*3/4-16;
        invalidationRect.top=rect.top+130;
        invalidationRect.bottom=rect.bottom-5;
        invalidationRect.left=rect.right*1/4+16;
        //Resizes canvas based on convergence on the line formed by the center point of the canvas and a point of the figure
        switch(wParam) {
        case VK_UP:

            if (resizeCount<0) break;
            for(int i=0; i<figureCount; i++) {
                for(int j=0; j<4; j++) {

                    slope=(arrayPoints[i][j].y-(rect.bottom-126)/2)/(float)(arrayPoints[i][j].x-rect.right/2);
                    displacement=arrayPoints[i][j].y-slope*arrayPoints[i][j].x;

                    arrayPoints[i][j].x=(rect.right/2)-(rect.right/2-arrayPoints[i][j].x)*1.1;
                    arrayPoints[i][j].y=roundf(arrayPoints[i][j].x*slope+displacement);
                }
            }
            resizeCount--;
            break;

        case VK_DOWN:

            if(resizeCount>10) break;
            for(int i=0; i<figureCount; i++) {
                for(int j=0; j<4; j++) {

                    slope=(arrayPoints[i][j].y-(rect.bottom-126)/2)/(float)(arrayPoints[i][j].x-rect.right/2);
                    displacement=arrayPoints[i][j].y-slope*arrayPoints[i][j].x;

                    arrayPoints[i][j].x=(rect.right/2)-(rect.right/2-arrayPoints[i][j].x)*0.9;
                    arrayPoints[i][j].y=roundf(arrayPoints[i][j].x*slope+displacement);


                }
            }
            resizeCount++;
            break;
        }
        InvalidateRect(hwnd,&invalidationRect,TRUE);
        break;

    case WM_PAINT:
        hdc=BeginPaint(hwnd,&ps);
        GetClientRect(hwnd,&rect);
        //Create figures
        SelectObject(hdc,GetStockObject(NULL_BRUSH));
        for (int i=0; i<figureCount; i++) {
            switch(arrayPoints[i][4].x) {
            case ID_SWITCH_SQUARE:
                Rectangle(hdc,arrayPoints[i][0].x,arrayPoints[i][0].y,arrayPoints[i][1].x,arrayPoints[i][1].y);
                break;
            case ID_SWITCH_CIRCLE:
                Ellipse(hdc,arrayPoints[i][0].x,arrayPoints[i][0].y,arrayPoints[i][1].x,arrayPoints[i][1].y);
                break;
            case ID_SWITCH_BEZIER:
                PolyBezier(hdc,arrayPoints[i],4);
                break;
            }
        }
        //Create traces
        if (mouse_moving) {

            if (drawing_circle) {
                Ellipse(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,xFin,yFin);
            }

            if (drawing_bezier && !first_point) {
                MoveToEx(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,NULL);
                LineTo(hdc,xFin,yFin);
            } else if (drawing_bezier) {
                MoveToEx(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,NULL);
                LineTo(hdc,xFin,yFin);

                MoveToEx(hdc,arrayPoints[figureCount][2].x,arrayPoints[figureCount][2].y,NULL);
                LineTo(hdc,xFinSecond,yFinSecond);
            }

            if (drawing_square) {
                Rectangle(hdc,arrayPoints[figureCount][0].x,arrayPoints[figureCount][0].y,xFin,yFin);
            }

        }

        SelectObject(hdc,GetStockObject(WHITE_BRUSH));
        //Create the gradients
        CreateGradient(hdc,0,0,rect.right/4+10,rect.bottom+1);
        CreateGradient(hdc,rect.right*3/4-10,0,rect.right+1,rect.bottom+1);
        //Creates the background for drawing
        DrawTheWorkingArea(hdc,rect);
        //Adds the lines to the drawing
        DrawTheLines(hdc,rect);
        //Adds figures to the mix
        DrawGeometry(hdc,rect);
        //Make bmp
        hdcMem = CreateCompatibleDC(hdc);
        SelectObject(hdcMem,hBitmap);
        BitBlt(hdc,rect.right/4+16,6,185,120,hdcMem,0,0,SRCCOPY);
        DeleteDC(hdcMem);
        EndPaint(hwnd,&ps);
        break;

    case WM_CTLCOLORSTATIC:
        SetBkMode((HDC)wParam,TRANSPARENT);
        return (LRESULT)GetStockObject(NULL_BRUSH);

    case WM_GETMINMAXINFO:
        //Setting the minimal size for the window
        MINMAXINFO *ptMinMax;
        ptMinMax=(MINMAXINFO*)lParam;

        ptMinMax->ptMinTrackSize.x=450;
        ptMinMax->ptMinTrackSize.y=300;
        break;

    case WM_DESTROY:

        PostQuitMessage (0);       /* send a WM_QUIT to the message queue */
        break;
    default:                      /* for messages that we don't deal with */
        return DefWindowProc (hwnd, message, wParam, lParam);
    }

    return 0;
}
void MainLoop(CPlatform * const  pPlatform)
{
	float tranD[3] = {0.0f, -1.0f, 0};				
	//update the main application
	pPlatform->Tick();	
	WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);
	WRender::EnableDepthTest(true);		
	program.Start();

	//Draw from light perspective
	//glPolygonOffset( 2.5f, 25.0f );
	//glEnable( GL_POLYGON_OFFSET_FILL);
	transform.Push();			
	{
		WRender::SetupViewport(0, 0, TEX_DIMENSIONS, TEX_DIMENSIONS);	//adjust viewport
		WRender::BindFrameBuffer(WRender::FrameBuffer::DRAW, fbo);		//set fbo 
		WRender::ClearScreenBuffer(COLOR_BIT | DEPTH_BIT);				//clear draw buffers (must be called after we set the fbo)

		rotLat.Identity();	rotLat.Rotate(lightLatitude, 1, 0, 0);
		rotLong.Identity();	rotLong.Rotate(lightLongitude, 0, 1, 0);

		transform.Translate(cameraPosition);			
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);

		//setup shadow mvp
			
		shadow_transform.Identity();
		shadow_transform.Translate(0.5f, 0.5f, 0.5f);
		shadow_transform.Scale(0.5f,0.5f,0.5f);
		shadow_transform.ApplyTransform(transforms.proj);
		shadow_transform.ApplyTransform(transform.GetCurrentMatrix());
		DrawGeometry(true);

		WRender::UnbindFrameBuffer(WRender::FrameBuffer::DRAW); //reset draw buffer
		WRender::SetupViewport(0, 0, 640, 640);	//reset viewport			
	}
	//glDisable( GL_POLYGON_OFFSET_FILL);
	transform.Pop();		

	//draw scene
	transform.Push();			
	{
		rotLat.Identity();	rotLat.Rotate(latitude, 1, 0, 0);
		rotLong.Identity();	rotLong.Rotate(longitude, 0, 1, 0);

		transform.Translate(cameraPosition);
		transform.ApplyTransform(rotLat);
		transform.ApplyTransform(rotLong);
		DrawGeometry(false);			
	}
	transform.Pop();		

	//render depth texture to screen
	textureShader.Start();
	WRender::BindVertexArrayObject(sqVao);					
	textureShader.SetVec3("translate",tranD);		
	WRender::Draw(WRender::TRIANGLE_STRIP, WRender::U_BYTE, sizeof(sqIndices)/sizeof(unsigned char), 0);		
		
	//update Keyboard
	pPlatform->UpdateBuffers();
	if(!pPlatform->GetKeyboard().keys[KB_LEFTSHIFT].IsPressed())
	{	pLat = &latitude; pLong = &longitude;}
	else
	{	pLat = &lightLatitude; pLong = &lightLongitude;}

	if(pPlatform->GetKeyboard().keys[KB_UP].IsPressed())
		*pLat += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_DOWN].IsPressed())
		*pLat -= 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_LEFT].IsPressed())//l
		*pLong += 90.0f * pPlatform->GetDT();
	if(pPlatform->GetKeyboard().keys[KB_RIGHT].IsPressed())//r
		*pLong -= 90.0f * pPlatform->GetDT();		

}
/// <summary>
/// IDWriteTextRenderer::DrawGlyphRun
/// Draws glyphs
/// </summary>
HRESULT StateTextRender::DrawGlyphRun(
        LPVOID clientDrawingContext,
        FLOAT baselineOriginX,
        FLOAT baselineOriginY,
        DWRITE_MEASURING_MODE measuringMode,
        const DWRITE_GLYPH_RUN * glyphRun,
        const DWRITE_GLYPH_RUN_DESCRIPTION * glyphRunDescription,
        LPUNKNOWN clientDrawingEffect)
{
    UNREFERENCED_PARAMETER(glyphRunDescription);
    UNREFERENCED_PARAMETER(clientDrawingEffect);

    HRESULT hr = S_OK;

    auto renderTarget = ((ID2D1RenderTarget*) clientDrawingContext);

    // Since the fill looks horrid anyways, only do this if we are
    // going to stroke, and fill using D2D's DrawGlyphRun
    if (mState->mStateSettings.fontStrokeWidth > 0.0f)
    {
        // Get our D2D factory
        ID2D1Factory *d2dFactory;
        renderTarget->GetFactory(&d2dFactory);

        // Create the path geometry.
        ID2D1PathGeometry *pPathGeometry = nullptr;
        hr = d2dFactory->CreatePathGeometry(&pPathGeometry);

        // Write to the path geometry using the geometry sink.
        ID2D1GeometrySink* sink = nullptr;
        if (SUCCEEDED(hr))
        {
            hr = pPathGeometry->Open(&sink);
        }

        // Get the glyph run outline geometries back from DirectWrite and place them within the geometry sink.
        if (SUCCEEDED(hr))
        {
            hr = glyphRun->fontFace->GetGlyphRunOutline(
                glyphRun->fontEmSize,
                glyphRun->glyphIndices,
                glyphRun->glyphAdvances,
                glyphRun->glyphOffsets,
                glyphRun->glyphCount,
                glyphRun->isSideways,
                glyphRun->bidiLevel % 2,
                sink
            );
        }

        // Close the geometry sink
        if (SUCCEEDED(hr))
        {
            hr = sink->Close();
        }

        // Initialize a matrix to translate the origin of the glyph run.
        D2D1::Matrix3x2F const matrix = D2D1::Matrix3x2F(
            1.0f, 0.0f,
            0.0f, 1.0f,
            baselineOriginX, baselineOriginY
            );

        // Create the transformed geometry
        ID2D1TransformedGeometry* pTransformedGeometry = nullptr;
        if (SUCCEEDED(hr))
        {
            hr = d2dFactory->CreateTransformedGeometry(
                pPathGeometry,
                &matrix,
                &pTransformedGeometry
                );
        }

        ID2D1StrokeStyle* strokeStyle = nullptr;
        if (SUCCEEDED(hr))
        {
            d2dFactory->CreateStrokeStyle(
                D2D1::StrokeStyleProperties(
                    D2D1_CAP_STYLE_FLAT,
                    D2D1_CAP_STYLE_FLAT,
                    D2D1_CAP_STYLE_SQUARE,
                    D2D1_LINE_JOIN_BEVEL,
                    5.0f,
                    D2D1_DASH_STYLE_SOLID,
                    0.0f
                ),
                nullptr,
                0,
                &strokeStyle);
        }

        if (SUCCEEDED(hr))
        {

            float strokeWidth = mState->mStateSettings.fontStrokeWidth;
            if (strokeWidth != 0.0f)
            {
                // Draw the outline of the glyph run
                renderTarget->DrawGeometry(
                    pTransformedGeometry,
                    mState->mBrushes[State::BrushType::TextStroke].brush,
                    strokeWidth,
                    strokeStyle
                    );
            }

            // Fill in the glyph run
            // This is so ugly...
            /*renderTarget->FillGeometry(
                pTransformedGeometry,
                mState->mBrushes[State::BrushType::Text].brush
                );*/
        }
    
        SAFERELEASE(strokeStyle);
        SAFERELEASE(pPathGeometry);
        SAFERELEASE(sink);
        SAFERELEASE(pTransformedGeometry);
        d2dFactory->Release();
    }

    // TODO::Figure out how to replicate the quality of D2Ds DrawGlyphRun!
    renderTarget->DrawGlyphRun(D2D1::Point2F(baselineOriginX, baselineOriginY), glyphRun,
        mState->mBrushes[State::BrushType::Text].brush, measuringMode);

    return hr;
}
Exemple #13
0
int __stdcall wWinMain(HINSTANCE instance, HINSTANCE,
                       wchar_t* cmdline, int cmd_show) {

  ::CoInitializeEx(NULL, COINIT_MULTITHREADED);

  try {
    DCoWindow window;
    
    // Create device independent resources. FactoryD2D1 and Geometries are such.
    auto wic_factory = plx::CreateWICFactory();
#if defined (_DEBUG)
    auto d2d1_factory = plx::CreateD2D1FactoryST(D2D1_DEBUG_LEVEL_INFORMATION);
#else
    auto d2d1_factory = plx::CreateD2D1FactoryST(D2D1_DEBUG_LEVEL_NONE);
#endif
    const auto circle =  D2D1::Ellipse(D2D1::Point2F(50.0f, 50.0f), 49.0f, 49.0f);
    plx::ComPtr<ID2D1EllipseGeometry> circle_geom;
    auto hr = d2d1_factory->CreateEllipseGeometry(circle, circle_geom.GetAddressOf());
    if (hr != S_OK)
      throw plx::ComException(__LINE__, hr);

    // Device dependent resources.
#if defined (_DEBUG)
    auto device3D = plx::CreateDeviceD3D11(D3D11_CREATE_DEVICE_DEBUG);
#else
    auto device3D = plx::CreateDevice3D(0);
#endif
    auto device2D = plx::CreateDeviceD2D1(device3D, d2d1_factory);

    VisualManager viman(window.window(), window.dpi(), device2D);
    window.set_visual_manager(&viman);

    const D2D1_SIZE_F zero_offset = {0};

    auto background = viman.make_surface(1.0f, 1.0f);
    {
      auto dc = background.begin_draw(D2D1::ColorF(0.3f, 0.3f, 0.3f, 0.7f), zero_offset);
      background.end_draw();
    }
    viman.set_background_surface(window.window(), background);


    // scale-dependent resources.
    auto surface1 = viman.make_surface(100.0f, 100.0f);
    {
      auto dc = surface1.begin_draw(D2D1::ColorF(0.0f, 0.0f, 0.0f, 0.0f), zero_offset);
      plx::ComPtr<ID2D1SolidColorBrush> brush;
      dc->CreateSolidColorBrush(D2D1::ColorF(0.0f, 0.5f, 1.0f, 0.4f), brush.GetAddressOf());
      dc->FillGeometry(circle_geom.Get(), brush.Get());
      brush->SetColor(D2D1::ColorF(1.0f, 1.0f, 1.0f));
      dc->DrawGeometry(circle_geom.Get(), brush.Get());
      surface1.end_draw();
    }

    unsigned int as_width, as_height;
    auto png1 = plx::CreateWICDecoder(
        wic_factory, plx::FilePath(L"c:\\test\\images\\diamonds_k.png"));
    auto png1_cv = plx::CreateWICBitmapBGRA(0, WICBitmapDitherTypeNone, png1, wic_factory);
    png1_cv->GetSize(&as_width, &as_height);

    auto sc_width = window.dpi().to_physical_x(as_width * 0.5f);
    auto sc_height = window.dpi().to_physical_y(as_height * 0.5f);
    auto surface2 = viman.make_surface(sc_width, sc_height);
    {
      auto dc = surface2.begin_draw(D2D1::ColorF(0.0f, 0.0f, 0.4f, 0.0f), zero_offset);
      auto bmp1 = CreateD2D1Bitmap(dc, png1_cv);
      auto dr = D2D1::Rect(0.0f, 0.0f, sc_width, sc_height);
      dc->DrawBitmap(bmp1.Get(), &dr, 1.0f);
      surface2.end_draw();
    }

    // add the image at the bottom.
    viman.add_visual(surface2, D2D1::Point2F(0.0f, 0.0f));

    auto svg = RealizeSVG(
        //"C:\\Users\\cpu\\Documents\\GitHub\\nanosvg\\example\\nano.svg",
        //"C:\\Test\\svg\\2_elipse_red_black.svg",
        "C:\\Test\\svg\\3_red_arrows_angles.svg",
        window.dpi(), d2d1_factory);

    D2D1_RECT_F svg_bounds = {};
    hr = svg->GetBounds(nullptr, &svg_bounds);
    auto surface3 = viman.make_surface(
        window.dpi().to_physical_x(svg_bounds.right - svg_bounds.left + 1),
        window.dpi().to_physical_y(svg_bounds.bottom - svg_bounds.top + 1));
    {
      auto dc = surface3.begin_draw(
           D2D1::ColorF(0.7f, 0.7f, 0.7f, 0.4f), 
           D2D1::SizeF(-svg_bounds.left, -svg_bounds.top));
      plx::ComPtr<ID2D1SolidColorBrush> brush;
      dc->CreateSolidColorBrush(
          D2D1::ColorF(0.5f, 0.0f, 1.0f, 0.4f), brush.GetAddressOf());
      // Now we can paint and we can draw.
      dc->FillGeometry(svg.Get(), brush.Get());
      brush->SetColor(D2D1::ColorF(1.0f, 1.0f, 1.0f));
      dc->DrawGeometry(svg.Get(), brush.Get());
      surface3.end_draw();
    }

    viman.add_visual(surface3, D2D1::Point2F(10.0f, 80.0f));

    // Add some elipses on top.
    for (int ix = 0; ix != 5; ++ix) {
      viman.add_visual(surface1, D2D1::Point2F(125.0f * ix, 45.0f * ix));
    }

    viman.commit();
    
    HACCEL accel_table = ::LoadAccelerators(instance, MAKEINTRESOURCE(IDC_VTESTS));
    MSG msg;
    while (::GetMessage(&msg, NULL, 0, 0)) {
      if (!::TranslateAccelerator(msg.hwnd, accel_table, &msg)) {
        ::TranslateMessage(&msg);
        ::DispatchMessage(&msg);
      }
    }

    return (int) msg.wParam;

  } catch (plx::Exception& ex) {
    ex;
    __debugbreak();
    return -1;
  }
}