Click here to Skip to main content
14,603,097 members
   

Graphics

 
QuestionOpenGL GLFW/SDL emdeded into WinForms/WPF Pin
Member 1403803230-Oct-18 4:17
MemberMember 1403803230-Oct-18 4:17 
QuestionHow do I convert iTextSharp text to outline (vectorize)? Pin
Jakob Farian Krarup6-Jun-18 19:38
MemberJakob Farian Krarup6-Jun-18 19:38 
AnswerRe: How do I convert iTextSharp text to outline (vectorize)? Pin
Jakob Farian Krarup8-Jun-18 2:05
MemberJakob Farian Krarup8-Jun-18 2:05 
QuestionMessage Closed Pin
29-May-18 23:34
Memberopinas29-May-18 23:34 
AnswerRe: Graphics.FillPath( Brush, GraphicsPath ) does not fill a simple P Pin
Eddy Vluggen29-May-18 23:57
professionalEddy Vluggen29-May-18 23:57 
Question64 bit .NET CatmullRom method? Pin
primem0ver8-Feb-18 7:35
Memberprimem0ver8-Feb-18 7:35 
AnswerMessage Closed Pin
24-Mar-18 21:23
Memberhamedamiri24-Mar-18 21:23 
Questionc++ directx9 center background Pin
Korowai12-Nov-17 7:40
MemberKorowai12-Nov-17 7:40 
Hello,

i am trying to code some graphics for a little game in c++ and winapi / directx9.

I have established a background as a surface. Then i put some sprites on the background.

The problem is, as i call a function that has to center the screen on the active sprite, it doesn't show the background.

Here is the code so far, if you miss an information, please ask and i will answer.


First, the part of main, that is called, when user pushes button (winapi)
<pre>case ID_ZENTRIEREN:
            {
                for (int x=0;x<4;x++)
                    if (Spieler[x].Rundenaktiv==true)
                {
                    Spielx=Spieler[x].posx;
                    Spiely=Spieler[x].posy;
                    d3ddev->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0);
                    render_frame_center(hDlg1, Worldposx, Worldposy, Bildschirmbreite, Bildschirmhoehe, Spielx, Spiely);
                    if (Spieler[x].Mobilart==0) //Schuerfer
                        {
                            float Mobilposx, Mobilposy;
                            Mobilposx=Spieler[x].posx;
                            Mobilposy=Spieler[x].posy;
                            render_Schuerfer(oWorldposx, oWorldposy, Mobilposx, Mobilposy);
                        }
                        else if (Spieler[x].Mobilart==1) //Frachter
                        {
                            float Mobilposx, Mobilposy;
                            Mobilposx=Spieler[x].posx;
                            Mobilposy=Spieler[x].posy;
                            render_Frachter(oWorldposx, oWorldposy, Mobilposx, Mobilposy);
                        }
                        else if (Spieler[x].Mobilart==2) //Flugwaechter
                        {
                            float Mobilposx, Mobilposy;
                            Mobilposx=Spieler[x].posx;
                            Mobilposy=Spieler[x].posy;
                            render_Flugwaechter(oWorldposx, oWorldposy, Mobilposx, Mobilposy);
                        }
                        else if (Spieler[x].Mobilart==3) //Jaeger
                        {
                            float Mobilposx, Mobilposy;
                            Mobilposx=Spieler[x].posx;
                            Mobilposy=Spieler[x].posy;
                            render_Jaeger(oWorldposx, oWorldposy, Mobilposx, Mobilposy);
                        }

                    render_ZeichenaktivesMobil(Spielx, Spiely, oWorldposx, oWorldposy);
                    render_frame_center(hDlg1, Worldposx, Worldposy, Bildschirmbreite, Bildschirmhoehe, Spielx, Spiely);
                    d3ddev->Present(NULL,NULL,NULL,NULL);

                }
            }
            break;


