Lenteur2

SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 - 13 déc. 2005 à 15:21
SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 - 14 avril 2006 à 04:52
Pour résumé, j'ai fait une DLL de graphisme 2D qui marche très bien. Le seul problème c'est que c'est très lent. J'utilisais SetPixel pour afficher les pixels (voir procédure dans la question lenteur) On ma suggéré d'utiliser BitBlt. Mais, corrigez moi si je me trompe, BitBlt n'est pas fait pour créé des pixels. Il ne fait que les afficher à l'écran. Donc ma question reviend à: connessez vous un moyen pour créé des pixels à l'écran sans faire ramé l'ordi. En gros sans utiliser SetPixel.

49 réponses

SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 15
10 avril 2006 à 18:53
On dirait que ça a encore disparue. Bon je décris. Alors ya un carée gris de 150 sur 150. Quand je rentre les coordonnées dans le tableau, il se forme des lignes qui s'empile une par dessus les autres sans respecter les coordonné. En plus elle change de couleur à toute les lignes.

___________________________________________
Les plus grands esprits trouvent toujours une solution
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
10 avril 2006 à 21:43
Si j'ai pu voit l'image mais le probleme doit venir du reste du code car avec (150-y) ca DOIT inverser et non pas 0,120
0
SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 15
10 avril 2006 à 23:51
Et bien voici le code

BITMAPINFO dib;
ZeroMemory(&dib, sizeof(dib));


dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
dib.bmiHeader.biHeight = 150;
dib.bmiHeader.biWidth = 150;
dib.bmiHeader.biPlanes = 1;
dib.bmiHeader.biBitCount = 24;

DWORD bytewidth = 4*((3*150+3)/4);

BYTE *test = new BYTE[bytewidth*150];


int tmp = 0;
int x = 0;
int y = 0;


while(y < 50)
{
while(x < 50)
{
tmp = (150-y)*150+3*x;
test[tmp] = 0;
test[tmp+1] = 255;
test[tmp+2] = 0;
x++;
}
y++;
x=0;
}


SetDIBitsToDevice(memhDC, 0, 0, 150, 150, 0, 0, 0, 150, test, &dib, DIB_RGB_COLORS);

delete test;

___________________________________________
Les plus grands esprits trouvent toujours une solution
0
SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 15
10 avril 2006 à 23:53
C'est le vrai code. Celui avec lequel je compile.

___________________________________________
Les plus grands esprits trouvent toujours une solution
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 15
11 avril 2006 à 00:33
Et si ça peut t'aider voici le code complet d'un programme test:

#include <windows.h>
HDC hDC;
BITMAPINFO dib;

HRESULT WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;

switch(message)
{
case WM_CREATE:
hDC = GetDC(hWnd);

ZeroMemory(&dib, sizeof(dib));

dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
dib.bmiHeader.biHeight = 150;
dib.bmiHeader.biWidth = 150;
dib.bmiHeader.biPlanes = 1;
dib.bmiHeader.biBitCount = 24;
break;

case WM_PAINT:
{
BeginPaint(hWnd, &ps);

DWORD bytewidth = 4*((3*150+3)/4);
BYTE *test = new BYTE[bytewidth*150];

int tmp = 0;
int x = 0;
int y = 0;

while(y < 50)
{
while(x < 50)
{
tmp = (150-y)*150+3*x;
test[tmp] = 0;
test[tmp+1] = 255;
test[tmp+2] = 0;
x++;
}
y++;
x=0;
}

SetDIBitsToDevice(hDC, 0, 0, 150, 150, 0, 0, 0, 150, test, &dib, DIB_RGB_COLORS);

delete test;

EndPaint(hWnd, &ps);
}
break;

case WM_DESTROY:
PostQuitMessage(0);
break;

default:
return DefWindowProc(hWnd, message, wParam, lParam);
}

return FALSE;
}

int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
WNDCLASSEX wcex;
MSG msg;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);
wcex.lpszMenuName = 0;
wcex.lpszClassName = "test";
wcex.hIconSm = 0;

RegisterClassEx(&wcex);

HWND hWnd = CreateWindow("test", "test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)
{
MessageBox(0, "Impossible", 0, 0);
return FALSE;
}

ShowWindow(hWnd, SW_MAXIMIZE);
UpdateWindow(hWnd);

while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 0;
}

