Click here to Skip to main content
15,887,214 members
Home / Discussions / Graphics
   

Graphics

 
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
Member 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 
AnswerRe: Urgently need code for rotating a leaf in c languag e Pin
Patrice T3-Mar-17 15:14
mvePatrice T3-Mar-17 15:14 
QuestionHelp getting started Pin
SpiveyC#17-Feb-17 1:18
SpiveyC#17-Feb-17 1:18 
AnswerRe: Help getting started Pin
Pete O'Hanlon17-Feb-17 1:50
mvePete O'Hanlon17-Feb-17 1:50 
GeneralRe: Help getting started Pin
SpiveyC#19-Feb-17 22:40
SpiveyC#19-Feb-17 22:40 
QuestionDirectX9 - Problems to arrange bitmap Pin
Korowai25-Dec-16 8:54
Korowai25-Dec-16 8:54 
Hi,

i properly have coded a bitmap to be drawn in a control child of a dialogue in WINAPI.

Now i want to fit the bitmap, that has to be bigger than the window size, in specific coordinates, lateron i want to make controls that move the picture in the window.

My problem is i really don't know where i can set the variables who arrange the picture.

Here's the code (only the main, the headers are not neccessary):

C++
#if defined(UNICODE) && !defined(_UNICODE)
    #define _UNICODE
#elif defined(_UNICODE) && !defined(UNICODE)
    #define UNICODE
#endif

#include <tchar.h>
#include <windows.h>
#include <windowsx.h>
#include <d3d9.h>
#include <d3dx9.h>
#include "Resource.h"

#pragma comment (lib, "d3d9.lib")

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);
BOOL CALLBACK Raumaktionproc (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
TCHAR szClassName[ ] = _T("CodeBlocksWindowsApp");

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;
LPDIRECT3DVERTEXBUFFER9 g_pVertexBuffer = NULL;
LPDIRECT3DTEXTURE9      g_pTexture      = NULL;

#define D3DFVF_CUSTOMVERTEX ( D3DFVF_XYZ | D3DFVF_TEX1 )

struct Vertex
{
    float x, y, z;
    float tu, tv;
};

Vertex g_quadVertices[] =
{
	{-1.0f, 1.0f, 0.0f,  0.0f,0.0f },
	{ 1.0f, 1.0f, 0.0f,  1.0f,0.0f },
	{-1.0f,-1.0f, 0.0f,  0.0f,1.0f },
	{ 1.0f,-1.0f, 0.0f,  1.0f,1.0f }
};
static HWND hwndRaumkarte;

void initD3D(HWND hwndRaumkarte);
void render_frame(void);
void cleanD3D(void);
void loadTexture(void);

#define ID_StartDialog 1


int WINAPI WinMain (HINSTANCE hThisInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpszArgument,
                     int nCmdShow)
{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    memset(&messages,0,sizeof(messages));

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default colour as the background of the window */
    wincl.hbrBackground = (HBRUSH) COLOR_BACKGROUND;

    /* Register the window class, and if it fails quit the program */
    if (!RegisterClassEx (&wincl))
        return 0;

    /* The class is registered, let's create the program*/
    hwnd = CreateWindowEx (
           0,                   /* Extended possibilites for variation */
           szClassName,         /* Classname */
           _T("Code::Blocks Template Windows App"),       /* Title Text */
           WS_OVERLAPPEDWINDOW, /* default window */
           CW_USEDEFAULT,       /* Windows decides the position */
           CW_USEDEFAULT,       /* where the window ends up on the screen */
           800,                 /* The programs width */
           600,                 /* and height in pixels */
           HWND_DESKTOP,        /* The window is a child-window to desktop */
           NULL,                /* No menu */
           hThisInstance,       /* Program Instance handler */
           NULL                 /* No Window Creation data */
           );

    /* Make the window visible on the screen */
    ShowWindow (hwnd, nCmdShow);

    /* Run the message loop. It will run until GetMessage() returns 0 */
    while (GetMessage (&messages, NULL, 0, 0))
    {
        /* Translate virtual-key messages into character messages */
        TranslateMessage(&messages);
        /* Send message to WindowProcedure */
        DispatchMessage(&messages);
    }

    /* The program return-value is 0 - The value that PostQuitMessage() gave */
    return messages.wParam;
}


/*  This function is called by the Windows function DispatchMessage()  */

LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    static HINSTANCE hInstance;

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


        CreateWindow(TEXT("button"),"Karte anzeigen",WS_CHILD|WS_VISIBLE,
                    20, 20, 200, 40, hwnd, (HMENU) ID_StartDialog, NULL,NULL);

        }
        break;
    case WM_COMMAND:
            //hMenu=GetMenu(hwnd);
            switch (LOWORD(wParam))
            {
            case ID_StartDialog:
        {


        DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1),hwnd, Raumaktionproc);
                    InvalidateRect(hwnd,NULL, TRUE);
        }
            }
        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;
}