As next, the function that should center the background:
<pre>void render_frame_center(HWND hDlg1, float &Worldposx, float &Worldposy, float &Bildschirmbreite, float &Bildschirmhoehe, float &Spielx, float &Spiely)
{
    RECT screenRect;
    GetClientRect(GetDlgItem(hDlg1, ID_KARTE),&screenRect);
    RECT drawRect;
    // Spieler im Feld
if (Spielx>(screenRect.right-screenRect.left)/2&&
    Spielx<1600-(screenRect.right-screenRect.left)/2&&
    Spiely>(screenRect.bottom-screenRect.top)/2&&
    Spiely<1200-(screenRect.bottom-screenRect.top)/2)
    {
    drawRect.top=Spiely+(screenRect.top-screenRect.bottom)/2;
    drawRect.left=Spielx-(screenRect.right-screenRect.left)/2;
    drawRect.right=Spielx+(screenRect.right-screenRect.left)/2;
    drawRect.bottom=Spiely+(screenRect.top-screenRect.bottom)/2;
    }
    //links
else if (Spielx<(screenRect.right-screenRect.left)/2&&
    Spielx<1600-(screenRect.right-screenRect.left)/2&&
    Spiely>(screenRect.bottom-screenRect.top)/2&&
    Spiely<1200-(screenRect.bottom-screenRect.top)/2)
{
    drawRect.top=Spiely+(screenRect.top-screenRect.bottom)/2;
    drawRect.left=0;
    drawRect.right=0+(screenRect.right-screenRect.left);
    drawRect.bottom=Spiely+(screenRect.top-screenRect.bottom)/2;
}
//rechts
else if (Spielx>(screenRect.right-screenRect.left)/2&&
    Spielx>1600-(screenRect.right-screenRect.left)/2&&
    Spiely>(screenRect.bottom-screenRect.top)/2&&
    Spiely<1200-(screenRect.bottom-screenRect.top)/2)
    {
    drawRect.top=Spiely+(screenRect.top-screenRect.bottom)/2;
    drawRect.left=1600-(screenRect.right-screenRect.left);
    drawRect.right=1600;
    drawRect.bottom=Spiely+(screenRect.top-screenRect.bottom)/2;
    }
    //oben
else if (Spielx>(screenRect.right-screenRect.left)/2&&
    Spielx<1600-(screenRect.right-screenRect.left)/2&&
    Spiely<(screenRect.bottom-screenRect.top)/2&&
    Spiely<1200-(screenRect.bottom-screenRect.top)/2)
    {
    drawRect.top=0;
    drawRect.left=Spielx-(screenRect.right-screenRect.left)/2;
    drawRect.right=Spielx+(screenRect.right-screenRect.left)/2;
    drawRect.bottom=0+(screenRect.top-screenRect.bottom);
    }
    //unten
else if (Spielx>(screenRect.right-screenRect.left)/2&&
    Spielx<1600-(screenRect.right-screenRect.left)/2&&
    Spiely>(screenRect.bottom-screenRect.top)/2&&
    Spiely>1200-(screenRect.bottom-screenRect.top)/2)
    {
    drawRect.top=1200-(screenRect.top-screenRect.bottom);
    drawRect.left=Spielx-(screenRect.right-screenRect.left)/2;
    drawRect.right=Spielx+(screenRect.right-screenRect.left)/2;
    drawRect.bottom=1200;
    }
    // oben links
else if (Spielx<(screenRect.right-screenRect.left)/2&&
    Spielx<1600-(screenRect.right-screenRect.left)/2&&
    Spiely<(screenRect.bottom-screenRect.top)/2&&
    Spiely<1200-(screenRect.bottom-screenRect.top)/2)
    {
    drawRect.top=0;
    drawRect.left=0;
    drawRect.right=0+(screenRect.right-screenRect.left);
    drawRect.bottom=0+(screenRect.top-screenRect.bottom);
    }
   // oben rechts
else if (Spielx>(screenRect.right-screenRect.left)/2&&
    Spielx>1600-(screenRect.right-screenRect.left)/2&&
    Spiely<(screenRect.bottom-screenRect.top)/2&&
    Spiely<1200-(screenRect.bottom-screenRect.top)/2)
    {
    drawRect.top=0;
    drawRect.left=1600-(screenRect.right-screenRect.left);
    drawRect.right=1600;
    drawRect.bottom=0+(screenRect.top-screenRect.bottom);
    }
    //unten links
else if (Spielx<(screenRect.right-screenRect.left)/2&&
    Spielx<1600-(screenRect.right-screenRect.left)/2&&
    Spiely>(screenRect.bottom-screenRect.top)/2&&
    Spiely>1200-(screenRect.bottom-screenRect.top)/2)
    {
    drawRect.top=1200-(screenRect.top-screenRect.bottom);
    drawRect.left=0;
    drawRect.right=0+(screenRect.right-screenRect.left);
    drawRect.bottom=1200;
    }
    //unten rechts
else if (Spielx>(screenRect.right-screenRect.left)/2&&
    Spielx>1600-(screenRect.right-screenRect.left)/2&&
    Spiely>(screenRect.bottom-screenRect.top)/2&&
    Spiely>1200-(screenRect.bottom-screenRect.top)/2)
    {
    drawRect.top=1200-(screenRect.top-screenRect.bottom);
    drawRect.left=1600-(screenRect.right-screenRect.left);
    drawRect.right=1600;
    drawRect.bottom=1200;
    }


    d3ddev->BeginScene();

	d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);
    d3ddev->StretchRect(Hintergrund, &drawRect, backbuffer, NULL, D3DTEXF_NONE);

    d3ddev->EndScene();

}


