• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

166 Neutral

About Kevn

  • Rank
  1. Problems Initiating DirectX 11

    That fixed it, thank you! :)   Sorry about the error checking. I did have some error checking in place, although probably nowhere near what I should be doing. I know now it was a mistake but I removed the error checks before posting thinking that it would reduce the amount of code people had to read through to help me. 
  2. the code breaks at the  pSwapChain->GetBuffer() function when I try to compile it. I believe the swapchain isn't getting created and I am not sure how to fix it . Also, I did get it to compile one time and for some reason the blue window created didn't respond to me trying to drag it around the screen or close it.    My code:  #include <Windows.h> #include <D3D11.h>   D3D_DRIVER_TYPE pd3dDriverType = D3D_DRIVER_TYPE_HARDWARE; ID3D11Device* pd3dDevice; ID3D11DeviceContext* pd3dImmediateContext; IDXGISwapChain* pSwapChain; ID3D11Texture2D* pDepthStencilBuffer; ID3D11RenderTargetView* pRenderTargetView; ID3D11DepthStencilView* pDepthStencilView;   UINT m4xMsaaQuality = 0; bool enable4xMsaa; int clientWidth = 800; int clientHeight = 600; const float blue[4] = { 0.0f, 0.0f, 1.0f, 0.0f };   LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); void InitWindow(WNDCLASSEX&, HWND&, HINSTANCE, int); bool InitDirect3D(HWND&);   int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {   WNDCLASSEX wc; HWND hwnd;  MSG msg;    InitWindow(wc, hwnd, hInstance, nCmdShow); InitDirect3D(hwnd);   while (GetMessage(&msg, NULL, 0, 0) > 0) { if (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else { pd3dImmediateContext->ClearRenderTargetView(pRenderTargetView, blue); pd3dImmediateContext->ClearDepthStencilView(pDepthStencilView, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL , 1.0f, 0);   pSwapChain->Present(0, 0); } }   return msg.wParam;  }   LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { switch (msg)   { case WM_CLOSE: DestroyWindow(hwnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefWindowProc(hwnd, msg, wParam, lParam); }   return 0; }   void InitWindow(WNDCLASSEX& wc, HWND& hwnd, HINSTANCE hInstance, int nCmdShow) { wc.cbSize = sizeof(WNDCLASSEX);  wc.style = 0; wc.lpfnWndProc = WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); wc.lpszMenuName = NULL; wc.lpszClassName = (const char*)"MyWindow"; wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);   hwnd = CreateWindowEx(  WS_EX_CLIENTEDGE, (const char*)"MyWindow", "First Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, clientWidth, clientHeight, NULL, NULL, hInstance, NULL);   ShowWindow(hwnd, nCmdShow);  UpdateWindow(hwnd);       }   bool InitDirect3D(HWND& hwnd) { D3D_FEATURE_LEVEL featureLevel; HRESULT HR = D3D11CreateDevice( 0,                  pd3dDriverType, 0,                  NULL, NULL, NULL,              D3D11_SDK_VERSION, &pd3dDevice, &featureLevel, &pd3dImmediateContext);   pd3dDevice->CheckMultisampleQualityLevels(DXGI_FORMAT_R8G8B8A8_UNORM, 4, &m4xMsaaQuality);   DXGI_SWAP_CHAIN_DESC sd; sd.BufferDesc.Width = clientWidth; sd.BufferDesc.Height = clientHeight; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; if (enable4xMsaa) { sd.SampleDesc.Count = 4; sd.SampleDesc.Quality = m4xMsaaQuality - 1; } else { sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; } sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = hwnd; sd.Windowed = true; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Flags = 0;   IDXGIDevice* dxgiDevice = 0; pd3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);   IDXGIAdapter* dxgiAdapter = 0; dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&dxgiAdapter);   IDXGIFactory* dxgiFactory = 0; dxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&dxgiFactory);   dxgiFactory->CreateSwapChain(pd3dDevice, &sd, &pSwapChain);   dxgiDevice->Release(); dxgiAdapter->Release(); dxgiFactory->Release();   ID3D11Texture2D* backBuffer; pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer)); pd3dDevice->CreateRenderTargetView(backBuffer, 0, &pRenderTargetView);   backBuffer->Release();   D3D11_TEXTURE2D_DESC depthStencilDesc; depthStencilDesc.Width = clientWidth; depthStencilDesc.Height = clientHeight; depthStencilDesc.MipLevels = 1; depthStencilDesc.ArraySize = 1; depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; if (enable4xMsaa) { depthStencilDesc.SampleDesc.Count = 4; depthStencilDesc.SampleDesc.Quality = m4xMsaaQuality - 1; } else { depthStencilDesc.SampleDesc.Count = 1; depthStencilDesc.SampleDesc.Quality = 0; } depthStencilDesc.Usage = D3D11_USAGE_DEFAULT; depthStencilDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL; depthStencilDesc.CPUAccessFlags = 0; depthStencilDesc.MiscFlags = 0;   pd3dDevice->CreateTexture2D(&depthStencilDesc, 0, &pDepthStencilBuffer); pd3dDevice->CreateDepthStencilView(pDepthStencilBuffer, 0, &pDepthStencilView);   pd3dImmediateContext->OMSetRenderTargets(1, &pRenderTargetView, pDepthStencilView);   D3D11_VIEWPORT pScreenViewport; pScreenViewport.TopLeftX = 0; pScreenViewport.TopLeftY = 0; pScreenViewport.Width = static_cast<float>(clientWidth); pScreenViewport.Height = static_cast<float>(clientHeight); pScreenViewport.MinDepth = 0.0f; pScreenViewport.MaxDepth = 1.0f;   pd3dImmediateContext->RSSetViewports(1, &pScreenViewport);   return true; }  
  3. Understanding graphics pipeline

    Thank you :)
  4. Are these processes in the correct order?   1 - orthogonal or perspective projection 2 - vertex transformation 3 - clipping 4 - geometry definition 5 - rasterization 6 - texture mapping 7 - update frame buffer   My practice midterm on computer graphics listed these seven processes to be placed in order. I wasn't given any solutions to the practice midterm, so I would like to know if I am correct. If I am not, can you please point me in the right direction? Thank you.
  5. Rotating an object along a curve

    I wasn't doing it that way, but I will definitely give it a try. That way I can fall back to it if I can't figure out the derivative. Thank you.
  6. Hey, I have an object that follows a Bezier Curve(in 2D), however I need it to rotate with the tangent of the curve as it follows. Currently I am taking the derivative of the Bezier Curve with respect to a time variable u, and taking the x and y coordinates at that u derivative location to use in my rotation matrix. My matrix looks like this:   | x/r  -y/r  0  0  | | y/r   x/r  0  0  | |  0     0   1  0  | |  0     0   0  1  |   where the x and y values are the ones I took from the position at the derivative with respect to u and r = sqrt(x^2 + y^2). Then I multiply this matrix to the object matrix.   Am I going about this correctly? If so, i'm probably messing up on my derivative. If not, what should be I doing?
  7. I'm trying to make it so I can drag objects, like a box, around with my mouse in a DirectX 10/Windows application. So far I only have a plane for the floor, a few boxes, and my mouse coordinates displayed to the screen. What would be the best technique to detect when my mouse is over an object? Do I need to figure out where the box edges are in terms of screen coordinates and then do a compare with my mouse coordinates? If so, how do I determine the location of an object in terms of screen coordinates instead of my world coordinate system?
  8. Win32 Edit Control Help

    Awesome, thank you for the help.
  9. Win32 Edit Control Help

    I am working on a chat portion of a program and I am using two edit control windows and one button for the chat. One edit control window(lets call it chat window) is read only and is where all the text in the chat is displayed. The other edit control window(input window) is where the user inputs text to the chat window. The button(send) takes the text from the input window and adds it onto a string containing the text in the chat window and then updates the chat window text with that string. Now that works fine for placing the text in the chat window.However, when the string length in the chat window is greater than the window size and the scroll bar becomes active, if new text is inputed to the chat window, the scroll bar resets to the top position instead of staying scrolled all the way down. This is problematic because if two users are typing to eachother, they will have to continuely scroll down whenever something new is said to see it. So my question is, how would I go about fixing this or is there a better way to make the chat window portion then using an edit control window?
  10. my window setup: [source lang="cpp"]int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowPosition(300, 100); glutInitWindowSize(1200, 800); glutCreateWindow("Project 1"); glClearColor(0.0,0.0,0.0,0.0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0, 1200.0, 0.0, 800.0); glutDisplayFunc(display); glutMainLoop(); return 0; } [/source] And no, i haven't checked errors. I don't know how the OpenGL error checking system works. I'll go look that up now.
  11. I am trying to read the color values of a pixel on the screen, however the values I am getting from glReadPixel are whatever color my glClearColor is. Making a point: [CODE] glColor3f(1.0, 0.4, 0.2); glBegin(GL_POINTS); glVertex2i(100 , 100); glEnd(); [/CODE] code to read pixel color: [CODE] glutSwapBuffers(); vector<float> rcolors(3); glReadPixels(100, 100, 1, 1, GL_RGB, GL_FLOAT, &rcolors[0]); cout << rcolors[0] << endl << rcolors[1] << endl << rcolors[2] << endl; [/CODE] I am able to see the red pixel, but the values returned in cout are my clear color, which is black in my case.
  12. [sup]not sure what that means [img]http://public.gamedev.net//public/style_emoticons/default/sad.png[/img] [/sup] [sup]Well, I got my program to draw a line one pixel at a time using glDrawPixels. Only it repeats the same line over and over to the right and left of the line I told it to draw. So like if I told it to draw a line from position (100,100) to (600,600). there will be a line there but then another like from (300,100) to (900, 600). and another so many pixels to the right and left in the x direction over.[/sup] [sup]the code in question, the linebres just uses a line algorithm that calls setPixel however many times needed to draw the line: [/sup] [sup][CODE] struct RGBType { float r; float g; float b; }; RGBType *pixel_buffer = new RGBType[800 * 1200]; using namespace std; int window_height = 800; int window_width = 1200; void setPixel(int x, int y) { pixel_buffer[800*y + x].r=0.5; pixel_buffer[800*y + x].g=0.5; pixel_buffer[800*y + x].b=0.5; } void display(void) { glClearColor(1.0f, 1.0f, 1.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); lineBres(100, 100, 600, 600); glDrawPixels(window_width, window_height, GL_RGB, GL_FLOAT, pixel_buffer); glutSwapBuffers(); delete[] pixel_buffer; glLoadIdentity(); } int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitWindowSize (window_width, window_height); glutInitWindowPosition (100,100); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutCreateWindow ("Project 1"); glViewport(0, 0, 800, 1200); glMatrixMode(GL_MODELVIEW); glLoadIdentity( ); glMatrixMode(GL_PROJECTION); glLoadIdentity( ); gluOrtho2D(0.0, 800.0, 0.0, 1200.0); glutDisplayFunc(display); glutMainLoop(); return 0; } [/CODE][/sup]
  • Advertisement