BOOL CALLBACK Raumaktionproc(HWND hDlg1, UINT message, WPARAM wParam, LPARAM lParam)
{
    PAINTSTRUCT ps;
    HDC hdc;
    RECT rect;
    hdc=GetDC(hDlg1);
    hwndRaumkarte=GetDlgItem(hDlg1, ID_RAUMKARTE);

    switch (message)
    {


    case WM_INITDIALOG:
       {
        ShowWindow(GetDlgItem(hDlg1, IDD_DIALOG1), TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_OK),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_RAUMKARTE),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_VERTSCROLL),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_HORSCROLL),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_BASIS),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_FEUER),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_GEGNERAUSWAHL),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_KOM),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_FEUERBEENDEN),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_FEUERFLUCHT),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_LABWERFEN),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_LTAUSCHEN),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_MOBILINFO),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_NMOBIL),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_PLANET),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_SCAN),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_VMOBIL),TRUE);
        ShowWindow(GetDlgItem(hDlg1, ID_ZIELAUSWAHLLISTE),TRUE);

        EnableWindow(GetDlgItem(hDlg1, ID_GEGNERAUSWAHL),FALSE);
        EnableWindow(GetDlgItem(hDlg1, ID_FEUERBEENDEN),FALSE);
        EnableWindow(GetDlgItem(hDlg1, ID_FEUERFLUCHT),FALSE);
        initD3D(hwndRaumkarte);
        InvalidateRect(hDlg1, NULL, TRUE);
        return FALSE;
       };
    case WM_PAINT:
        {
            render_frame();

            //render_frame_Mobil(Mobilx, Mobily);


        }
        break;


    case WM_COMMAND:
        switch (LOWORD (wParam))
       {
           case ID_OK:
        {
                        MessageBox(hDlg1, TEXT ("Runde im All beendet"), "EXO 1.2", MB_ICONEXCLAMATION|MB_OK);
                        cleanD3D();
                        EndDialog(hDlg1,0);
                        return TRUE;
        }
       break;
        }
        break;

    }
    return FALSE;
    }

void loadTexture()
{
    D3DXCreateTextureFromFile( d3ddev, "Raumkarte.bmp", &g_pTexture );

	d3ddev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	d3ddev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
}


void initD3D(HWND hwndRaumkarte)
{
    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;

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

    loadTexture();

    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();

    D3DXMATRIX matProj;
    D3DXMatrixPerspectiveFovLH( &matProj, D3DXToRadian( 45.0f ),
                                1920.0f / 1080.0f, 0.1f, 100.0f );
    d3ddev->SetTransform( D3DTS_PROJECTION, &matProj );

	d3ddev->SetRenderState(D3DRS_LIGHTING, FALSE);
}

void render_frame(void)
{
    d3ddev->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0);

    D3DXMATRIX matWorld;
    D3DXMatrixTranslation( &matWorld, 0.5f, 0.5f, 1.0f );
    d3ddev->SetTransform( D3DTS_WORLD, &matWorld );

    d3ddev->BeginScene();
    d3ddev->SetTexture( 0, g_pTexture );
    d3ddev->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof(Vertex) );
	d3ddev->SetFVF( D3DFVF_CUSTOMVERTEX );
	d3ddev->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );


    d3ddev->EndScene();

    d3ddev->Present(NULL,NULL,NULL,NULL);

}

void cleanD3D(void)
{
    if( g_pTexture != NULL )
        g_pTexture->Release();

    if( g_pVertexBuffer != NULL )
        g_pVertexBuffer->Release();

    d3ddev->Release();
    d3d->Release();
}


For now i need someone to tell me where i have to change the attributes to render the picture in different pixel- parts.
I am a newbie, i got two books, but none can really bring light to this question.

Where do i have to start? With the vertices? With the matrix? Or is it in the parts
of D3DXMatrixTranslation or D3DXMatrixPerspectiveFovLH?

Please help, thx,
Chris
QuestionGetting a sense of Depth and 3D space from images Pin
Member 1233692920-Dec-16 5:19
Member 1233692920-Dec-16 5:19 
AnswerRe: Getting a sense of Depth and 3D space from images Pin
Gerry Schmitz21-Dec-16 8:41
mveGerry Schmitz21-Dec-16 8:41 
QuestionHow to extract geometry from Google Earth? Pin
Member 123369294-Oct-16 1:08
Member 123369294-Oct-16 1:08 
SuggestionRe: How to extract geometry from Google Earth? Pin
Richard MacCutchan4-Oct-16 3:48
mveRichard MacCutchan4-Oct-16 3:48 
AnswerRe: How to extract geometry from Google Earth? Pin
leon de boer18-Oct-16 9:48
leon de boer18-Oct-16 9:48 
QuestionD2D + WPF + SwapChain = ??? Pin
Max Dhom17-May-16 0:56
Max Dhom17-May-16 0:56 
QuestionHow to create complex 3d Objects with direct3d? Pin
Member 1226818310-Apr-16 6:17
Member 1226818310-Apr-16 6:17 
QuestionHow to render multiple 3D objects separately? Pin Pin
Member 1226818327-Mar-16 4:24
Member 1226818327-Mar-16 4:24 
AnswerRe: How to render multiple 3D objects separately? Pin Pin
Graham Breach27-Mar-16 23:29
Graham Breach27-Mar-16 23:29 
GeneralRe: How to render multiple 3D objects separately? Pin Pin
Member 122681833-Apr-16 6:41
Member 122681833-Apr-16 6:41 
AnswerRe: How to render multiple 3D objects separately? Pin Pin
Forrest9012-Jul-16 1:36
Forrest9012-Jul-16 1:36 
GeneralRe: How to render multiple 3D objects separately? Pin Pin
Romain3413-Jul-16 22:33
Romain3413-Jul-16 22:33 
QuestionD2D/GDI+ Interop Problem Pin
Member 1171275327-Feb-16 19:21
Member 1171275327-Feb-16 19:21 
AnswerRe: D2D/GDI+ Interop Problem Pin
Richard MacCutchan27-Feb-16 21:11
mveRichard MacCutchan27-Feb-16 21:11 
QuestionDirect3d Game programming error Pin
Member 1226818323-Feb-16 22:12
Member 1226818323-Feb-16 22:12 
SuggestionRe: Direct3d Game programming error Pin
Richard Deeming24-Feb-16 1:05
mveRichard Deeming24-Feb-16 1:05 
GeneralRe: Direct3d Game programming error Pin
Member 1226818324-Feb-16 20:15
Member 1226818324-Feb-16 20:15 

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.