Here is the init for directx
<pre>void initD3D(HWND hDlg1, HWND hwndRaumkarte, float &Bildschirmbreite, float &Bildschirmhoehe)
{

    HRESULT hresult;


    d3d=Direct3DCreate9(D3D_SDK_VERSION);
    D3DDISPLAYMODE d3ddm;
    d3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.Windowed=TRUE;
    d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
    d3dpp.hDeviceWindow=hwndRaumkarte;
    d3dpp.BackBufferFormat       = d3ddm.Format;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
    d3dpp.PresentationInterval   = D3DPRESENT_INTERVAL_IMMEDIATE;
    d3dpp.BackBufferCount=1;
    d3dpp.BackBufferFormat=D3DFMT_X8R8G8B8;
    d3dpp.BackBufferWidth=800;
    d3dpp.BackBufferHeight=600;

    d3d->CreateDevice(D3DADAPTER_DEFAULT,
                      D3DDEVTYPE_HAL,
                      hwndRaumkarte,
                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                      &d3dpp,
                      &d3ddev);

   // d3ddev->StretchRect(pScr, &screenRect, pDst, NULL, D3DTEXF_LINEAR);
    d3ddev->CreateVertexBuffer( 4*sizeof(Vertex), D3DUSAGE_WRITEONLY,
                                      D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT,
                                      &g_pVertexBuffer, NULL );
    void *pVertices = NULL;
    g_pVertexBuffer->Lock( 0, sizeof(g_quadVertices), (void**)&pVertices, 0 );
    memcpy( pVertices, g_quadVertices, sizeof(g_quadVertices) );
    g_pVertexBuffer->Unlock();


    D3DXMatrixPerspectiveFovLH( &Spritematrix, D3DXToRadian( Kamerawinkel ),
                                800 / 600, 0.00f, 100.0f );

    d3ddev->SetTransform( D3DTS_PROJECTION, &Spritematrix );
	d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	d3ddev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
	d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);

	d3ddev->SetTransform(D3DTS_WORLD, &Spritematrix);


	d3ddev->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS,
                                 D3DTTFF_DISABLE );


    d3ddev->Clear(0,NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0),1.0f,0);

    d3ddev->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    hresult= d3ddev->CreateOffscreenPlainSurface(1600,1200,D3DFMT_X8R8G8B8,D3DPOOL_DEFAULT, &Hintergrund, NULL);


    if (hresult !=D3D_OK)
        return;
}





Further information:
the surface has 800/600, but will be presented as 1600/1200.
int Spielx, Spielx==coordinates of the ship/ sprite

It would be great if someone helps me, because i didn't find a hint in my books or in web.
QuestionFree html5 templates... Pin
Z@db@khsh18-Sep-17 20:40
MemberZ@db@khsh18-Sep-17 20:40 
AnswerRe: Free html5 templates... Pin
Vinod Jangle20-Jun-18 12:39
MemberVinod Jangle20-Jun-18 12:39 
AnswerMessage Closed Pin
10-Jun-19 23:26
professionalSamaj Imfotech10-Jun-19 23:26 
QuestionCan opengl memory fragment Pin
Joe Woodbury13-Jun-17 13:44
professionalJoe Woodbury13-Jun-17 13:44 
QuestionWin32 console programming Pin
Member 132421455-Jun-17 11:17
MemberMember 132421455-Jun-17 11:17 
AnswerRe: Win32 console programming Pin
Richard MacCutchan5-Jun-17 21:39
mveRichard MacCutchan5-Jun-17 21:39 
AnswerMessage Closed Pin
12-Aug-17 22:47
Memberseoamo net12-Aug-17 22:47 
QuestionLibrary for obtaining duration of video movies in various formats? Pin
Member 798912223-May-17 23:03
MemberMember 798912223-May-17 23:03 
AnswerRe: Library for obtaining duration of video movies in various formats? Pin
Michael_Davies23-May-17 23:18
MemberMichael_Davies23-May-17 23:18 
GeneralRe: Library for obtaining duration of video movies in various formats? Pin
Member 798912224-May-17 0:41
MemberMember 798912224-May-17 0:41 
QuestionHow to use GDI to convert these SPRs and MAPs files to bmp files, so I can invoke LoadImage function to load the bmp files and render them on my window by invoking the BitBlt function Pin
EZCodeProject4-May-17 10:03
MemberEZCodeProject4-May-17 10:03 
AnswerRe: How to use GDI to convert these SPRs and MAPs files to bmp files, so I can invoke LoadImage function to load the bmp files and render them on my window by invoking the BitBlt function Pin
Richard MacCutchan4-May-17 10:57
mveRichard MacCutchan4-May-17 10:57 
AnswerRe: How to use GDI to convert these SPRs and MAPs files to bmp files, so I can invoke LoadImage function to load the bmp files and render them on my window by invoking the BitBlt function Pin
Jochen Arndt4-May-17 21:29
professionalJochen Arndt4-May-17 21:29 
GeneralRe: How to use GDI to convert these SPRs and MAPs files to bmp files, so I can invoke LoadImage function to load the bmp files and render them on my window by invoking the BitBlt function Pin
EZCodeProject5-May-17 9:25
MemberEZCodeProject5-May-17 9:25 
GeneralRe: How to use GDI to convert these SPRs and MAPs files to bmp files, so I can invoke LoadImage function to load the bmp files and render them on my window by invoking the BitBlt function Pin
Jochen Arndt5-May-17 21:52
professionalJochen Arndt5-May-17 21:52 
QuestionUrgently need code for rotating a leaf in c language Pin
Member 1301643721-Feb-17 21:54
MemberMember 1301643721-Feb-17 21:54 
AnswerRe: Urgently need code for rotating a leaf in c language Pin
Richard MacCutchan21-Feb-17 21:55
mveRichard MacCutchan21-Feb-17 21:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.