Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

941 Good

About 23yrold3yrold

  • Rank

Personal Information

  • Interests
  1. 23yrold3yrold

    XNA and BasicEffect trouble

    Okay, I almost have this. I can get the colored polys working, and I moved to textured polys, which is also working, but the lighting isn't anymore. It obeys the color of the light and the ambient; I can adjust variables like that and the graphics respond accordingly. But the lighting is still flat, like I've got no normals, which leads me to believe that I set the normals up wrong or I need to do something extra for textures that I didn't for colored polys, since the old textureless cube that I set up with normals receives light perfectly. The structure: public struct VertexPositionNormalTextured { public Vector3 Position; public Vector2 TextureCoord; public Vector3 Normal; public VertexPositionNormalTextured(Vector3 position, Vector2 texCoord, Vector3 normal) { this.Position = position; this.TextureCoord = texCoord; this.Normal = normal; } public static int SizeInBytes = sizeof(float) * (3 + 2 + 3); public static VertexElement[] VertexElements = new VertexElement[] { new VertexElement( 0, sizeof(float) * 0, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Position, 0 ), new VertexElement( 0, sizeof(float) * 3, VertexElementFormat.Vector2, VertexElementMethod.Default, VertexElementUsage.TextureCoordinate, 0 ), new VertexElement( 0, sizeof(float) * 5, VertexElementFormat.Vector3, VertexElementMethod.Default, VertexElementUsage.Normal, 0 ), }; The new model initialization: poweruptexture = Content.Load<Texture2D>("powerup_l"); vertices2 = new VertexPositionNormalTextured[8]; // top vertices2[0].Position = new Vector3(-20f, -20f, 20f); vertices2[0].TextureCoord.X = 0; vertices2[0].TextureCoord.Y = 0; vertices2[0].Normal = new Vector3(0f, 0f, 0f); vertices2[1].Position = new Vector3(20f, -20f, 20f); vertices2[1].TextureCoord.X = 1; vertices2[1].TextureCoord.Y = 0; vertices2[1].Normal = new Vector3(0f, 0f, 0f); vertices2[2].Position = new Vector3(20f, 20f, 20f); vertices2[2].TextureCoord.X = 1; vertices2[2].TextureCoord.Y = 1; vertices2[2].Normal = new Vector3(0f, 0f, 0f); vertices2[3].Position = new Vector3(-20f, 20f, 20f); vertices2[3].TextureCoord.X = 0; vertices2[3].TextureCoord.Y = 1; vertices2[3].Normal = new Vector3(0f, 0f, 0f); // bottom vertices2[4].Position = new Vector3(-20f, -20f, -20f); vertices2[4].TextureCoord.X = 0; vertices2[4].TextureCoord.Y = 0; vertices2[4].Normal = new Vector3(0f, 0f, -1f); vertices2[5].Position = new Vector3(20f, -20f, -20f); vertices2[5].TextureCoord.X = 1; vertices2[5].TextureCoord.Y = 0; vertices2[5].Normal = new Vector3(0f, 0f, -1f); vertices2[6].Position = new Vector3(-20f, 20f, -20f); vertices2[6].TextureCoord.X = 0; vertices2[6].TextureCoord.Y = 1; vertices2[6].Normal = new Vector3(0f, 0f, -1f); vertices2[7].Position = new Vector3(20f, 20f, -20f); vertices2[7].TextureCoord.X = 1; vertices2[7].TextureCoord.Y = 1; vertices2[7].Normal = new Vector3(0f, 0f, -1f); texturedVertexDeclaration = new VertexDeclaration(Game1.device, VertexPositionTexture.VertexElements); indices[0] = 0; indices[1] = 1; indices[2] = 3; indices[3] = 1; indices[4] = 2; indices[5] = 3; indices[6] = 5; indices[7] = 4; indices[8] = 6; indices[9] = 5; indices[10] = 6; indices[11] = 7; The effect: basicEffect = new BasicEffect(Game1.device, null); basicEffect.Alpha = 1.0f; basicEffect.DiffuseColor = new Vector3(1f, 1f, 1f); basicEffect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f); basicEffect.SpecularPower = 1.0f; basicEffect.AmbientLightColor = new Vector3(0.5f, 0.5f, 0.5f); basicEffect.DirectionalLight0.Enabled = true; basicEffect.DirectionalLight0.DiffuseColor = Vector3.One; basicEffect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(0.5f, 0.5f, -1.0f)); basicEffect.DirectionalLight0.SpecularColor = Vector3.One; basicEffect.LightingEnabled = true; basicEffect.Texture = poweruptexture; basicEffect.TextureEnabled = true; // set up basic world view projection and the camera basicEffect.World = Matrix.Identity; basicEffect.View = Matrix.CreateLookAt(new Vector3(0, 0, 200), Vector3.Zero, Vector3.Up); Matrix m = new Matrix(); Matrix.CreateOrthographic(800, 450, 0.1f, 1000, out m); basicEffect.Projection = m; And finally, the drawing: Game1.device.RenderState.CullMode = CullMode.None; Game1.device.RenderState.DepthBufferEnable = true; basicEffect.Begin(); foreach (Powerup e in powerupList) { foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); Game1.device.VertexDeclaration = texturedVertexDeclaration; Game1.device.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices2, 0, vertices2.Length, indices, 0, indices.Length / 3); pass.End(); } } basicEffect.End(); The texture brightens if I increase ambient, but it remains unaffected by its angle to the light. Again, works fine if I uncomment the colored polys and use that instead, and I don't see what I'm doing different. Thoughts? EDIT: NM, I'm a 'tard. [embarrass] // bad line texturedVertexDeclaration = new VertexDeclaration(Game1.device, VertexPositionTexture.VertexElements); // new, gooder line texturedVertexDeclaration = new VertexDeclaration(Game1.device, VertexPositionNormalTextured.VertexElements); Um, carry on! [Edited by - 23yrold3yrold on January 2, 2010 3:25:13 PM]
  2. 23yrold3yrold

    XNA and BasicEffect trouble

    Yeah, I'm still not used to the whole "invent your own type and register it" routine, but I added the normals, initialized by hand (it's just a cube) and mostly good to go. Had to enable the depth buffer (why isn't that enabled by default?!) and play with the values a bit, but I got me some nicely colored spinning cube power-ups in my shooter now, well-lit and everything. It's gonna be real fun making more detailed power-ups; I'll probably just texture the cubes with giant letters, but at least I've got something I can work with. Thanks.
  3. 23yrold3yrold

    XNA and BasicEffect trouble

    Okay, that makes sense. Any clues on how to initialize that? My array is VertexPositionColored; I see mention of VertexPositionNormalColored online but not in official documentation and my compiler gives me an error on it. Obviously I'm still researching, but if anyone can give me a push in the right direction, that's be nifty.
  4. I'm building a simple little game engine and a shooter on top of it to get my feet wet with XNA. The functionality of the 'effects' though are kind of throwing me. Permit me to drop some code on you ... I "make" my model; 2 squares for testing: vertices = new VertexPositionColor[12]; // top vertices[0].Position = new Vector3(-20f, -20f, 20f); vertices[0].Color = Color.Red; vertices[1].Position = new Vector3(20f, -20f, 20f); vertices[1].Color = Color.Red; vertices[2].Position = new Vector3(-20f, 20f, 20f); vertices[2].Color = Color.Red; vertices[3].Position = new Vector3(20f, -20f, 20f); vertices[3].Color = Color.Red; vertices[4].Position = new Vector3(20f, 20f, 20f); vertices[4].Color = Color.Red; vertices[5].Position = new Vector3(-20f, 20f, 20f); vertices[5].Color = Color.Red; // bottom vertices[6].Position = new Vector3(-20f, -20f, -20f); vertices[6].Color = Color.Blue; vertices[7].Position = new Vector3(20f, -20f, -20f); vertices[7].Color = Color.Blue; vertices[8].Position = new Vector3(-20f, 20f, -20f); vertices[8].Color = Color.Blue; vertices[9].Position = new Vector3(20f, -20f, -20f); vertices[9].Color = Color.Blue; vertices[10].Position = new Vector3(-20f, 20f, -20f); vertices[10].Color = Color.Blue; vertices[11].Position = new Vector3(20f, 20f, -20f); vertices[11].Color = Color.Blue; coloredVertexDeclaration = new VertexDeclaration(Game1.device, VertexPositionColor.VertexElements); I set up an effect object: basicEffect = new BasicEffect(Game1.device, null); basicEffect.Alpha = 1.0f; basicEffect.DiffuseColor = new Vector3(0.1f, 0.9f, 0.1f); basicEffect.SpecularColor = new Vector3(0.25f, 0.25f, 0.25f); basicEffect.SpecularPower = 1.0f; basicEffect.AmbientLightColor = new Vector3(0.75f, 0.75f, 0.75f); basicEffect.DirectionalLight0.Enabled = true; basicEffect.DirectionalLight0.DiffuseColor = Vector3.One; basicEffect.DirectionalLight0.Direction = Vector3.Normalize(new Vector3(1.0f, -1.0f, -1.0f)); basicEffect.DirectionalLight0.SpecularColor = Vector3.One; basicEffect.LightingEnabled = true; basicEffect.World = Matrix.Identity; basicEffect.View = Matrix.CreateLookAt(new Vector3(0, 0, 200), Vector3.Zero, Vector3.Up); Matrix m = new Matrix(); Matrix.CreateOrthographic(800, 450, 0.1f, 1000, out m); basicEffect.Projection = m; And I try drawing: basicEffect.Begin(); foreach (Powerup e in powerupList) { basicEffect.World *= Matrix.CreateTranslation(pos.X - camx, pos.Y - camy, 0f); foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes) { pass.Begin(); Game1.device.VertexDeclaration = coloredVertexDeclaration; Game1.device.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 4); pass.End(); } } basicEffect.End(); I always get 2 very flatly-colored polygons in the basicEffect.DiffuseColor color (green here). Setting VertexColorEnabled to true just turns everything black. Not sure what I'm fouling up here; thoughts?
  5. I'm pretty sure the drawing function is being called, or else it would be drawing nothing as opposed to drawing everything a beat behind. Anyway, I trimmed the code down to a bare minimum so it's uber-short; if anyone wants to try it out, I appreciate it. This is all XNA at this point, my DirectX system has been removed completely. Guess I need to figure out how XNA does swap chains now too.
  6. I can try, but that would be a lot more work to incorporate it into my program and not actually teach me what's wrong, so I'm understandably hesitant. :) I may have to give it a go and hope for the best ...
  7. I guess that was informative, but ultimately unhelpful. What I'm doing it's doing, and what it's doing that I wasn't had zero overall effect on my program when I tried it. So no difference in the end. [sad] I'm going to keep on this, and I'll post back if I make any headway. But being this frustrated is depressing, and I don't feel like being depressed for Christmas. If anyone else can think of why it wouldn't be updating properly let me know please. EDIT: BTW, I've tried making the drawing area a regular PictureBox drawn with outside functions, and I've tried making it a derived control with all the drawing in OnPaint; no change either way. And passing the control's invalidate function to Application.Idle as a delegate just makes the control lock onto the background gray color with no XNA or DirectX drawing at all. EDIT2: graphicsDevice.GraphicsDeviceStatus is always GraphicsDeviceStatus.Normal, btw. Never Lost or NotReset. [Edited by - 23yrold3yrold on December 23, 2009 11:15:50 PM]
  8. This is a semi-repeat of an old thread of mine which I ended with "Gonna have to find a way to deal with that ..." well, I couldn't figure it out so I'm back for round 2. This tilemap utility would actually be nice to have running right now, even with minimal functionality, so I'm determined to give it another run here. Okay, so my window redraws a beat behind all the time. I'm just clearing it to CornflowerBlue right now. If I open a menu, it leaves a giant artifact when it closes. Still there when I open a new menu, and won't refresh until that one closes. I can try to Refresh or Invalidate all day to MouseMove, ReSize, etc., but I can't update on every friggin' event, and I really shouldn't have to. The funny thing is, I've been using DirectX to try to speed up my drawing, and now I'm trying to use XNA in case it fixes my problem (it doesn't) and if I clear the device context to black with either, it still leaves the artifact, but it's the color I'm clearing to in e.Graphics.Clear(), which tells me the update is happening, but I'm screwing up my DirectX/XNA. In DirectX I'm doing this for initialization: pps = new PresentParameters(Program.maindevicecontext.PresentationParameters); pps.BackBufferCount = 1; pps.DeviceWindow = drawingwindow; pps.DeviceWindowHandle = drawingwindow.Handle; pps.BackBufferWidth = drawingwindow.Width; pps.BackBufferHeight = drawingwindow.Height; m_mainwindowswap = new SwapChain(Program.maindevicecontext, pps); pps = new PresentParameters(Program.maindevicecontext.PresentationParameters); pps.BackBufferCount = 1; pps.DeviceWindow = currenttiles; pps.DeviceWindowHandle = currenttiles.Handle; pps.BackBufferWidth = currenttiles.Width; pps.BackBufferHeight = currenttiles.Height; m_currtilesswap = new SwapChain(Program.maindevicecontext, pps); In XNA I'm doing this (haven't bothered with swap chains in XNA yet). I'm setting the SwapEffect to Discard in both cases ... PresentationParameters pp = new PresentationParameters(); pp.BackBufferCount = 1; pp.BackBufferFormat = SurfaceFormat.Unknown; pp.BackBufferHeight = 600; pp.BackBufferWidth = 800; pp.DeviceWindowHandle = drawingwindow.Handle; pp.IsFullScreen = false; pp.SwapEffect = Microsoft.Xna.Framework.Graphics.SwapEffect.Discard; device = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, Microsoft.Xna.Framework.Graphics.DeviceType.Hardware, drawingwindow.Handle, pp); Doing this in both cases: SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, true); SetStyle(ControlStyles.DoubleBuffer, true); Here's how I'm repainting the screen in both cases: Surface surf = m_mainwindowswap.GetBackBuffer(0, BackBufferType.Mono); surf.Device.SetRenderTarget(0, surf); // start drawing surf.Device.BeginScene(); surf.Device.Clear(ClearFlags.Target, System.Drawing.Color.Black, 1.0f, 0); surf.Device.EndScene(); m_mainwindowswap.Present(); device.Clear(Microsoft.Xna.Framework.Graphics.Color.CornflowerBlue); device.Present(); Anything else anyone can think of why it wouldn't refresh properly? Am I initializing incorrectly, am I drawing the scene incorrectly, is there something I should be checking for? I can make XNA work in a game engine, but I just can't make it or DirectX play nice in a WinForm ...
  9. 23yrold3yrold

    Using fonts in DirectX from resource files

    Yup, it worked. I'm going to detail this real quick in case someone else ever needs it; took longer than it really should have for me to clue in. [embarrass] So basically my resource file is this: 1 FONT "WME.ttf"I load it like this ... HRSRC res = FindResource(instance, MAKEINTRESOURCE(1), RT_FONT); HANDLE m_fonthandle; if (res) { HGLOBAL mem = LoadResource(instance, res); void *data = LockResource(mem); size_t len = SizeofResource(instance, res); DWORD nFonts; m_fonthandle = AddFontMemResourceEx(data, len, NULL, &nFonts); if(m_fonthandle == 0) MessageBox(NULL, "Font add fails", "Error", MB_OK); }Then I create a font for DirectX in the usual manner ... LPD3DXFONT myfont = NULL; D3DXFONT_DESC FontDesc = {15, 0, 400, 0, false, DEFAULT_CHARSET, OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_PITCH, "My Font"}; D3DXCreateFontIndirect(pDevice, &FontDesc, &myfont); And now I can use it like any other ... myfont->DrawText(NULL, "I win at embedded fonts", -1, &(MakeRect(600, 2, 200, 100)), DT_LEFT, 0xffffffff); Clean up my crap when I'm done: RemoveFontMemResourceEx(m_fonthandle); Works perfectly. [cool] Thanks for the help.
  10. 23yrold3yrold

    Using fonts in DirectX from resource files

    Wow, I forgot I made this thread. Been a busy couple of days. ^_^ I've heard of AddFontMemResourceEx(); maybe I just didn't pay enough attention to it. So it will register the font in some way that D3DXCreateFontIndirect() will be able to pick up on it? I can't try it right now, but if that's so, that's pretty much what I'm looking for, thanks. [cool]
  11. Hey all. I've been trying to improve my DirectX game with a few fancy freeware fonts I've found scattered around the Interwebs. I can embed them in an .rc file and get a valid handle to them at runtime no prob. But with DirectX, I'm used to using D3DXCreateFont() and D3DXCreateFontIndirect(), both of which take a font name and load the font from c:\windows\font. Is there some way I can get a valid DirectX font from the TrueType I'm embedding in the resource file, or do I have to use an installer program to install the font, then load it like any other? I'm kind of hoping there's an option for the former; I could figure out how to do it with NSIS or something like it I imagine, but I'd like to know if it's possible to just keep the fonts in the binary.
  12. I'd heard about DrawPrimitiveUP() but usually in derogatory terms, and I couldn't find any good examples of it's use. But it looks like I got it working now. void Blackfade(unsigned char fade) { CUSTOMVERTEX vertices[4] = { 0, 0, 0, 1, (fade << 24), 800, 0, 0, 1, (fade << 24), 0, 600, 0, 1, (fade << 24), 800, 600, 0, 1, (fade << 24) }; // Set alpha blending states. pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true); pDevice->SetFVF(myFVF); pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(CUSTOMVERTEX)); //turn off alpha-blend pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false); } Feel free to criticize that. Needs some other features but the functionality is there. Thanks for the help.
  13. Hey all. Something I've been kind of fighting with today is drawing a primitive with an alpha in a hackish attempt to fade a screen to black. Now, I can do the whole alpha of vertices, create the vertex buffer and lock thing ... but I want the alpha of that polygon to change over time. I can get a static poly with a static alpha, but I can't change things after the fact (as far as I know). I thought about using the diffuse alpha of a material but I can't figure out how to affect the polygon with it and most resources show how to do it with textures so I've got nothing to check my work against. Here's what I'm currently rolling with, and yes it currently draws my screen black as night. [rolleyes] And before anyone asks, yes I'm pretty inexperienced with DirectX, but it's what I'm told I'm using for this project. And no, the article here on playing with gamma settings doesn't work on this comp. const DWORD myFVF = D3DFVF_XYZRHW | D3DFVF_DIFFUSE; struct CUSTOMVERTEX { float x, y, z, weight; DWORD color; }; LPDIRECT3DVERTEXBUFFER9 pV = NULL; D3DMATERIAL9 m_material; LPDIRECT3DVERTEXBUFFER9 FillVertices(LPDIRECT3DDEVICE9 pDevice) { ZeroMemory(&m_material, sizeof(m_material)); m_material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); m_material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); m_material.Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); m_material.Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); m_material.Diffuse.a = 0.0f; m_material.Power = 5.0f; CUSTOMVERTEX cVertices[4]; LPDIRECT3DVERTEXBUFFER9 pVertexBuffer; cVertices[0].x = 0; cVertices[0].y = 0; cVertices[0].z = 0; cVertices[0].weight = 1; cVertices[0].color = 0xFF000000; cVertices[1].x = 800; cVertices[1].y = 0; cVertices[1].z = 0; cVertices[1].weight = 1; cVertices[1].color = 0xFF000000; cVertices[2].x = 0; cVertices[2].y = 600; cVertices[2].z = 0; cVertices[2].weight = 1; cVertices[2].color = 0xFF000000; cVertices[3].x = 800; cVertices[3].y = 600; cVertices[3].z = 0; cVertices[3].weight = 1; cVertices[3].color = 0xFF000000; if (FAILED(pDevice->CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX), 0, myFVF, D3DPOOL_DEFAULT, &pVertexBuffer, NULL ) ) ) MessageBox(NULL, "Error while creating VertexBuffer", "FillVertices()", MB_OK); VOID* pVertices; if (FAILED(pVertexBuffer->Lock(0, 4 * sizeof(CUSTOMVERTEX), (void**)&pVertices, 0))) MessageBox(NULL, "Error trying to lock", "FillVertices()", MB_OK); else { memcpy(pVertices, cVertices, 4 * sizeof(CUSTOMVERTEX)); pVertexBuffer->Unlock(); } return pVertexBuffer; } void Blackfade() { if(pV == NULL) pV = FillVertices(pDevice); // Set alpha blending states. pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true); pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE); pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); pDevice->SetMaterial(&m_material); pDevice->SetStreamSource(0, pV, 0, sizeof(CUSTOMVERTEX)); pDevice->SetFVF(myFVF); pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); //turn off alpha-blend pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false); } So how would you suggest I set it up so the alpha value of the drawn polygon can be changed over time? Or can you think of another way to do a fullscreen fade to black altogether? Thanks.
  14. I think I found the problem; the Application.Idle doesn't fire if that dialog window is open ... for whatever reason. Confirmed by adding the MessageBox.Show() call; it spams my screen until I open that dialog. Gonna have to find a way to deal with that ...
  15. Yeah, I'm only invalidating the two child windows. Flickers like mad. If I just call my custom "repaint these controls" functions in Application.Idle then the original problem persists.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!