Amaz1ng

Members
  • Content count

    63
  • Joined

  • Last visited

Community Reputation

131 Neutral

About Amaz1ng

  • Rank
    Member
  1. I got dbl to work by simply passing "fp" as a reference (i think) like this &(fp).  such a simple thing   =/   I guess i can move on from function ptrs now #include <iostream> #include <cassert> using namespace std; #define DEF(X) double * X(int y) { \ double z = (double)3.55+y; \ double * ptr = &z; \ cout << "inside func " #X << ". Returning a dbl ptr with *ptr value of " \ << *ptr << endl; return ptr;} DEF(a); DEF(b); DEF(c); /* a pointer to an array of 3 pointers to functions that take an int and return a double pointer */ double * (*fp[])(int) = {a,b,c}; /* pointer to function that takes an int and returns a pointer to a function that takes a double ptr and returns a pointer to an array of 3 pointers to functions that take an int and return a double pointer */ double * (*(*(*(*f1)(int))(double *))[3])(int); /* a function that takes a double ptr and returns a pointer to an array of 3 pointers to functions that take an int and return a double pointer */ double * (*(*dbl(double *))[3])(int) { cout << "inside dbl" << endl; return &(fp); } /* function that takes an int and returns a pointer to a function that takes a double ptr and returns a pointer to an array of 3 pointers to functions that take an int and return a double pointer */ double *(*(*(*func(int))(double *))[3])(int) { cout << "inside func" << endl; return dbl; } int main() { /* char choice = 'c'; double * ptr; ptr = (*fp[choice - 'a'])(5); assert(ptr != NULL); */ f1 = func; double * (*(*(*adbl)(double *))[3])(int); //pointer to store the pointer to function from f1 adbl = f1(3); double * x = NULL; adbl(x); cin.get(); }
  2. how do I create a small multiplayer game?

    beej guide is pretty good. I havent found any resources specific to games yet though. 
  3. #include <iostream> #include <cstdlib> using namespace std; #define DEF(X) double * X(int y) { \ double z = (double)3.55+y; \ double * ptr = &z; \ cout << "inside func " #X << ". Returning a dbl ptr with *ptr value of " \ << *ptr << endl; return ptr;} DEF(a); DEF(b); DEF(c); typedef double * (*fp)(int); fp arrf[] = {a,b,c}; fp * fptr = arrf; fp * func(int x) { cout << "inside func." << endl; return fptr; } int main() { fp * lol; lol = func(5); *lol[0](3); *lol[1](4); *lol[2](5); cin.get(); } i guess that works lol. I don't know what i was trying to do in the 1st post. Thanks for the typedef hint tho.
  4. I tried this code and it seems to check out when i type it into cdecl.org but the function "dbl" gives me a compile error when i try to return a pointer to an array of function pointers. Am I defining "fp" right?    #include <iostream> #include <cassert> using namespace std; #define DEF(X) double * X(int y) { \ double z = (double)3.55+y; \ double * ptr = &z; \ cout << "inside func " #X << ". Returning a dbl ptr with *ptr value of " \ << *ptr << endl; return ptr;} DEF(a); DEF(b); DEF(c); /* a pointer to an array of 3 pointers to functions that take an int and return a double pointer */ double * (*fp[])(int) = {a,b,c}; /* pointer to function that takes an int and returns a pointer to a function that takes a double ptr and returns a pointer to an array of 3 pointers to functions that take an int and return a double pointer */ double * (*(*(*(*f1)(int))(double *))[3])(int); /* a function that takes a double ptr and returns a pointer to an array of 3 pointers to functions that take an int and return a double pointer */ double * (*(*dbl(double *))[3])(int) { cout << "inside dbl" << endl; return fp; } /* function that takes an int and returns a pointer to a function that takes a double ptr and returns a pointer to an array of 3 pointers to functions that take an int and return a double pointer */ double *(*(*(*func(int))(double *))[3])(int) { cout << "inside func" << endl; return dbl; } int main() { /* char choice = 'c'; double * ptr; ptr = (*fp[choice - 'a'])(5); assert(ptr != NULL); */ cin.get(); } This is the error it gives lol.....   cannot convert from 'double *(__cdecl *[3])(int)' to 'double *(__cdecl *(*)[3])(int)   -edit- i dont think fp is actually a "pointer to an array of function pointers" but its just an "array of function pointers". But I don't know how to make it an actual pointer, I keep getting errors.
  5. I saw in beej network guide some code that packs a int into a char and I didnt understand some things about it so I was just playing around with it and for one reason or another I moved the snippet directly into main. I found out it doesn't work right when I do that. Notice it outputs a really big number if I do the operations of the pack functions in main. Any particular reason why? #include <iostream> #include <bitset> #include <limits> using namespace std; void packi32(unsigned char *buf, unsigned long i) { *buf++ = i>>24; *buf++ = i>>16; *buf++ = i>>8; *buf++ = i; //cout << buf[0] << " " << buf[1] << " " << buf[2] << " " << buf[3] << endl; } unsigned long unpacki32(unsigned char *buf) { return (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3]; } int main() { unsigned char * buf = new unsigned char[4]; unsigned long i = 254; unsigned long result = 0; *buf++ = i >> 24; *buf++ = i >> 16; *buf++ = i >> 8; *buf++ = i; result = unpacki32(buf); cout << result << endl; memset(buf, 0, sizeof(buf)); packi32(buf, i); result = unpacki32(buf); cout << result; cin.get(); }
  6. Profits vs Time Investment in Game Dev

    I hear ya. I actually gave up with games and programming in general...now I'm pursuing a bachelors of pharmacy.
  7. Minecraft

    The minecraft concept has been around for like 7-8 years atleast. I remember playing warcraft 3 mods that are pretty much mirrors of the minecraft gameplay. That particular concept of "building a fortress before the baddies come out at night" isn't new by any means. I guess that guy just found some formula that "clicked" with people...now he's a millionaire a few times over.
  8. Behold, the quintessential noob

    Hey, working with Unity and Photon is HARD. But I'd be interested to see exactly what your ideas are about a game.
  9. Internet Bandwidth

    My old hughesnet plan was much worse. Try dealing with a 375mb limit per 24 hrs, download speeds averaging 90kpbs, and uploads that never broke like 6.0kbps - all for $90/month.
  10. Algebra calculators?

    You can buy a TI-8x calculator. I have one and it can do pretty much anything. http://www.amazon.com/Texas-Instruments-TI-89-Titanium-Calculator/dp/B0001EMLZ2/ref=sr_1_1?ie=UTF8&qid=1308529643&sr=8-1
  11. Hey I am following along with Frank Lunas book, and I tried to do one of the excercises which was to make a pyramid. I'm pretty sure that this has some problems because it looks like a side is missing or something but here is my code: [code] #include <D3DX10.h> #include <windows.h> #include <tchar.h> #include <stdio.h> /*Vertex Structures*/ struct Vertex { D3DXVECTOR3 POSITION; D3DXVECTOR3 COLOR; }; /*Function Decs*/ bool initWindow(HWND*,HINSTANCE,int,int); LRESULT CALLBACK wndProc(HWND, UINT, WPARAM, LPARAM); void Error(LPCWSTR); void Error(char*); void initD3D(); void render(); void InitBuffersAndLayouts(); /*Window Vars*/ HWND g_hWnd = NULL; int windowWidth = 800; int windowHeight = 600; /*DirectX Core Interfaces*/ ID3D10Device *g_pDevice; ID3D10Blob *g_pBlob; ID3D10InputLayout *g_pLayout; ID3D10RasterizerState *g_pRasterState; IDXGISwapChain *g_pSwapChain; /*DirectX Resource Interfaces*/ ID3D10Buffer *g_pVertexBuffer; ID3D10Buffer *g_pIndexBuffer; ID3D10Texture2D *g_pBackBuffer; ID3D10RenderTargetView *g_pRenderTarget; /*DirectX Effect Interfaces*/ ID3D10EffectTechnique *g_pTechnique; ID3D10Effect *g_pEffect; /*DirectX Shader Interfaces*/ ID3D10VertexShader *g_pVertexShader; /*Matrix Data From Shader*/ ID3D10EffectMatrixVariable * g_pWorld; ID3D10EffectMatrixVariable * g_pView; ID3D10EffectMatrixVariable * g_pProjection; D3DXMATRIX g_World; D3DXMATRIX g_View; D3DXMATRIX g_Projection; /******************************************************************* * Initialize Main Window ********************************************************************/ bool initWindow(HWND &hWnd, HINSTANCE hInstance, int width, int height) { WNDCLASSEX wcex; 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+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = TEXT("DX10"); wcex.hIconSm = 0; RegisterClassEx(&wcex); //Resize the window RECT rect = { 0, 0, width, height }; AdjustWindowRect(&rect, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, FALSE); //create the window from the class above //disable resizing and correct for extra width and height g_hWnd = CreateWindow( L"DX10", L"Amaz1ng", WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, CW_USEDEFAULT, CW_USEDEFAULT, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL); //window handle not created if (!g_hWnd) return false; //if window creation was successful ShowWindow(g_hWnd, SW_SHOW); UpdateWindow(g_hWnd); return true; } /******************************************************************* * Window Message Processing ********************************************************************/ LRESULT CALLBACK wndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { // Allow the user to press the escape key to end the application case WM_KEYDOWN : switch(wParam) { // Check if the user hit the escape key case VK_ESCAPE : PostQuitMessage(0); break; } break; // The user hit the close button, close the application case WM_DESTROY : PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam); } /******************************************************************* * Main Entry Point ********************************************************************/ int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow ) { // Set up the application window if ( !initWindow(g_hWnd, hInstance, windowWidth, windowHeight)) return 0; initD3D(); InitBuffersAndLayouts(); // Main message loop MSG msg = {0}; while (WM_QUIT != msg.message) { while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE) { TranslateMessage(&msg); DispatchMessage(&msg); } render(); } return (int) msg.wParam; } /******************************************************************* * Initialize Directx10 ********************************************************************/ void initD3D() { HRESULT HR = S_OK; /*Device and Swap Chain Creation*/ DXGI_SWAP_CHAIN_DESC sd; ZeroMemory(&sd, sizeof(DXGI_SWAP_CHAIN_DESC)); sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 2; sd.OutputWindow = g_hWnd; sd.Windowed = true; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.SampleDesc.Quality = 0; sd.SampleDesc.Count = 1; sd.BufferDesc.Width = windowWidth; sd.BufferDesc.Height = windowHeight; HR = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_DEBUG, D3D10_SDK_VERSION, &sd, &g_pSwapChain, &g_pDevice); if(HR != S_OK) Error(L"Swap Chain and device creation fucked up"); /*Setup the backbuffer and render target*/ HR = g_pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (void**)&g_pBackBuffer); if(HR != S_OK) Error(L"Getting the backbuffer....fucked up"); HR = g_pDevice->CreateRenderTargetView(g_pBackBuffer, NULL, &g_pRenderTarget); if(HR != S_OK) Error(L"Creating the render target...fawked up"); g_pBackBuffer->Release(); g_pDevice->OMSetRenderTargets(1, &g_pRenderTarget, NULL); /*Create and set the viewports*/ D3D10_VIEWPORT vp; vp.Height = windowHeight; vp.MaxDepth = 1; vp.MinDepth = 0; vp.TopLeftX = 0; vp.TopLeftY = 0; vp.Width = windowWidth; g_pDevice->RSSetViewports(1, &vp); } /******************************************************************* * Rendering and Drawing ********************************************************************/ void render() { g_pDevice->ClearRenderTargetView(g_pRenderTarget, D3DXCOLOR(1.0f,0.5f,0.3f,1)); float t = GetTickCount() / 1000.0f; D3DXMatrixRotationY(&g_World, t); g_pWorld->SetMatrix(( float* )&g_World); g_pView->SetMatrix(( float* )&g_View); g_pProjection->SetMatrix(( float* )&g_Projection); D3D10_TECHNIQUE_DESC tDesc; g_pTechnique->GetDesc(&tDesc); for(UINT i = 0; i < tDesc.Passes; ++i) { g_pTechnique->GetPassByIndex(i)->Apply(0); g_pDevice->DrawIndexed(18, 0, 0); } g_pSwapChain->Present(0,0); } /******************************************************************* * Error Output ********************************************************************/ void Error(LPCWSTR msg) { MessageBox(g_hWnd, msg, L"Error", MB_ICONERROR); } void Error(char * msg) { MessageBoxA(g_hWnd, msg, "Error", MB_ICONERROR); } /******************************************************************* * Buffers (vertex Data), Layouts, and Effect File Data Initialization ********************************************************************/ void InitBuffersAndLayouts() { /*Creating the input layout and getting the effect passes from the shader file*/ HRESULT HR = S_OK; D3D10_INPUT_ELEMENT_DESC vLayout[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0}, {"COLOR", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0,sizeof(D3DXVECTOR3), D3D10_INPUT_PER_VERTEX_DATA, 0}, }; D3D10CreateBlob(100, &g_pBlob); if(FAILED (D3DX10CreateEffectFromFile(L"shaderz.fx", NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, g_pDevice, NULL, NULL, &g_pEffect, &g_pBlob, NULL) )) { Error(L"D3DX10CreateEffectFromFile failed"); Error((char*)g_pBlob->GetBufferPointer()); } g_pTechnique = g_pEffect->GetTechniqueByName("Render"); D3D10_PASS_DESC passDesc; g_pTechnique->GetPassByIndex(0)->GetDesc(&passDesc); UINT elements = sizeof(vLayout) / sizeof(vLayout[0]); HR = g_pDevice->CreateInputLayout(vLayout, elements, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &g_pLayout); if(HR != S_OK) Error(L"Creating the input layout failed"); g_pDevice->IASetInputLayout(g_pLayout); /*Creating and setting the actual Vertex/Index Buffers*/ Vertex vertices[] = { D3DXVECTOR3(-2.0f, 0.0f, 3.0f ), //position a D3DXVECTOR3(0.9f, 0.9f, 0.9f), //color D3DXVECTOR3(2.0f, 0.0f, 3.0f), //position b D3DXVECTOR3(0.1f, 5.1f, 0.1f), //color D3DXVECTOR3(2.0f, 0.0f, -1.0f), //position c D3DXVECTOR3(0.1f, 0.1f, 8.1f), //color D3DXVECTOR3(-2.0f, 0.0f, -1.0f), //position d D3DXVECTOR3(0.1f, 0.1f, 8.1f), //color D3DXVECTOR3(0.0f, 2.0f, 1.0f), //position f, tip of pyramid D3DXVECTOR3(0.1f, 0.1f, 8.1f), //color }; D3D10_BUFFER_DESC vDesc; vDesc.ByteWidth = sizeof(vertices) * 5; vDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER; vDesc.CPUAccessFlags = 0; vDesc.MiscFlags = 0; vDesc.Usage = D3D10_USAGE_DEFAULT; D3D10_SUBRESOURCE_DATA dat; dat.pSysMem = vertices; dat.SysMemPitch = 0; dat.SysMemSlicePitch = 0; HR = g_pDevice->CreateBuffer(&vDesc, &dat, &g_pVertexBuffer); if(HR != S_OK) Error(L"Creating the Vertex Buffer Failed"); UINT stride = sizeof(Vertex); UINT offset = 0; g_pDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer, &stride, &offset); g_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST); int indices[] = { 0, 4, 3, 3, 4, 2, 2, 4, 1, 0, 4, 1, 0, 1, 2, 0, 2, 3 }; D3D10_BUFFER_DESC iDesc; iDesc.ByteWidth = sizeof(indices) * 18; iDesc.BindFlags = D3D10_BIND_INDEX_BUFFER; iDesc.CPUAccessFlags = 0; iDesc.Usage = D3D10_USAGE_DEFAULT; iDesc.MiscFlags = 0; D3D10_SUBRESOURCE_DATA iData; iData.pSysMem = indices; iData.SysMemPitch = 0; iData.SysMemSlicePitch = 0; HR = g_pDevice->CreateBuffer(&iDesc, &iData, &g_pIndexBuffer); if(HR != S_OK) Error("Index buffer creation failed"); g_pDevice->IASetIndexBuffer(g_pIndexBuffer, DXGI_FORMAT_R32_UINT, 0); /*Get and initialize matrix data from shader file*/ g_pWorld = g_pEffect->GetVariableByName("World")->AsMatrix(); g_pView = g_pEffect->GetVariableByName("View")->AsMatrix(); g_pProjection = g_pEffect->GetVariableByName("Projection")->AsMatrix(); /*Initialize the variables that will be used to interface with the shader file.*/ D3DXMatrixIdentity(&g_World); D3DXMatrixPerspectiveFovLH(&g_Projection, ( float )D3DX_PI * 0.5f, windowWidth / (float)windowHeight, 0.1f, 100.0f); D3DXVECTOR3 Eye( 0.0f, 1.0f, -5.0f ); D3DXVECTOR3 At( 0.0f, 0.0f, 3.0f ); D3DXVECTOR3 Up( 0.0f, 0.3f, 0.0f ); D3DXMatrixLookAtLH( &g_View, &Eye, &At, &Up ); } [/code] And the Shader [code] matrix World; matrix View; matrix Projection; struct PS_INPUT { float4 Pos : SV_POSITION; float4 Color : COLOR; }; //-------------------------------------------------------------------------------------- // Vertex Shader //-------------------------------------------------------------------------------------- PS_INPUT VS( float4 Pos : POSITION, float4 Color : COLOR ) { PS_INPUT psInput = (PS_INPUT)0; psInput.Pos = mul(Pos, World); psInput.Pos = mul(psInput.Pos, View); psInput.Pos = mul(psInput.Pos, Projection); psInput.Color = Color; return psInput; } //-------------------------------------------------------------------------------------- // Pixel Shader //-------------------------------------------------------------------------------------- float4 PS( PS_INPUT psInput ) : SV_Target { return psInput.Color; } //-------------------------------------------------------------------------------------- technique10 Render { pass P0 { SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); } } [/code] I'm gonna play around w/ it a bit more but I want to ask anyway - what can I do so that the sides are not transparent? And what do you guys think is the cause of the pyramid missing a side?
  12. jokes

    Are you on drugs?
  13. A bear flew through someone's car, from front to back

    Oh no - Chuck Norris' pet flying bear got lose!
  14. Have anyone here tried BizSpark?

    I don't know about BizSpark but the program looks similar to the Microsoft Dreamspark program which I participated in. With Dreamspark, they give students completely free software ranging from VS2010 to Microsoft Expression Studio. The rationale behind it is to expose people to and get them comfortable with Microsoft products. They are trying to create loyalty to the Microsoft brand so I can fully see Bizspark being similar. Just make sure to read over any agreements you may come across because I'm not saying they are 100% the same.
  15. [code] int D3DApp::countAdapters() { IDXGIFactory * fac; IDXGIAdapter * adapter; int i = 0; HRESULT h = S_OK; h = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&fac); if(h != S_OK) return -1; while(fac->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND) { ++i; } adapter->Release(); return i; } [/code] I'm getting unresolved external on CreateFactory. Any ideas? I think I have all the includes set correctly.