IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

DirectX Discussion :

Mécanisme de DirectX - Buffers


Sujet :

DirectX

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 62
    Points : 54
    Points
    54
    Par défaut Mécanisme de DirectX - Buffers
    Bonjour,
    Le titre est volontairement très vague car je ne sais pas d'où mon problème peut venir.
    J'ai commencé DX il y a peu et je suis en train de trifouiller le code proposé ici :
    http://www.directxtutorial.com/tutor...ics/dx9B4.aspx

    Mon objectif étant : j'appuie sur la flèche droite et le coté droit du triangle s'affiche ( de même pour les 2 autres cotés ).

    Mais voilà, lorsque j'appuie sur la flèche droite la ligne apparait ( et disparait une fois relâchée, normal ). Mais la ligne du bas étant constamment affichée semble perdre de ses couleurs : POURQUOI DONC ?

    Voila le ( long ) code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    #include "StdAfx.h"
    #include <d3d9.h>
    #include <d3dx9.h>
    #include <windows.h>
    #include <windowsx.h>
    #include <iostream>
     
    #pragma comment (lib, "d3d9.lib")
    // define the screen resolution
    #define SCREEN_WIDTH 800
    #define SCREEN_HEIGHT 600
     
    // global declarations
    LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
    LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class
    LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;    // the pointer to the vertex buffer
     
    // function prototypes
    void initD3D(HWND hWnd);    // sets up and initializes Direct3D
    void render_line(void);    // renders a single frame
    void cleanD3D(void);    // closes Direct3D and releases memory
     void init_graphicsB(void);    // 3D declarations
     void init_graphicsD(void);
     
    struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
    #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
     
    // the WindowProc function prototype
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
     
     
    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
                       HINSTANCE hPrevInstance,
                       LPSTR lpCmdLine,
                       int nCmdShow)
    {
        HWND hWnd;
        WNDCLASSEX wc;
     
        ZeroMemory(&wc, sizeof(WNDCLASSEX));
     
        wc.cbSize = sizeof(WNDCLASSEX);
        wc.style = CS_HREDRAW | CS_VREDRAW;
        wc.lpfnWndProc = WindowProc;
        wc.hInstance = hInstance;
        wc.hCursor = LoadCursor(NULL, IDC_ARROW);
        wc.lpszClassName = L"WindowClass";
     
        RegisterClassEx(&wc);
     
        hWnd = CreateWindowEx(NULL,
                              L"WindowClass",
                              L"Our Direct3D Program",
                              WS_OVERLAPPEDWINDOW,
                              0, 0,
                              SCREEN_WIDTH, SCREEN_HEIGHT,
                              NULL,
                              NULL,
                              hInstance,
                              NULL);
     
        ShowWindow(hWnd, nCmdShow);
     
        // set up and initialize Direct3D
        initD3D(hWnd);
     
        // enter the main loop:
     
        MSG msg;
     
        while(TRUE)
        {
            while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
            {
                TranslateMessage(&msg);
                DispatchMessage(&msg);
            }
     
            if(msg.message == WM_QUIT){
                break;
    		}
    		init_graphicsB();
    		render_line();
     
        }
     
        // clean up DirectX and COM
        cleanD3D();
     
        return msg.wParam;
    }
     
     
    // this is the main message handler for the program
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
        switch(message){
            case WM_DESTROY: 
                {
                    PostQuitMessage(0);
                    return 0;
                } break;
    		case WM_KEYDOWN:
    			if (wParam == VK_RIGHT){ //User hit Escape, end the app
    				init_graphicsD();
    				render_line();
     
    			}
        }
     
        return DefWindowProc (hWnd, message, wParam, lParam);
    }
     
     
    // this function initializes and prepares Direct3D for use
    void initD3D(HWND hWnd)
    {
        d3d = Direct3DCreate9(D3D_SDK_VERSION);
     
        D3DPRESENT_PARAMETERS d3dpp;
     
        ZeroMemory(&d3dpp, sizeof(d3dpp));
        d3dpp.Windowed = TRUE;
        d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
        d3dpp.hDeviceWindow = hWnd;
        d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
        d3dpp.BackBufferWidth = SCREEN_WIDTH;
        d3dpp.BackBufferHeight = SCREEN_HEIGHT;
     
        // create a device class using this information and the info from the d3dpp stuct
        d3d->CreateDevice(D3DADAPTER_DEFAULT,
                          D3DDEVTYPE_HAL,
                          hWnd,
                          D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                          &d3dpp,
                          &d3ddev);
    }
     
     
    // this is the function used to render a single frame
    void render_line(void){
     
        d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
     
        d3ddev->BeginScene();
     
            // select which vertex format we are using
            d3ddev->SetFVF(CUSTOMFVF);
     
            // select the vertex buffer to display
            d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
            d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
     
     
        d3ddev->EndScene();
     
        d3ddev->Present(NULL, NULL, NULL, NULL);
    }
     
     
    // this is the function that cleans up Direct3D and COM
    void cleanD3D(void)
    {
        v_buffer->Release();    // close and release the vertex buffer
        d3ddev->Release();    // close and release the 3D device
        d3d->Release();    // close and release Direct3D
    }
     
     
    // this is the function that puts the 3D models into video RAM
    void init_graphicsB(void)
    {
        // create the vertices using the CUSTOMVERTEX struct
        CUSTOMVERTEX vertices[] =
        {
    		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
            { 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
        };
     
        // create a vertex buffer interface called v_buffer
        d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
                                   0,
                                   CUSTOMFVF,
                                   D3DPOOL_MANAGED,
                                   &v_buffer,
                                   NULL);
     
        VOID* pVoid;    // a void pointer
     
        // lock v_buffer and load the vertices into it
        v_buffer->Lock(0, 0, (void**)&pVoid, 0);
        memcpy(pVoid, vertices, sizeof(vertices));
        v_buffer->Unlock();
    }
    void init_graphicsD(void)
    {
        // create the vertices using the CUSTOMVERTEX struct
        CUSTOMVERTEX vertices[] =
        {       
            { 650.0f, 300.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
            { 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
        };
     
        // create a vertex buffer interface called v_buffer
        d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
                                   0,
                                   CUSTOMFVF,
                                   D3DPOOL_MANAGED,
                                   &v_buffer,
                                   NULL);
     
        VOID* pVoid;    // a void pointer
     
        // lock v_buffer and load the vertices into it
        v_buffer->Lock(0, 0, (void**)&pVoid, 0);
        memcpy(pVoid, vertices, sizeof(vertices));
        v_buffer->Unlock();
    }
    Merci d'avance pour vos réponses

  2. #2
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    bonsoir,

    la ligne du bas n'est pas constamment affichée, voilà pourquoi :

    ligne 72-86 :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    while(TRUE)
    	{
    		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
     
    		if(msg.message == WM_QUIT){
    			break;
    		}
    		init_graphicsB();
    		render_line();
     
    	}
    dans cette boucle tu recréés à chaque fois un nouveau vertex buffer qui écrase le précédent, stocké dans v_buffer;
    et à chaque fois que tu appuies sur droite du recréés aussi un vertex buffer écrasant le précédent, donc étant donné que tu fais un afficher après chaque écrasement, en fait tu affiche chaque ligne à tour de rôle, donc elles apparaissent pales.

    voilà un code qui devrait répondre à tes attentes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    #include <d3d9.h>
    #include <d3dx9.h>
    #include <windows.h>
    #include <windowsx.h>
    #include <iostream>
     
    #pragma comment (lib, "d3d9.lib")
    // define the screen resolution
    #define SCREEN_WIDTH 800
    #define SCREEN_HEIGHT 600
     
    // global declarations
    LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
    LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class
     
    LPDIRECT3DVERTEXBUFFER9 v_buffer_bas = NULL;    // pour stocker le coté gauche
    LPDIRECT3DVERTEXBUFFER9 v_buffer_droit = NULL; // pour stocker le coté droit
     
    bool affiche_le_cote_droit = false;
     
    // function prototypes
    void initD3D(HWND hWnd);    // sets up and initializes Direct3D
    void render_line(void);    // renders a single frame
    void cleanD3D(void);    // closes Direct3D and releases memory
    void init_graphicsB(void);    // 3D declarations
    void init_graphicsD(void);
     
    struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
    #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
     
    // the WindowProc function prototype
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
     
     
    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
    				   HINSTANCE hPrevInstance,
    				   LPSTR lpCmdLine,
    				   int nCmdShow)
    {
    	HWND hWnd;
    	WNDCLASSEX wc;
     
    	ZeroMemory(&wc, sizeof(WNDCLASSEX));
     
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc = WindowProc;
    	wc.hInstance = hInstance;
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.lpszClassName = L"WindowClass";
     
    	RegisterClassEx(&wc);
     
    	hWnd = CreateWindowEx(NULL,
    		L"WindowClass",
    		L"Our Direct3D Program",
    		WS_OVERLAPPEDWINDOW,
    		0, 0,
    		SCREEN_WIDTH, SCREEN_HEIGHT,
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
     
    	ShowWindow(hWnd, nCmdShow);
     
    	// set up and initialize Direct3D
    	initD3D(hWnd);
     
    	// initialise les vb
    	init_graphicsB();
    	init_graphicsD();
     
    	// enter the main loop:
     
    	MSG msg;
     
    	while(TRUE)
    	{
    		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    		{
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
     
    		if(msg.message == WM_QUIT){
    			break;
    		}
    		render_line();
     
    	}
     
    	// clean up DirectX and COM
    	cleanD3D();
     
    	return msg.wParam;
    }
     
     
    // this is the main message handler for the program
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch(message){
    		case WM_DESTROY: 
    			{
    				PostQuitMessage(0);
    				return 0;
    			} break;
    		case WM_KEYDOWN:
    			if (wParam == VK_RIGHT){ //User hit Escape, end the app
    				affiche_le_cote_droit = true;
     
    			}
    			break;
    		case WM_KEYUP:
    			if(wParam == VK_RIGHT)
    			{
    				affiche_le_cote_droit = false;
    			}
    			break;
    	}
     
    	return DefWindowProc (hWnd, message, wParam, lParam);
    }
     
     
    // this function initializes and prepares Direct3D for use
    void initD3D(HWND hWnd)
    {
    	d3d = Direct3DCreate9(D3D_SDK_VERSION);
     
    	D3DPRESENT_PARAMETERS d3dpp;
     
    	ZeroMemory(&d3dpp, sizeof(d3dpp));
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.hDeviceWindow = hWnd;
    	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	d3dpp.BackBufferWidth = SCREEN_WIDTH;
    	d3dpp.BackBufferHeight = SCREEN_HEIGHT;
     
    	// create a device class using this information and the info from the d3dpp stuct
    	d3d->CreateDevice(D3DADAPTER_DEFAULT,
    		D3DDEVTYPE_HAL,
    		hWnd,
    		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    		&d3dpp,
    		&d3ddev);
    }
     
     
    // this is the function used to render a single frame
    void render_line(void){
     
    	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
     
    	d3ddev->BeginScene();
     
    	// select which vertex format we are using
    	d3ddev->SetFVF(CUSTOMFVF);
     
    	// select the vertex buffer to display
    	d3ddev->SetStreamSource(0, v_buffer_bas, 0, sizeof(CUSTOMVERTEX));
    	d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
     
    	if(affiche_le_cote_droit == true)
    	{
    		d3ddev->SetStreamSource(0, v_buffer_droit, 0, sizeof(CUSTOMVERTEX));
    		d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
    	}
     
    	d3ddev->EndScene();
     
    	d3ddev->Present(NULL, NULL, NULL, NULL);
    }
     
     
    // this is the function that cleans up Direct3D and COM
    void cleanD3D(void)
    {
    	v_buffer_bas->Release();    // close and release the vertex buffer
    	v_buffer_droit->Release();
    	d3ddev->Release();    // close and release the 3D device
    	d3d->Release();    // close and release Direct3D
    }
     
     
    // this is the function that puts the 3D models into video RAM
    void init_graphicsB(void)
    {
    	// create the vertices using the CUSTOMVERTEX struct
    	CUSTOMVERTEX vertices[] =
    	{
    		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
    		{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
    	};
     
    	// create a vertex buffer interface called v_buffer
    	d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_bas,
    		NULL);
     
    	VOID* pVoid;    // a void pointer
     
    	// lock v_buffer and load the vertices into it
    	v_buffer_bas->Lock(0, 0, (void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_bas->Unlock();
    }
    void init_graphicsD(void)
    {
    	// create the vertices using the CUSTOMVERTEX struct
    	CUSTOMVERTEX vertices[] =
    	{       
    		{ 650.0f, 300.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
    	};
     
    	// create a vertex buffer interface called v_buffer
    	d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_droit,
    		NULL);
     
    	VOID* pVoid;    // a void pointer
     
    	// lock v_buffer and load the vertices into it
    	v_buffer_droit->Lock(0, 0, (void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_droit->Unlock();
    }

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 62
    Points : 54
    Points
    54
    Par défaut
    Ok d'accord !

    En tâtonnant j'avais pas réussi à creer d'autres buffers que le v_buffer que j'utilisais. Merci bien

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 62
    Points : 54
    Points
    54
    Par défaut
    Ça mérite de faire un Double Post !

    A propos de l'utilisation des buffers, quelle est la meilleure méthode ?
    Un buffer pour chaque objet ? Un buffer pour chaque groupe d'objet ( ayant la même fonction : sous un Mario un buffer pour le fond, un pour chaque sprite ) ?

    Si j'ai bien compris : il existe 1 à 3 buffers ( voire plus ) pour l'écran qui switchent qui est défini lors de la création du display. A côté on peux créer autant de buffers que l'on veut et les associer à des Primitives / Images / Sprites.

  5. #5
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    j'ai pas vraiment de conseil là dessus, personnellement, j'ai une autre limite : celle de ne pas trop faire appel à la méthode Draw*, si plus d'une centaine de fois pas frame, ça handicape le rendu.

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    62
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 62
    Points : 54
    Points
    54
    Par défaut
    J'ai mis un buffer à tout mes objets ( un carré qui s'affiche tout le temps et 3 lignes qui s'affichent si on appuie sur les flèches ).
    Mais j'ai une impression de déjà-vu, les buffers n'ont pas l'air de suivre le mouvement : la faute au while(true) ? Et donc la faute à un appel à Draw trop de fois par frame ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    #include "StdAfx.h"
    #include <d3d9.h>
    #include <d3dx9.h>
    #include <windows.h>
    #include <windowsx.h>
    #include <iostream>
     
    #pragma comment (lib, "d3d9.lib")
    // define the screen resolution
    #define SCREEN_WIDTH 1000
    #define SCREEN_HEIGHT 600
     
    // global declarations
    LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
    LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class
     
    LPDIRECT3DVERTEXBUFFER9 v_buffer_bas = NULL;    // pour stocker le coté gauche
    LPDIRECT3DVERTEXBUFFER9 v_buffer_droit = NULL; // pour stocker le coté droit
    LPDIRECT3DVERTEXBUFFER9 v_buffer_gauche = NULL;
    LPDIRECT3DVERTEXBUFFER9 v_buffer_carre = NULL;
     
     
    bool afficheDroit = false;
    bool afficheGauche = false;
    bool afficheBas = false;
     
    // function prototypes
    void initD3D(HWND hWnd);    // sets up and initializes Direct3D
    void render_line(void);
    void render_carre(void);
    void cleanD3D(void);    // closes Direct3D and releases memory
    void init_graphicsB(void);    // 3D declarations
    void init_graphicsD(void);
    void init_graphicsG(void);
     
    void init_graphicsCarre(void);
     
    struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
    #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
     
    // the WindowProc function prototype
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
     
     
    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
    				   HINSTANCE hPrevInstance,
    				   LPSTR lpCmdLine,
    				   int nCmdShow)
    {
    	HWND hWnd;
    	WNDCLASSEX wc;
     
    	ZeroMemory(&wc, sizeof(WNDCLASSEX));
     
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc = WindowProc;
    	wc.hInstance = hInstance;
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.lpszClassName = L"WindowClass";
     
    	RegisterClassEx(&wc);
     
    	hWnd = CreateWindowEx(NULL,
    		L"WindowClass",
    		L"Our Direct3D Program",
    		WS_OVERLAPPEDWINDOW,
    		0, 0,
    		SCREEN_WIDTH, SCREEN_HEIGHT,
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
     
    	ShowWindow(hWnd, nCmdShow);
     
    	// set up and initialize Direct3D
    	initD3D(hWnd);
     
    	// initialise les vb
    	init_graphicsB();
    	init_graphicsD();
    	init_graphicsG();
    	init_graphicsCarre();
     
    	// enter the main loop:
     
    	MSG msg;
     
    	while(TRUE)
    	{
    		d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
     
    		if(msg.message == WM_QUIT){
    			break;
    		}
    		render_line();	
    		render_carre();
     
    	}
     
    	// clean up DirectX and COM
    	cleanD3D();
     
    	return msg.wParam;
    }
     
     
    // this is the main message handler for the program
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch(message){
    		case WM_DESTROY: 
    			{
    				PostQuitMessage(0);
    				return 0;
    			} break;
     
    		case WM_KEYDOWN:
    			if (wParam == VK_RIGHT){ 
    				afficheDroit = true;
     
    			}			
    			if (wParam == VK_LEFT){ 
    				afficheGauche = true;
     
    			}			
    			if (wParam == VK_DOWN){ 
    				afficheBas = true;
     
    			}
    			break;
    		case WM_KEYUP:
    			if(wParam == VK_RIGHT){
    				afficheDroit = false;
    			}
    			if (wParam == VK_LEFT){ 
    				afficheGauche = false;
     
    			}
    			if (wParam == VK_DOWN){ 
    				afficheBas = false;
    			}
    			break;
    	}
     
    	return DefWindowProc (hWnd, message, wParam, lParam);
    }
     
     
    // this function initializes and prepares Direct3D for use
    void initD3D(HWND hWnd)
    {
    	d3d = Direct3DCreate9(D3D_SDK_VERSION);
     
    	D3DPRESENT_PARAMETERS d3dpp;
     
    	ZeroMemory(&d3dpp, sizeof(d3dpp));
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.hDeviceWindow = hWnd;
    	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	d3dpp.BackBufferWidth = SCREEN_WIDTH;
    	d3dpp.BackBufferHeight = SCREEN_HEIGHT;
     
    	// create a device class using this information and the info from the d3dpp stuct
    	d3d->CreateDevice(D3DADAPTER_DEFAULT,
    		D3DDEVTYPE_HAL,
    		hWnd,
    		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    		&d3dpp,
    		&d3ddev);
    }
     
     
    // this is the function used to render a single frame
    void render_line(void){
     
     
     
    	d3ddev->BeginScene();
     
    	// select which vertex format we are using
    	d3ddev->SetFVF(CUSTOMFVF);
     
    	// select the vertex buffer to display
     
    	if(afficheDroit == true){
    		d3ddev->SetStreamSource(0, v_buffer_droit, 0, sizeof(CUSTOMVERTEX));
    		d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
    	}
    	if(afficheGauche == true){
    		d3ddev->SetStreamSource(0, v_buffer_gauche, 0, sizeof(CUSTOMVERTEX));
    		d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
    	}
    	if(afficheBas == true){
    		d3ddev->SetStreamSource(0, v_buffer_bas, 0, sizeof(CUSTOMVERTEX));
    		d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
    	}
     
    	d3ddev->EndScene();
     
    	d3ddev->Present(NULL, NULL, NULL, NULL);
    }
     
     
     void render_carre(void){
     
    	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
     
    	d3ddev->BeginScene();
     
    	// select which vertex format we are using
    	d3ddev->SetFVF(CUSTOMFVF);
     
    	// select the vertex buffer to display
     
     
    	d3ddev->SetStreamSource(0, v_buffer_carre, 0, sizeof(CUSTOMVERTEX));
    	d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
     
     
    	d3ddev->EndScene();
     
    	d3ddev->Present(NULL, NULL, NULL, NULL);
    }
     
     
    // this is the function that cleans up Direct3D and COM
    void cleanD3D(void){
    	v_buffer_bas->Release();    // close and release the vertex buffer
    	v_buffer_droit->Release();
    	v_buffer_gauche->Release(); 
    	v_buffer_carre->Release(); 
    	d3ddev->Release();    // close and release the 3D device
    	d3d->Release();    // close and release Direct3D
    }
     
    // this is the function that puts the 3D models into video RAM
    void init_graphicsB(void)
    {
    	// create the vertices using the CUSTOMVERTEX struct
    	CUSTOMVERTEX vertices[] =
    	{
    		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
    		{ 350.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(250, 0, 0), },
    	};
     
     
    	// create a vertex buffer interface called v_buffer
    	d3ddev->CreateVertexBuffer(2*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_bas,
    		NULL);
     
    	VOID* pVoid;    // a void pointer
     
    	// lock v_buffer and load the vertices into it
    	v_buffer_bas->Lock(0, 0, (void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_bas->Unlock();
    }
    void init_graphicsD(void)
    {
    	// create the vertices using the CUSTOMVERTEX struct
    	CUSTOMVERTEX vertices[] =
    	{       
    		{ 500.0f, 200.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
    		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
    	};
     
    	// create a vertex buffer interface called v_buffer
    	d3ddev->CreateVertexBuffer(2*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_droit,
    		NULL);
     
    	VOID* pVoid;    // a void pointer
     
    	// lock v_buffer and load the vertices into it
    	v_buffer_droit->Lock(0, 0, (void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_droit->Unlock();
    }
    void init_graphicsG(void){
    	CUSTOMVERTEX vertices[] = 
    	{
    		{ 500.0f, 200.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    		{ 350.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    	};
     
    	d3ddev->CreateVertexBuffer(2*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_gauche,
    		NULL);
     
    	VOID* pVoid;
     
    	v_buffer_gauche->Lock(0,0,(void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_droit->Unlock();
    }
     
    void init_graphicsCarre(void){
    	CUSTOMVERTEX vertices[] = 
    	{
    		{ 10.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 255), },
    		{ 10.0f, 10.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    		{ 100.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 255), },
     
    		{ 100.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 255), },
    		{ 10.0f, 10.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    		{ 100.0f, 10.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    	};
     
    	d3ddev->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_carre,
    		NULL);
     
    	VOID* pVoid;
     
    	v_buffer_carre->Lock(0,0,(void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_carre->Unlock();
    }
    Il faudrait que j'integre un timer rafraichissant x fois l'image par seconde en faisant x appels à render_carre() et render_line() ?

    Merci d'avance

  7. #7
    Expert confirmé

    Profil pro
    Inscrit en
    Février 2006
    Messages
    2 382
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2006
    Messages : 2 382
    Points : 4 936
    Points
    4 936
    Par défaut
    il ne faut faire appel à BeginScene, Clear, EndScene et Present qu'une seule fois par frame (ce que j'appelle frame c'est un tour de boucle du while(true) ) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    #include "StdAfx.h"
    #include <d3d9.h>
    #include <d3dx9.h>
    #include <windows.h>
    #include <windowsx.h>
    #include <iostream>
     
    #pragma comment (lib, "d3d9.lib")
    // define the screen resolution
    #define SCREEN_WIDTH 1000
    #define SCREEN_HEIGHT 600
     
    // global declarations
    LPDIRECT3D9 d3d;    // the pointer to our Direct3D interface
    LPDIRECT3DDEVICE9 d3ddev;    // the pointer to the device class
     
    LPDIRECT3DVERTEXBUFFER9 v_buffer_bas = NULL;    // pour stocker le coté gauche
    LPDIRECT3DVERTEXBUFFER9 v_buffer_droit = NULL; // pour stocker le coté droit
    LPDIRECT3DVERTEXBUFFER9 v_buffer_gauche = NULL;
    LPDIRECT3DVERTEXBUFFER9 v_buffer_carre = NULL;
     
     
    bool afficheDroit = false;
    bool afficheGauche = false;
    bool afficheBas = false;
     
    // function prototypes
    void initD3D(HWND hWnd);    // sets up and initializes Direct3D
     
    void BeginRender(); // pour commencer le rendu
    void EndRender(); // pour finir le rendu
     
    void render_line(void);
    void render_carre(void);
    void cleanD3D(void);    // closes Direct3D and releases memory
    void init_graphicsB(void);    // 3D declarations
    void init_graphicsD(void);
    void init_graphicsG(void);
     
    void init_graphicsCarre(void);
     
    struct CUSTOMVERTEX {FLOAT X, Y, Z, RHW; DWORD COLOR;};
    #define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
     
    // the WindowProc function prototype
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
     
     
    // the entry point for any Windows program
    int WINAPI WinMain(HINSTANCE hInstance,
    				   HINSTANCE hPrevInstance,
    				   LPSTR lpCmdLine,
    				   int nCmdShow)
    {
    	HWND hWnd;
    	WNDCLASSEX wc;
     
    	ZeroMemory(&wc, sizeof(WNDCLASSEX));
     
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	wc.lpfnWndProc = WindowProc;
    	wc.hInstance = hInstance;
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.lpszClassName = L"WindowClass";
     
    	RegisterClassEx(&wc);
     
    	hWnd = CreateWindowEx(NULL,
    		L"WindowClass",
    		L"Our Direct3D Program",
    		WS_OVERLAPPEDWINDOW,
    		0, 0,
    		SCREEN_WIDTH, SCREEN_HEIGHT,
    		NULL,
    		NULL,
    		hInstance,
    		NULL);
     
    	ShowWindow(hWnd, nCmdShow);
     
    	// set up and initialize Direct3D
    	initD3D(hWnd);
     
    	// initialise les vb
    	init_graphicsB();
    	init_graphicsD();
    	init_graphicsG();
    	init_graphicsCarre();
     
    	// enter the main loop:
     
    	MSG msg;
     
    	while(TRUE)
    	{
    		d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    		while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
    			TranslateMessage(&msg);
    			DispatchMessage(&msg);
    		}
     
    		if(msg.message == WM_QUIT){
    			break;
    		}
    		BeginRender();
    		render_line();	
    		render_carre();
    		EndRender();
    	}
     
    	// clean up DirectX and COM
    	cleanD3D();
     
    	return msg.wParam;
    }
     
     
    // this is the main message handler for the program
    LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	switch(message){
    case WM_DESTROY: 
    	{
    		PostQuitMessage(0);
    		return 0;
    	} break;
     
    case WM_KEYDOWN:
    	if (wParam == VK_RIGHT){ 
    		afficheDroit = true;
     
    	}			
    	if (wParam == VK_LEFT){ 
    		afficheGauche = true;
     
    	}			
    	if (wParam == VK_DOWN){ 
    		afficheBas = true;
     
    	}
    	break;
    case WM_KEYUP:
    	if(wParam == VK_RIGHT){
    		afficheDroit = false;
    	}
    	if (wParam == VK_LEFT){ 
    		afficheGauche = false;
     
    	}
    	if (wParam == VK_DOWN){ 
    		afficheBas = false;
    	}
    	break;
    	}
     
    	return DefWindowProc (hWnd, message, wParam, lParam);
    }
     
     
    // this function initializes and prepares Direct3D for use
    void initD3D(HWND hWnd)
    {
    	d3d = Direct3DCreate9(D3D_SDK_VERSION);
     
    	D3DPRESENT_PARAMETERS d3dpp;
     
    	ZeroMemory(&d3dpp, sizeof(d3dpp));
    	d3dpp.Windowed = TRUE;
    	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    	d3dpp.hDeviceWindow = hWnd;
    	d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
    	d3dpp.BackBufferWidth = SCREEN_WIDTH;
    	d3dpp.BackBufferHeight = SCREEN_HEIGHT;
     
    	// create a device class using this information and the info from the d3dpp stuct
    	d3d->CreateDevice(D3DADAPTER_DEFAULT,
    		D3DDEVTYPE_HAL,
    		hWnd,
    		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
    		&d3dpp,
    		&d3ddev);
    }
     
    void BeginRender()
    {
    	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
     
    	d3ddev->BeginScene();
    }
     
    void EndRender()
    {
    	d3ddev->EndScene();
     
    	d3ddev->Present(NULL, NULL, NULL, NULL);
    }
     
    // this is the function used to render a single frame
    void render_line(void){
     
    	// select which vertex format we are using
    	d3ddev->SetFVF(CUSTOMFVF);
     
    	// select the vertex buffer to display
     
    	if(afficheDroit == true){
    		d3ddev->SetStreamSource(0, v_buffer_droit, 0, sizeof(CUSTOMVERTEX));
    		d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
    	}
    	if(afficheGauche == true){
    		d3ddev->SetStreamSource(0, v_buffer_gauche, 0, sizeof(CUSTOMVERTEX));
    		d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
    	}
    	if(afficheBas == true){
    		d3ddev->SetStreamSource(0, v_buffer_bas, 0, sizeof(CUSTOMVERTEX));
    		d3ddev->DrawPrimitive(D3DPT_LINELIST, 0, 1);
    	}
    }
     
     
    void render_carre(void){
     
    	// select which vertex format we are using
    	d3ddev->SetFVF(CUSTOMFVF);
     
    	// select the vertex buffer to display
     
     
    	d3ddev->SetStreamSource(0, v_buffer_carre, 0, sizeof(CUSTOMVERTEX));
    	d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
    }
     
     
    // this is the function that cleans up Direct3D and COM
    void cleanD3D(void){
    	v_buffer_bas->Release();    // close and release the vertex buffer
    	v_buffer_droit->Release();
    	v_buffer_gauche->Release(); 
    	v_buffer_carre->Release(); 
    	d3ddev->Release();    // close and release the 3D device
    	d3d->Release();    // close and release Direct3D
    }
     
    // this is the function that puts the 3D models into video RAM
    void init_graphicsB(void)
    {
    	// create the vertices using the CUSTOMVERTEX struct
    	CUSTOMVERTEX vertices[] =
    	{
    		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
    		{ 350.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(250, 0, 0), },
    	};
     
     
    	// create a vertex buffer interface called v_buffer
    	d3ddev->CreateVertexBuffer(2*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_bas,
    		NULL);
     
    	VOID* pVoid;    // a void pointer
     
    	// lock v_buffer and load the vertices into it
    	v_buffer_bas->Lock(0, 0, (void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_bas->Unlock();
    }
    void init_graphicsD(void)
    {
    	// create the vertices using the CUSTOMVERTEX struct
    	CUSTOMVERTEX vertices[] =
    	{       
    		{ 500.0f, 200.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
    		{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
    	};
     
    	// create a vertex buffer interface called v_buffer
    	d3ddev->CreateVertexBuffer(2*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_droit,
    		NULL);
     
    	VOID* pVoid;    // a void pointer
     
    	// lock v_buffer and load the vertices into it
    	v_buffer_droit->Lock(0, 0, (void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_droit->Unlock();
    }
    void init_graphicsG(void){
    	CUSTOMVERTEX vertices[] = 
    	{
    		{ 500.0f, 200.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    		{ 350.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    	};
     
    	d3ddev->CreateVertexBuffer(2*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_gauche,
    		NULL);
     
    	VOID* pVoid;
     
    	v_buffer_gauche->Lock(0,0,(void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_droit->Unlock();
    }
     
    void init_graphicsCarre(void){
    	CUSTOMVERTEX vertices[] = 
    	{
    		{ 10.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 255), },
    		{ 10.0f, 10.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    		{ 100.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 255), },
     
    		{ 100.0f, 100.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 255), },
    		{ 10.0f, 10.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    		{ 100.0f, 10.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
    	};
     
    	d3ddev->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX),
    		0,
    		CUSTOMFVF,
    		D3DPOOL_MANAGED,
    		&v_buffer_carre,
    		NULL);
     
    	VOID* pVoid;
     
    	v_buffer_carre->Lock(0,0,(void**)&pVoid, 0);
    	memcpy(pVoid, vertices, sizeof(vertices));
    	v_buffer_carre->Unlock();
    }

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Directx ou opengl
    Par scorpiwolf dans le forum DirectX
    Réponses: 13
    Dernier message: 07/02/2003, 08h29
  2. Alpha blending et Z-buffer directx 8
    Par Cesar4 dans le forum DirectX
    Réponses: 1
    Dernier message: 23/05/2002, 12h58
  3. OpenGL ou DirectX
    Par Nadir dans le forum DirectX
    Réponses: 6
    Dernier message: 02/05/2002, 12h48
  4. Documentation DirectX dans C++Builder 3
    Par srvremi dans le forum DirectX
    Réponses: 1
    Dernier message: 26/04/2002, 09h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo