• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

PhillipClark

Members
  • Content count

    13
  • Joined

  • Last visited

Community Reputation

119 Neutral

About PhillipClark

  • Rank
    Member
  1. Gotcha, so I guess that should explain why the light does not appear to be on the z-axis like it should be, it is instead a bit to the left. When you say to send the world position to the pixel shader, do you mean in place of the one I'm already sending, or as an extra? EDIT: Just updated my code and all of a sudden everything works like a charm! Thanks, dude, and thanks to the guy who first mentioned it, I was just too thick-headed to think about passing another position to the pixel buffer. I've definitely learnt my lesson about mixing world/view/proj spaces [img]http://public.gamedev.net//public/style_emoticons/default/happy.png[/img] That being said, is there a more elegant way to handle this instead of passing two positions?
  2. Thanks for the suggestions, especially the tip about using input.norm.xyz, I feel ignorant now. So, letting HLSL align the buffer automatically should be okay? My old code was float3 for the vertex shader input, but I got paranoid and switched to float4 [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] Is it okay for the input position to be float3, since it can only be passed to the pixel shader as a float4? Should I always set the w-component to zero when I don't need it?
  3. I actually just discovered that if I move my light source a ridiculous distance away (z value of -5000.0) then it works properly. I'm cool with this, but I'm really curious as to why it would not work at a distance that should have given the object enough room, and of course I would like to be able to set my light position to normal values without having to multiply by 5000.
  4. I just added the two things you said in your first post, to make sure the normal is truly normalized at all steps. Unfortunately, it did not fix the bug. Could you further explain your last post concerning world space light position vs surface? In the simple lighting examples I've seen on the internet they have made no distinction between the different view spaces when doing lighting in the pixel shader, yet their lighting was displayed correctly. [size=5][b][u]Updated normal transform in vertex shader:[/u][/b][/size] [CODE] float4 tmp_norm = float4( input.norm.x, input.norm.y, input.norm.z, 0.0 ); output.norm = mul( tmp_norm , world_matrix ); output.norm = normalize( output.norm ); [/CODE] [size=5][b][u]Updated normal declaration in pixel shader:[/u][/b][/size] [CODE] float4 norm_norm = normalize( input.norm ); float3 tmp_norm = float3( norm_norm.x, norm_norm.y, norm_norm.z ); [/CODE]
  5. I have a simple model loaded and a point light source that I am trying to get to work correctly, but it's just not happening. I have probably spent around 12 hours over the past two days trying to figure out what is wrong, and I'm starting to get really frustrated, so I thought I would ask here as a last resort. I have checked and double checked my lighting equation many times with at least 3 different sources. At the moment I am using constant lighting coefficient so that I know for a fact my object will be lit no matter what the distance. My light is EXPLICITLY fixed at the -30.0 position on the Z-axis, yet my object appears as if it is lit from a different direction. My camera is located at ( 0.0, 0.0, -20.0 ) so that I can verify the model is not swallowing the light, and it is not. The light is plenty far away from my model. I've changed the light/camera distance many times and have gotten the same result. The entire front side of my object should be lit, instead it is lit from a different angle. I use the DirectXMath library and I was VERY, VERY careful to store the const buffer matrices correctly and with the right alignment. I also made sure my HLSL byte alignment was correct by using float4. I use the row-major compiler options for HLSL so I do not need to use matrix transpose, and my code reflects that. Please give my code a look and tell me where I've gone wrong, because I obviously cannot figure it out! [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] [size=5][b][u]Bugged lighting:[/u][/b][/size] [attachment=12680:bug.jpg] [size=5][b][u]Matrix update function:[/u][/b][/size] [attachment=12677:update.jpg] [size=5][u][b]Vertex shader:[/b][/u][/size] [attachment=12678:vs.jpg] [size=5][b][u]Pixel shader:[/u][/b][/size] [attachment=12679:ps.jpg]
  6. Downloaded Asheron's Call. This is some weird stuff, man. 1999.
  7. Elizabeth Bailey and I just ordered an N64 with 7 games, ZOMG time to enjoy old times.
  8. Wow, those posts are way over my head [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] [quote name='Tsus' timestamp='1347612435' post='4980001'] Hi again, To get back to your problem, in what spaces are light_vector and input.pos? Are they both in world space? The values you reported to see anything at all are indeed a little extreme. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] And yes, in theory the attentuation won't fall down to zero. In practice, however, you just cut it off somewhere. [/quote] inpus.pos is in world space (transformed in vertex shader), but the light_vector is just raw input, no transformations. Is that correct? Here are the lighting equations I'm using, from the book "Mathematics for 3D Game Programming and Computer Graphics": [eqn]\mathcal{K}_{diffuse} = \mathcal{DA} + \mathcal{D}(\sum_{i=1}^{n}\mathcal{C}_{i}max(\mathbf{N}\bigodot\mathbf{L}_{i},0))[/eqn] D = diffuse reflection color A = ambient intensity (should this be a float or a float3?) C = light attenuation * light_color N = surface normal L = normalized light vector [eqn]\mathcal{K}_{specular} = \mathcal{S}(\sum_{i=1}^{n}\mathcal{C}_{i}max( \mathbf{R} \bigodot \mathbf{V}_{i}, 0 )^m ( \mathbf{N} \bigodot \mathbf{L} > 0 ) )[/eqn] S = specular reflection color C = light attenuation * light_color R = 2*( N dot L )*N - L V = camera vector m = specular exponent N = surface normal L = normalized light vector Here is the dropbox link to the model: [url="https://www.dropbox.com/s/ve75wd69dpl6jls/kit2.obj"]https://www.dropbox....pl6jls/kit2.obj[/url]
  9. [quote name='Tsus' timestamp='1347576196' post='4979870'] Anyway, the reason why things are getting dark is, that your light source is probably too far away. Consider a distance of 10 units in space. Squared and divided gives you 1/100 of your un-attenuated intensity. I think, things should work for you, if you make your light brighter, i.e. your variable “lightColor”. The lightColor actually stores the luminous intensity in candela (cd). A candle has about 1 candela. A 100 watt light bulb has about 130 cd. So, I guess you need rather large values. :-) By the way, your test model is quite beautiful. Is it available online? I'd like to use it in my thesis. Cheers! [/quote] So my light color, which is currently ( 1.0f, 1.0f, 1.0f ), needs to be something like ( 100.0f, 100.0f, 100.0f )? I tried this but it is still the same result. I am apparently missing some of the logic here. I'm not sure what you are talking about dividing by PI. I haven't seen any diffuse/specular calculations that use PI, unless you're talking about the actual physical model, not the real time phong model. I guess I should have specified [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img] Also my light position is at ( 5, 5, -5 ) so it's not a crazy distance away or anything. I have it coded so that I can move the light around so I should be able to move it close enough. I got the 3d model a while ago so I have no clue where it is online but I can upload it somewhere for you (no texture, just v/vn obj file). What's a good free upload place? Update: I can only get it to light the object if make the equation attenuation = 1.0f / ( d*d*0.00000075 ) or making the light color something ridiculous like ( 999999, 9999999, 99999999 ) but that's kind of silly, there has to be a better way right? Also, using that, I can't get the light to completely "fall off" no matter how far I move it away from the object.
  10. I have a diffuse+specular equation in my pixel shader, and it works pretty well except for this one issue: When I change this: [CODE]float attenuation = 1.0f / d*d;[/CODE] To this: [CODE]float attenuation = 1.0f / ( d*d );[/CODE] My model is no longer lit, and is instead the color of my ambient intensity. I find this extremely strange. The reason I want parentheses is so I can use a different attenuation function such as ( 1 + 0.045*d + 0.0075*d*d ). It also messes up if I try this: [CODE] float denominator = d*d; float attenuation = 1.0f / denominator; [/CODE] Here is my entire pixel shader. The reason for all of the "tmp_stuff" variables is to make everything "politically correct" since I have no choice but to input them as float4 due to constant buffer alignment properties. I would rather convert everything to temporary float3 rather than risk the chance of something not working right because of float4. Anyways, it shouldn't have anything to do with my current problem. I've doubled, tripled, and quad-checked my lighting equations with four different books, and I'm just baffled with this problem. [CODE] void ps( in v2p input, out float4 final_color : SV_TARGET ) { float3 ambient_intensity = float3( 0.1f, 0.1f, 0.1f ); float3 diffuse_color = float3( 0.8f, 0.8f, 0.8f); float3 specular_color = float3( 1.0f, 1.0f , 1.0f ); float3 tmp_light; tmp_light.x = light_vector.x; tmp_light.y = light_vector.y; tmp_light.z = light_vector.z; float3 norm_light = normalize( tmp_light ); float3 tmp_pos; tmp_pos.x = input.pos.x; tmp_pos.y = input.pos.y; tmp_pos.z = input.pos.z; float3 tmp_norm; tmp_norm.x = input.norm.x; tmp_norm.y = input.norm.y; tmp_norm.z = input.norm.z; float3 tmp_cam = float3( 0.0f, 0.0f, -20.0f ); // fixed view camera position // light intensity float d = distance( tmp_pos, tmp_light ); float attenuation = 1.0f/d*d; // HERE IS THE PROBLEM AREA float3 pointlight = attenuation*float3( light_color.x, light_color.y, light_color.z ); // diffuse lighting float diffuse = max( dot( tmp_norm, norm_light) , 0.0f ); float3 diffuse_final = diffuse_color*ambient_intensity + diffuse_color*pointlight*diffuse; // specular lighting float3 reflect_vect = 2*dot( tmp_norm, norm_light )*tmp_norm - norm_light; float ref_max = max( dot( reflect_vect, normalize(tmp_cam) ), 0.0f ); float spec_exponent = pow ( ref_max, 50.0f ); float3 spec_final; if( dot( tmp_norm, norm_light ) <= 0 ) { spec_final = float3( 0.0f, 0.0f, 0.0f ); } if( dot( tmp_norm, norm_light ) > 0 ) { spec_final = specular_color*pointlight*spec_exponent; } final_color = float4( diffuse_final + spec_final, 1.0f ); } [/CODE] Without parentheses: [img]http://i48.tinypic.com/357rmnq.png[/img] With parentheses: [img]http://i45.tinypic.com/70jscy.png[/img]
  11. I have the constructor default the z and alpha values if they are not inputted, so it should be able to support 2, 3, and 4D vectors in that sense. Maybe. O.o I'm probably wrong here. [EDIT] In response to your [EDIT]: That was one of the things I was thinking about, but I had no clue how to go about it. Thanks for the clarification. I'm a real noob when it comes to the format stuff. It is now working correctly! Thank you!
  12. My title says it all. I didn't change my original code at all. I only replaced the D3DXVECTOR3 class with my vec4 class. The colors of my primitives became incorect, and I am at a loss as to why. Obviously there must be an error in my vec4 class, right? I cannot seem find it, if there is one, so I was wondering if anyone here would like to take a look? My program displays a simple animated box, but it's supposed to be blue, not red! I have narrowed the problem down a little and it seems it is happening when I replace "D3DXVECTOR3" in my vertex list with "vec4" for the position. My replacement color vector for D3DXCOLOR works properly. [size="4"][b]vec4.h[/b][/size] [code]#ifndef VEC4_H #define VEC4_H class vec4 { float x, y, z, alpha; public: vec4( const float& xCoord, const float& yCoord, const float& zCoord = 0.0f, const float& alphaVal = 1.0f ); vec4( const vec4& v ); vec4& operator=( const vec4& v ); ~vec4(); float getX(); void setX( const float& xCoord ); float getY(); void setY( const float& yCoord ); float getZ(); void setZ( const float& zCoord ); float getAlpha(); void setAlpha( const float& alphaVal ); void scalarMult( const float& s ); vec4 operator+( const vec4& v )const; }; #endif[/code] [size="4"][b]vec4.cpp[/b][/size] [code]#ifndef VEC4_CPP #define VEC4_CPP #include "vec4.h" vec4::vec4( const float& xCoord, const float& yCoord, const float& zCoord, const float& alphaVal ) { x = xCoord; y = yCoord; z = zCoord; alpha = alphaVal; } vec4::vec4( const vec4& v ) { x = v.x; y = v.y; z = v.z; alpha = v.alpha; } vec4& vec4::operator=( const vec4& v ) { x = v.x; y = v.y; z = v.z; alpha = v.alpha; return *this; } vec4::~vec4() { } float vec4::getX() { return x; } void vec4::setX( const float& xCoord ) { x = xCoord; } float vec4::getY() { return y; } void vec4::setY( const float& yCoord ) { y = yCoord; } float vec4::getZ() { return z; } void vec4::setZ( const float& zCoord ) { z = zCoord; } float vec4::getAlpha() { return alpha; } void vec4::setAlpha( const float& alphaVal ) { alpha = alphaVal; } void vec4::scalarMult( const float& s ) { x = x*s; y = y*s; z = z*s; } vec4 vec4::operator+( const vec4& v )const { return vec4( x + v.x, y + v.y, z + v.z ); } #endif[/code] [size="4"][b]d3d.h[/b][/size] [code]#ifndef D3D_H #define D3D_H #include <D3D10.h> #include <D3DX10.h> #include "vec4.h" #pragma comment (lib, "d3d10.lib") #pragma comment (lib, "d3dx10.lib") struct VERTEX { vec4 Position; vec4 Color; }; class D3D { int w, h; // width, height of window ID3D10Device* dev; IDXGISwapChain* sc; ID3D10RenderTargetView* rtv; ID3D10Buffer* pBuff; ID3D10Buffer* pIndexBuff; ID3D10Effect* pEff; ID3D10EffectTechnique* pTech; ID3D10EffectPass* pPass; ID3D10InputLayout* pLayout; ID3D10EffectScalarVariable* pVariable; public: D3D( int width, int height ); void init( HWND hwnd ); void pipe(); void geo(); void render_frame(); void clean(); }; #endif[/code] [size="4"][b]d3d.cpp[/b][/size] [code]#include "d3d.h" D3D::D3D( int width, int height ) { w = width; h = height; } //################################################################################################ void D3D::init( HWND hwnd ) { DXGI_SWAP_CHAIN_DESC scd; scd.BufferCount = 1; scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; scd.BufferDesc.Height = h; scd.BufferDesc.RefreshRate.Denominator = 1; scd.BufferDesc.RefreshRate.Numerator = 60; scd.BufferDesc.Scaling = DXGI_MODE_SCALING_CENTERED; scd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE; scd.BufferDesc.Width = w; scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; scd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; scd.OutputWindow = hwnd; scd.SampleDesc.Count = 1; scd.SampleDesc.Quality = 0; scd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; scd.Windowed = true; D3D10CreateDeviceAndSwapChain( NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, NULL, D3D10_SDK_VERSION, &scd, &sc, &dev ); ID3D10Texture2D* pBackBuffer; sc->GetBuffer( 0, __uuidof( ID3D10Texture2D ), ( LPVOID* )&pBackBuffer ); dev->CreateRenderTargetView( pBackBuffer, NULL, &rtv ); pBackBuffer->Release(); dev->OMSetRenderTargets( 1, &rtv, NULL ); D3D10_VIEWPORT viewport; viewport.Height = h; viewport.MaxDepth = 0; viewport.MinDepth = 0; viewport.TopLeftX = 0; viewport.TopLeftY = 0; viewport.Width = w; dev->RSSetViewports( 1, &viewport ); } //################################################################################################ void D3D::geo() { VERTEX vvertices[] = { // position // color { vec4( -0.8f, -0.8f, 0.0f ), vec4( 0.0f, 0.0f, 1.0f, 1.0f ) }, { vec4( -0.8f, 0.8f, 0.0f ), vec4( 0.0f, 0.0f, 1.0f, 1.0f ) }, { vec4( 0.8f, 0.8f, 0.0f ), vec4( 0.0f, 0.0f, 1.0f, 1.0f ) }, { vec4( -0.8f, -0.8f, 0.0f ), vec4( 0.0f, 0.0f, 1.0f, 1.0f ) }, { vec4( 0.8f, 0.8f, 0.0f ), vec4( 0.0f, 0.0f, 1.0f, 1.0f ) }, { vec4( 0.8f, -0.8f, 0.0f ), vec4( 0.0f, 0.0f, 1.0f, 1.0f ) } }; D3D10_BUFFER_DESC vbd; vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER; vbd.ByteWidth = sizeof( VERTEX ) * 6; vbd.CPUAccessFlags = NULL; vbd.MiscFlags = NULL; vbd.Usage = D3D10_USAGE_IMMUTABLE; D3D10_SUBRESOURCE_DATA vinitData; vinitData.pSysMem = vvertices; dev->CreateBuffer( &vbd, &vinitData, &pBuff ); int ivertices[6] = { 0, 1, 2, 0, 4, 5 }; D3D10_BUFFER_DESC ibd; ibd.BindFlags = D3D10_BIND_INDEX_BUFFER; ibd.ByteWidth = sizeof( int ) * 6; ibd.CPUAccessFlags = NULL; ibd.MiscFlags = NULL; ibd.Usage = D3D10_USAGE_IMMUTABLE; D3D10_SUBRESOURCE_DATA iinitData; iinitData.pSysMem = ivertices; dev->CreateBuffer( &ibd, &iinitData, &pIndexBuff ); // use if not immutable //void* pVoid; //pBuff->Map( D3D10_MAP_WRITE_DISCARD, NULL, &pVoid ); //memcpy( pVoid, vertices, sizeof( vertices ) ); //pBuff->Unmap(); } //################################################################################################ void D3D::pipe() { D3D10_PASS_DESC passdesc; D3DX10CreateEffectFromFile( "effect.fx", NULL, NULL, "fx_4_0", NULL, NULL, dev, NULL, NULL, &pEff, NULL, NULL ); pTech = pEff->GetTechniqueByIndex( 0 ); pPass = pTech->GetPassByIndex( 0 ); pPass->GetDesc( &passdesc ); D3D10_INPUT_ELEMENT_DESC layout[2]; layout[0].AlignedByteOffset = D3D10_APPEND_ALIGNED_ELEMENT; layout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; layout[0].InputSlot = 0; layout[0].InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA; layout[0].InstanceDataStepRate = 0; layout[0].SemanticIndex = 0; layout[0].SemanticName = "POSITION"; layout[1].AlignedByteOffset = D3D10_APPEND_ALIGNED_ELEMENT; layout[1].Format = DXGI_FORMAT_R32G32B32_FLOAT; layout[1].InputSlot = 0; layout[1].InputSlotClass = D3D10_INPUT_PER_VERTEX_DATA; layout[1].InstanceDataStepRate = 0; layout[1].SemanticIndex = 0; layout[1].SemanticName = "COLOR"; dev->CreateInputLayout( layout, 2, passdesc.pIAInputSignature, passdesc.IAInputSignatureSize, &pLayout ); pVariable = pEff->GetVariableByName( "timeVar" )->AsScalar(); } //################################################################################################ void D3D::render_frame() { FLOAT color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; dev->ClearRenderTargetView( rtv, color ); dev->IASetInputLayout( pLayout ); dev->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); UINT stride = sizeof( VERTEX ); UINT offset = 0; static float time = 0.0f; time += 0.0001f; dev->IASetVertexBuffers( 0, 1, &pBuff, &stride, & offset ); dev->IASetIndexBuffer( pIndexBuff, DXGI_FORMAT_R32_UINT, 0 ); pVariable->SetFloat( time ); pPass->Apply( NULL ); dev->DrawIndexed( 6, 0, 0 ); sc->Present( NULL, NULL ); } //################################################################################################ void D3D::clean() { if( pLayout ) pLayout->Release(); if( pEff ) pEff->Release(); if( pBuff ) pBuff->Release(); if( rtv ) rtv->Release(); if( dev ) dev->Release(); if( sc ) sc->Release(); }[/code] [size="4"][b]effect.fx[/b][/size] [code]float timeVar; // a struct for the vertex shader return value struct VSOut { float4 Col : COLOR; // vertex color float4 Pos : SV_POSITION; // vertex screen coordinates }; // the vertex shader VSOut VS(float4 Col : COLOR, float4 Pos : POSITION) { VSOut Output; Output.Pos = Pos; // set the vertex position to the input's position Output.Pos.x *= sin( timeVar ); // shrink the vertex on the x-axis Output.Pos.y *= sin( timeVar ); Output.Col = Col; // set the vertex color to the input's color return Output; // send the modified vertex data to the Rasterizer Stage } // the pixel shader float4 PS(float4 Col : COLOR) : SV_TARGET { return Col; // set the pixel color to the color passed in by the Rasterizer Stage } // the primary technique technique10 Technique_0 { // the primary pass pass Pass_0 { SetVertexShader(CompileShader(vs_4_0, VS())); SetGeometryShader(NULL); SetPixelShader(CompileShader(ps_4_0, PS())); } }[/code]
  13. Again thanks for the replies. I stupidly assumed that my 8800GT supported dx11, which was exactly what was causing the crash I think.
  14. Thanks for the reply. I figured that was the case. Can you spot any errors in my D3D11CreateDeviceAndSwapChain() call? I was unsure how to handle pFeatureLevels, so that may be the incorrect part. I chose to only include one feature level (D3D_FEATURE_LEVEL_11_0), so my featurelevel count should be 1, right? EDIT: I fixed it by setting the &pFeatureLevels parameter to NULL and the FeatureLevels paramteter to NULL also. Any tips for how I can get it to work by specifying a feature level like I had tried in my source code?
  15. [code]#include <windows.h> #include <d3d11.h> HWND hwnd; HINSTANCE hInstance; D3D_FEATURE_LEVEL pFeatureLevel; IDXGISwapChain *ppSwapChain; ID3D11Device *ppDevice; ID3D11DeviceContext *ppImmediateContext; ID3D11RenderTargetView *pRenderTargetView; void InitWindow( HINSTANCE hInstance, int nCmdShow ); void InitDevice(); void Render(); LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ); int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { InitWindow( hInstance, nCmdShow ); InitDevice(); MSG msg = {0}; while( WM_QUIT != msg.message ) { if( PeekMessage( &msg, hwnd, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else Render(); } } void InitWindow( HINSTANCE hInstance, int nCmdShow ) { WNDCLASS wnd; wnd.cbClsExtra = 0; wnd.cbWndExtra = 0; wnd.hbrBackground = (HBRUSH)COLOR_WINDOW; wnd.hCursor = LoadCursor( 0, IDC_ARROW ); wnd.hIcon = LoadIcon( 0, IDI_APPLICATION ); wnd.hInstance = hInstance; wnd.lpfnWndProc = WndProc; wnd.lpszClassName = "Default"; wnd.lpszMenuName = NULL; wnd.style = CS_VREDRAW | CS_HREDRAW; RegisterClass( &wnd ); hwnd = CreateWindow( "Default", "Test", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 400, 0, 0, hInstance, 0 ); ShowWindow( hwnd, nCmdShow ); } void InitDevice() { // first fill out swap chain desc DXGI_SWAP_CHAIN_DESC sd; sd.BufferCount = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.Width = 400; sd.BufferDesc.Height = 400; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.Flags = NULL; sd.OutputWindow = hwnd; sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Windowed = true; // now create device and swap chain D3D_DRIVER_TYPE DriverType = D3D_DRIVER_TYPE_HARDWARE; D3D_FEATURE_LEVEL pFeatureLevels = D3D_FEATURE_LEVEL_11_0; if( !D3D11CreateDeviceAndSwapChain( NULL, DriverType, NULL, NULL, &pFeatureLevels, 1, D3D11_SDK_VERSION, &sd, &ppSwapChain, &ppDevice, &pFeatureLevel, &ppImmediateContext )) MessageBox( 0, "OOps", "Oops!", 0 ); // now handle the render target views for buffers ID3D11Texture2D *pBackBuffer; ppSwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), reinterpret_cast<void**>(&pBackBuffer) ); MessageBox( 0, "GetBuffer success!", "Success!", 0 ); ppDevice->CreateRenderTargetView( pBackBuffer, NULL, &pRenderTargetView ); D3D11_VIEWPORT vp; vp.Width = 400; vp.Height = 400; vp.MaxDepth = 1.0f; vp.MinDepth = 0.0f; vp.TopLeftX = 0; vp.TopLeftY = 0; ppImmediateContext->RSSetViewports( 1, &vp ); } void Render() { // Just clear the backbuffer float ClearColor[4] = { 0.0f, 0.125f, 0.3f, 1.0f }; //red,green,blue,alpha ppImmediateContext->ClearRenderTargetView( pRenderTargetView, ClearColor ); ppSwapChain->Present( 0, 0 ); } LRESULT CALLBACK WndProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam ) { PAINTSTRUCT ps; HDC hdc; switch( msg ) { case WM_CREATE: return 0; case WM_KEYDOWN: switch( wParam ) { case VK_LEFT: SetWindowText( hwnd, "pressed left arrow key!" ); return 0; case VK_RIGHT: SetWindowText( hwnd, "pressed right arrow key!" ); return 0; case VK_DOWN: SetWindowText( hwnd, "pressed down arrow key!" ); return 0; case VK_UP: SetWindowText( hwnd, "pressed up arrow key!" ); return 0; case VK_ESCAPE: PostQuitMessage( 0 ); return 0; } case WM_KEYUP: { SetWindowText( hwnd, "Test" ); return 0; } case WM_DESTROY: { PostQuitMessage( 0 ); return 0; } } return DefWindowProc( hwnd, msg, wParam, lParam ); }[/code] Says I have an access violation when I execute ppSwapChain->GetBuffer. Any ideas?