Jump to content

50cent

Members
  • Posts

    10
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

50cent's Achievements

Newbie

Newbie (1/14)

10

Reputation

  1. Un mic sample cu WebGL WebGL Aquarium
  2. function getvocals($string) { $vocale=array("a","e","i","o","u"); $nr=0; for($i=0;$i<strlen($string);++$i) if(in_array(strtolower($string[$i]),$vocale)) ++$nr; return $nr; }
  3. 50cent

    Parola

    Folosesti combinatia urmatoare BringWindowToTop(form); EnableWindow(hWnd,FALSE); Va aduce form-ul in prim plan si dezactiveaza fereastra principala Daca parola e corecta ->EnableWindow(hWnd,TRUE);
  4. 50cent

    open cl

    OpenCL (Open Computing Language) este un nou standard de programare care se executa in paralel pe multiple platforme(CPU ,GPU, DSP). Programele openCL au de obicei un fisier extern numit kernel in care se gasesc functii care urmeaza sa fie executate in paralel. Am sa va arat un mic programel openCL care ia 2 vectori si care salveaza in alt vector minmul dintre elementele din a si b de pe fiecare pozitie #include <stdio.h> #include <stdlib.h> #include <conio.h> #include <iostream> using namespace std; //header si .lib open cl #include <CL/cl.h> #pragma comment (lib,"OpenCL.lib") //globale const int ELEMENTS = 200; //prototip functii char* readSource(const char *sourceFilename); void afisare(int *,int n); int main(int argc, char ** argv) { size_t datasize = sizeof(int)*ELEMENTS;//dimensiune memorie de alocat int *A, *B;//vectori de intrare int *C;//vectorul final /* alocare memorie */ A = (int*)malloc(datasize); B = (int*)malloc(datasize); C = (int*)malloc(datasize); //initializare for(int i =0; i < ELEMENTS; ++i) { A[i] = rand() % 100 + 1; B[i] = rand() % 100 + 1; } afisare(A,ELEMENTS); afisare(B,ELEMENTS); // variabile specifice open cl cl_int status; //folosita pentru a verifica erori pentru majoritatea functiilor cl_uint numPlatforms = 0; //numarul de platforme cl_platform_id *platforms; //pointer catre platforme cl_uint numDevices = 0; //numarul de dispozitive open cl cl_device_id *devices; //pointer catre dispozitive cl_context context; //contextul open cl cl_command_queue cmdQueue0,cmdQueue1;//stiva de comenzi cl_mem d_A0, d_A1, d_B0, d_B1; // bufferele de intrare cl_mem d_C0, d_C1; // buffere de iesire cl_program program; //pointer catre programul open cl(folosit pentru executia kernel) cl_kernel kernel0, kernel1; //kernel cl_int buildErr; //folosit pentru a stoca erorile de compilare kernel clGetPlatformIDs(0, NULL, &numPlatforms);//numarul de platforme platforms = (cl_platform_id*)malloc(numPlatforms*sizeof(cl_platform_id));//aloca memorie in functie de platformele gasite clGetPlatformIDs(numPlatforms, platforms, NULL);//stocheaza platofrmele in pointer status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL, 0, NULL, &numDevices);//numarul de dispozitive if(numDevices < 2) { printf("Cel putin 2 dispozitive open cl, (%d gasite).\n", numDevices);//avem nevoie de cpu+gpu exit(-1); } devices = (cl_device_id*)malloc(numDevices*sizeof(cl_device_id));//aloca memorie in functie de dispozitive gasite status = clGetDeviceIDs(platforms[0], CL_DEVICE_TYPE_ALL, numDevices, devices, NULL);//stocheaza dispozitivele in pointer context = clCreateContext(NULL, numDevices, devices, NULL, NULL, &status);//creare context cmdQueue0 = clCreateCommandQueue(context, devices[0], 0, &status); cmdQueue1 = clCreateCommandQueue(context, devices[1], 0, &status); //alocare buffere pentru fiecare vector(jumatate CPU jumatate GPU) //A d_A0 = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, datasize/2, A, &status); d_A1 = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, datasize/2, &A[ELEMENTS/2], &status); //B d_B0 = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, datasize/2, B, &status); d_B1 = clCreateBuffer(context, CL_MEM_READ_ONLY|CL_MEM_COPY_HOST_PTR, datasize/2, &B[ELEMENTS/2], &status); //C d_C0 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, datasize/2, NULL, &status); d_C1 = clCreateBuffer(context, CL_MEM_WRITE_ONLY, datasize/2, NULL, &status); char *source;//se retine sursa pentru kernel const char *sourceFile = "kernel.cl";//numele fisierului care contine kernelul source = readSource(sourceFile); program = clCreateProgramWithSource(context, 1, (const char**)&source, NULL, &status);//compilare kernel buildErr = clBuildProgram(program, numDevices, devices, NULL, NULL, NULL); //select este numele functiei din fisierul kernel.cl kernel0 = clCreateKernel(program, "select", &status); kernel1 = clCreateKernel(program, "select", &status); // asociere buffere cu argumentele functiei din kernel status = clSetKernelArg(kernel0, 0, sizeof(cl_mem), &d_A0); status |= clSetKernelArg(kernel0, 1, sizeof(cl_mem), &d_B0); status |= clSetKernelArg(kernel0, 2, sizeof(cl_mem), &d_C0); status = clSetKernelArg(kernel1, 0, sizeof(cl_mem), &d_A1); status |= clSetKernelArg(kernel1, 1, sizeof(cl_mem), &d_B1); status |= clSetKernelArg(kernel1, 2, sizeof(cl_mem), &d_C1); size_t globalWorkSize[1]; globalWorkSize[0] = ELEMENTS/2; // executie kernele status = clEnqueueNDRangeKernel(cmdQueue0, kernel0, 1, NULL, globalWorkSize, NULL, 0, NULL, NULL);//GPU status = clEnqueueNDRangeKernel(cmdQueue1, kernel1, 1, NULL, globalWorkSize, NULL, 0, NULL, NULL);//CPU //transfera datele din buffer in vectorul c clEnqueueReadBuffer(cmdQueue0, d_C0, CL_TRUE, 0, datasize/2, C, 0, NULL, NULL); clEnqueueReadBuffer(cmdQueue1, d_C1, CL_TRUE, 0, datasize/2, &C[ELEMENTS/2], 0, NULL, NULL); cout<<"rezultat \n"; afisare(C,ELEMENTS); //eliberare memorie clReleaseKernel(kernel0); clReleaseKernel(kernel1); clReleaseProgram(program); clReleaseCommandQueue(cmdQueue0); clReleaseCommandQueue(cmdQueue1); clReleaseMemObject(d_A0); clReleaseMemObject(d_A1); clReleaseMemObject(d_B0); clReleaseMemObject(d_B1); clReleaseMemObject(d_C0); clReleaseMemObject(d_C1); clReleaseContext(context); free(A); free(; free(C); free(source); free(platforms); free(devices); _getch(); } char* readSource(const char *sourceFilename) { FILE *fp; int size; char *source; fp = fopen(sourceFilename, "rb"); if(fp == NULL) { printf("Nu gasesc fisierul: %s\n", sourceFilename); exit(-1); } fseek(fp, 0, SEEK_END); size = ftell(fp); fseek(fp, 0, SEEK_SET); source = (char*)malloc(size+1); fread(source, 1, size, fp); source[size] = '\0'; return source; } void afisare(int *a,int n) { for(int i=0;i<n;++i) cout<<a[i]<<" "; cout<<endl; } Si fisierul kernel.cl : __kernel void select(__global int *a, __global int *b, __global int *c) { int i = get_global_id(0); c[i]=a[i]>b[i]?b[i]:a[i]; }
  5. O problema de greedy.
  6. Programul de mai jos ilustreaza controale windows de baza,scris in Windows API #include <Windows.h> //#pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") #define latime 200 #define inaltime 250 #define buton 1 #define buton2 2 #define buton3 3 LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM); int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInsatce,LPSTR lpCmdLine,int nCmdShow) { HWND hWnd; WNDCLASSEX clasa; ZeroMemory(&clasa,sizeof(WNDCLASSEX)); clasa.cbSize=sizeof(WNDCLASSEX); clasa.hbrBackground=(HBRUSH)COLOR_WINDOW; clasa.hCursor=LoadCursor(NULL,IDC_ARROW); clasa.hIcon=LoadIcon(NULL,IDI_APPLICATION); clasa.hInstance=hInstance; clasa.lpfnWndProc=WindowProc; clasa.lpszClassName=L"orton"; clasa.style=CS_VREDRAW|CS_HREDRAW; RegisterClassEx(&clasa); hWnd=CreateWindowEx(NULL,L"orton",L"orton",WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX,10,10,latime,inaltime,NULL,NULL,hInstance,NULL); ShowWindow(hWnd,nCmdShow); HFONT hFont = CreateFont(15, 0, 0, 0, FW_NORMAL, false, false, false, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, L"Lucida Sans Unicode"); HWND label=CreateWindow(L"STATIC",L"butonul 1",WS_VISIBLE|WS_CHILD|SS_EDITCONTROL,5,15,60,25,hWnd,0,hInstance,NULL); HWND label2=CreateWindow(L"STATIC",L"butonul 2",WS_VISIBLE|WS_CHILD|SS_EDITCONTROL,5,45,60,25,hWnd,0,hInstance,NULL); HWND Button=CreateWindow(L"BUTTON",L"apasa",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,60,10,50,25,hWnd,(HMENU)buton,hInstance,NULL); HWND Button2=CreateWindow(L"BUTTON",L"apasa",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,60,40,50,25,hWnd,(HMENU)buton2,hInstance,NULL); HWND Button3=CreateWindow(L"BUTTON",L"fisier",WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,110,10,80,55,hWnd,(HMENU)buton3,hInstance,NULL); HWND edit=CreateWindow(L"EDIT",L"edit box",WS_VISIBLE|WS_CHILD|WS_HSCROLL|WS_VSCROLL|ES_LEFT|ES_MULTILINE|ES_AUTOHSCROLL|ES_AUTOVSCROLL,5,90,180,130,hWnd,0,hInstance,NULL); SendMessage(Button, WM_SETFONT,(WPARAM)hFont, true); SendMessage(Button2, WM_SETFONT,(WPARAM)hFont, true); SendMessage(label, WM_SETFONT,(WPARAM)hFont, true); SendMessage(label2, WM_SETFONT,(WPARAM)hFont, true); SendMessage(edit, WM_SETFONT,(WPARAM)hFont, true); SendMessage(Button3, WM_SETFONT,(WPARAM)hFont, true); MSG mesaj={0}; while(GetMessage(&mesaj,0,0,0)) { TranslateMessage(&mesaj); DispatchMessage(&mesaj); } return mesaj.wParam; } LRESULT CALLBACK WindowProc(HWND hWnd,UINT mesaj,WPARAM wParam,LPARAM lParam) { switch(mesaj) { case WM_DESTROY: PostQuitMessage(0); break; case WM_COMMAND: if (wParam == buton) MessageBox(hWnd,L"ai apasat pe butonul 1",L"Info",MB_OK|MB_ICONINFORMATION); if (wParam == buton2) MessageBox(hWnd,L"ai apasat pe butonul 2",L"Info",MB_OK|MB_ICONINFORMATION); if (wParam == buton3) { OPENFILENAME ofn; char szFileName[MAX_PATH] = ""; ZeroMemory(&ofn, sizeof(ofn)); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = hWnd; ofn.lpstrFilter = L"Fisiere text (*.txt)\0*.txt\0All Files (*.*)\0*.*\0"; ofn.lpstrFile = (LPWSTR)szFileName; ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT; ofn.lpstrDefExt = (LPCWSTR)"txt"; if(GetOpenFileName(&ofn)) { MessageBox(hWnd,(LPCWSTR)szFileName,L"Info",MB_OK|MB_ICONINFORMATION); } } break; default : return DefWindowProc(hWnd,mesaj,wParam,lParam); break; } return 0; } decomentati linia cu #pragma comment sa vedeti ce se intampla
  7. interesant, e mai ordonat sa afisezi cu echo si apostrof
  8. 50cent

    directx11

    Urmatorul program afiseaza o fereastra si initializaeaza directx 11 #include <Windows.h> #include <d3d11.h> #include <d3dx11.h> #include <d3dx10.h> // librariile directx #pragma comment (lib, "d3d11.lib") #pragma comment (lib, "d3dx11.lib") #pragma comment (lib, "d3dx10.lib") // declarare functii void initializare(HWND); void eliberare(void); void deseneaza(void); LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);//functia de procesare mesaje windows /* variabile globale */ IDXGISwapChain *swapchain; // pointer catre interfata swap chain ID3D11Device *dev; // pointer catre interfata d3d ID3D11DeviceContext *devcon; // pointer catre dispozitivul d3d ID3D11RenderTargetView *backbuffer; // pointer catre backbuffer /* creare fereastra folosind functia WinMain */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { WNDCLASSEX clasa;//clasa windows folosita pentru afisarea ferestrei HWND hWnd;//fereastra principala DWORD stil=WS_OVERLAPPED|WS_SYSMENU|WS_MINIMIZEBOX;//stil fereastra , folositi WS_OVERLAPPEDWINDOW pentru redimensionare fereastra si buton de maximizare ZeroMemory(&clasa,sizeof(WNDCLASSEX));//seteaza NULL toti membrii WNDCLASSEX clasa.cbSize = sizeof(WNDCLASSEX);// dimensiunea structurii clasa.style = CS_HREDRAW | CS_VREDRAW;// redeseneaza fereastra daca a fost miscata clasa.lpfnWndProc = WindowProc;//functia de procesare mesaje declarata mai sus clasa.hInstance = hInstance;//instanta aplicatie clasa.hCursor = LoadCursor(NULL, IDC_ARROW);//cursor , puteti testa IDC_WAIT clasa.hbrBackground = (HBRUSH)COLOR_WINDOW;//culoare fundal fereastra clasa.lpszClassName = "directx11";//numele classei clasa.hIcon=LoadIcon(NULL,IDI_APPLICATION);//icon aplicatie, puteti testa IDI_INFORMATION RegisterClassEx(&clasa);//inregistrare clasa pt a putea fi folosita hWnd = CreateWindowEx(NULL,"directx11","primul program directx 11",stil,10,10,800,600,NULL,NULL,hInstance,NULL);//creare fereastra ShowWindow(hWnd, nCmdShow);//afisare fereastra MSG msg={0};//variabila care stocheaza mesajele windows initializare(hWnd);//apelam functia de initializare direct 3d cu parametru hWnd(fereastra principala) /* bucla principala a programului */ while( WM_QUIT != msg.message ) { if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )//daca avem mesaje care asteapta sa fie procesate { TranslateMessage( &msg );//traducem mesajul pentru a putea fi procesat de functia noastra DispatchMessage( &msg );// trimitem mesajul tradus functiei WindowProc } else { deseneaza();//altfel desenam un cadru pe ecran } } eliberare();//daca am ajuns aici inseamna ca am inchis aplicatia , deci eliberam directx return msg.wParam; } /* functia pentru procesare mesaje windows */ LRESULT CALLBACK WindowProc(HWND hWnd, UINT mesaj, WPARAM wParam, LPARAM lParam) { switch(mesaj)//procesam mesaje(de ex. daca s-a apasat o tasta putem efectua anumite actiuni) { case WM_DESTROY://necesar pentu a iesi corect din aplicatie PostQuitMessage(0); break; default: return DefWindowProc(hWnd, mesaj, wParam, lParam);//mesajele care nu ne intereseaza le lasam in seama widows sa le proceseze break; } return 0; } void initializare(HWND hWnd)//functia de initializare d3d { // declaram o structura care sa tina informatii despre swap and chain DXGI_SWAP_CHAIN_DESC scd; //setam NULL toti memmbri structurii declarate anterior ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC)); // descriem structura scd.BufferCount = 1; // un back buffer scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // folosim culoare pe 32 de biti scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // metoda de utilizare swap and chain scd.OutputWindow = hWnd; // ferastra pe care von lucra scd.SampleDesc.Count = 4; // multisample scd.Windowed = TRUE; // vom lucra in window mode // creem interfata directx folosind informatiile de mai sus D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL, D3D11_SDK_VERSION, &scd, &swapchain, &dev, NULL, &devcon); // adresa backbuffer ID3D11Texture2D *pBackBuffer; swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&pBackBuffer); // folosim adreasa backbuffer pentru a seta unde va desena directx dev->CreateRenderTargetView(pBackBuffer, NULL, &backbuffer); pBackBuffer->Release(); // setam sa deseneze pe backbuffer devcon->OMSetRenderTargets(1, &backbuffer, NULL); // declaram viewport D3D11_VIEWPORT viewport; //setam NULL toti membrii viewport ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT)); viewport.TopLeftX = 0;//coordonata x de unde incepe sa deseneze(coltul din stanga sus) viewport.TopLeftY = 0;//coordonata y de unde incepe sa deseneze(coltul din stanga sus) viewport.Width = 800;//latime viewport.Height = 600;//inaltime devcon->RSSetViewports(1, &viewport);//setam viewport } void eliberare() { // eliberam memoria folosita si inchidem directx swapchain->Release(); dev->Release(); backbuffer->Release(); devcon->Release(); } void deseneaza() { // eliberam backbuffer si setam culoarea de background devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.3f, 0.4f, 1.0f)); /* aici se poate punde cod pentru desenare pe backbuffer */ // interschimbam backbuffer cu front buffer swapchain->Present(0, 0); }
×
×
  • Create New...