Click here to Skip to main content
15,846,726 members
Home / Discussions / Graphics
   

Graphics

 
AnswerRe: opengl (openTK) Pin
Gerry Schmitz7-May-19 12:22
mveGerry Schmitz7-May-19 12:22 
GeneralRe: opengl (openTK) Pin
dspdad0107-May-19 15:00
dspdad0107-May-19 15:00 
QuestionOpenGL GLFW/SDL emdeded into WinForms/WPF Pin
Member 1403803230-Oct-18 5:17
Member 1403803230-Oct-18 5:17 
QuestionHow do I convert iTextSharp text to outline (vectorize)? Pin
Jakob Farian Krarup6-Jun-18 20:38
Jakob Farian Krarup6-Jun-18 20:38 
AnswerRe: How do I convert iTextSharp text to outline (vectorize)? Pin
Jakob Farian Krarup8-Jun-18 3:05
Jakob Farian Krarup8-Jun-18 3:05 
AnswerRe: Graphics.FillPath( Brush, GraphicsPath ) does not fill a simple P Pin
Eddy Vluggen30-May-18 0:57
professionalEddy Vluggen30-May-18 0:57 
Question64 bit .NET CatmullRom method? Pin
primem0ver8-Feb-18 8:35
primem0ver8-Feb-18 8:35 
Questionc++ directx9 center background Pin
Korowai12-Nov-17 8:40
Korowai12-Nov-17 8: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)
C++
<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:
C++
<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
C++
<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 21:40
Z@db@khsh18-Sep-17 21:40 
AnswerRe: Free html5 templates... Pin
User 418025420-Jun-18 13:39
User 418025420-Jun-18 13:39 
QuestionCan opengl memory fragment Pin
Joe Woodbury13-Jun-17 14:44
professionalJoe Woodbury13-Jun-17 14:44 
QuestionWin32 console programming Pin
Member 132421455-Jun-17 12:17
Member 132421455-Jun-17 12:17 
AnswerRe: Win32 console programming Pin
Richard MacCutchan5-Jun-17 22:39
mveRichard MacCutchan5-Jun-17 22:39 
QuestionLibrary for obtaining duration of video movies in various formats? Pin
kalberts24-May-17 0:03
kalberts24-May-17 0:03 
AnswerRe: Library for obtaining duration of video movies in various formats? Pin
Michael_Davies24-May-17 0:18
Michael_Davies24-May-17 0:18 
GeneralRe: Library for obtaining duration of video movies in various formats? Pin
kalberts24-May-17 1:41
kalberts24-May-17 1: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 11:03
EZCodeProject4-May-17 11: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 11:57
mveRichard MacCutchan4-May-17 11: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 22:29
professionalJochen Arndt4-May-17 22: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 10:25
EZCodeProject5-May-17 10: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 22:52
professionalJochen Arndt5-May-17 22:52 
QuestionUrgently need code for rotating a leaf in c language Pin
Member 1301643721-Feb-17 22:54
Member 1301643721-Feb-17 22:54 
AnswerRe: Urgently need code for rotating a leaf in c language Pin
Richard MacCutchan21-Feb-17 22:55
mveRichard MacCutchan21-Feb-17 22:55 
AnswerRe: Urgently need code for rotating a leaf in c languag e Pin
Patrice T3-Mar-17 16:14
mvePatrice T3-Mar-17 16:14 
QuestionHelp getting started Pin
SpiveyC#17-Feb-17 2:18
SpiveyC#17-Feb-17 2:18 

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.