___________________________________________
Les plus grands esprits trouvent toujours une solution
0
SnOOpss Messages postés 571 Date d'inscription samedi 3 avril 2004 Statut Membre Dernière intervention 5 décembre 2013
11 avril 2006 à 18:05
Je ne sais pas pourquoi ton code deconne mais celui la fonctionne ( a part un decalage RGB mais ca c'est pas le plus chiant)



#include <windows.h>



BITMAPINFO dib;



HRESULT WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)

{

PAINTSTRUCT ps;



switch(message)

{

case WM_CREATE:



ZeroMemory(&dib, sizeof(dib));



dib.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);

dib.bmiHeader.biHeight = 150;

dib.bmiHeader.biWidth = 150;

dib.bmiHeader.biPlanes = 1;

dib.bmiHeader.biBitCount = 24;

dib.bmiHeader.biCompression = BI_RGB;

break;



case WM_PAINT:

{

HDC hDC=BeginPaint(hWnd, &ps);





DWORD bytewidth = 4*((3*150+3)/4);



LPBYTE lpBits = new BYTE[bytewidth*150];



if (!(lpBits)) { return NULL; }



int tmp = 0;



for (int y = 50; y < 100; y++)

{

for (int x = 50; x < 100; x++)

{



tmp = (150-y-1)*bytewidth+3*x;





lpBits[tmp]=0;

lpBits[tmp+1]=255;

lpBits[tmp+2]=0;



}

}




SetDIBitsToDevice(hDC, 0, 0, 150, 150, 0, 0, 0, 150, lpBits, &dib,
DIB_RGB_COLORS);



EndPaint(hWnd, &ps);

}

break;



case WM_DESTROY:

PostQuitMessage(0);

break;



default:

return DefWindowProc(hWnd, message, wParam, lParam);

}



return FALSE;

}



int APIENTRY WinMain(HINSTANCE hInstance,


HINSTANCE hPrevInstance,


LPSTR lpCmdLine,


int nCmdShow)

{

WNDCLASSEX wcex;

MSG msg;



wcex.cbSize = sizeof(WNDCLASSEX);



wcex.style = CS_HREDRAW | CS_VREDRAW;

wcex.lpfnWndProc = (WNDPROC)WndProc;

wcex.cbClsExtra = 0;

wcex.cbWndExtra = 0;

wcex.hInstance = hInstance;

wcex.hIcon = 0;

wcex.hCursor = LoadCursor(NULL, IDC_ARROW);

wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW);

wcex.lpszMenuName = 0;

wcex.lpszClassName = "test";

wcex.hIconSm = 0;



RegisterClassEx(&wcex);



HWND hWnd = CreateWindow("test", "test",
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 150, 150, NULL,
NULL, hInstance, NULL);



if (!hWnd)

{

MessageBox(0, "Impossible", 0, 0);

return FALSE;

}



ShowWindow(hWnd, SW_SHOW);

UpdateWindow(hWnd);



while (GetMessage(&msg, NULL, 0, 0))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}



return 0;

}



Si tu trouves pourquoi dit le moi ca m'interresse, le probleme viens de ton remplissage de tableau ??
0
SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 15
11 avril 2006 à 19:26
tmp = (150-y-1)*150+3*x
C ça l'erreure. Tu le fais correctement dans ton code toi
tmp = (150-y-1)*bytewidth+3*x;

___________________________________________
Les plus grands esprits trouvent toujours une solution
0
SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 15
11 avril 2006 à 19:27
Car ça marche très bien maintenant.

___________________________________________
Les plus grands esprits trouvent toujours une solution
0
SAKingdom Messages postés 3212 Date d'inscription lundi 7 novembre 2005 Statut Membre Dernière intervention 16 février 2009 15
14 avril 2006 à 04:52
Ouais. Je vien juste de terminer de recoder ma librarie graphique et WOAW. Elle va 10 fois plus vite si c'est pas plus. Un TRÈS GRAND MERCI à toi [auteurdetail.aspx?ID=255292 SnOOpss]
ta patiente et ton aide mon été très précieuse.

___________________________________________
Les plus grands esprits trouvent toujours une solution
0
Rejoignez-nous