Jump to content
  • Advertisement
Sign in to follow this  
Plasmarobo

Invisible Geometry

This topic is 4154 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey, I have read a tutorial on rendering from vertex buffers, and I have designed my own class, but I must be doing something wrong. I am getting invisible geometry. I am rendering from a non-indexed vertex buffer of vertices with #define FVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1) Do I *have* to specify a texture? I tried playing with normals and winding order, but no luck so far. Here's my code (I'll post the Vertex Buffer class if someone wants)
#define WIN32_LEAN_AND_MEAN
#include "stdafx.h"
//we could include these in stdafx, but intel-sense likes them here
#include "Foundation.h"
#include "DirectX.h"
#include "Input.h"
#include "Images.h"
#include "3dbase.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
	Foundation::WinFnd::WinLayer App;
	if(!App.Start(hInstance, "Core", "Core", 800, 600, nCmdShow))
	{
		MessageBox(App.m_hWnd, "Application failed to initialize", "FAILURE", NULL);
		App.End();
		return 0;
	}
	App.window = &App;
	
	
	//Setup DirectX
	
	Graphics::DirectX::DirectXLayer Direct3D;
	Direct3D.Aquire();
	Direct3D.GetCapsHal();
	Graphics::DirectX::FormatBlock Settings;
	ZeroMemory(&Settings, sizeof(Graphics::DirectX::FormatBlock));
	//Direct3D.GetAdapterFormat(Settings);
	Settings.Init_Def(App.m_hWnd);
	
	Direct3D.CreateDevice(Settings);
	Direct3D.SetRenderState(D3DRS_LIGHTING, true);
	Direct3D.SetRenderStateEx(D3DRS_AMBIENT, D3DCOLOR_XRGB(255,255,255));
	Direct3D.SetRenderStateEx(D3DRS_FILLMODE, D3DFILL_WIREFRAME); 
	//Setup Input
	Input::DI8 Input_Control;
	Input_Control.Create(hInstance);
	Input::Keyboard keyboard(&Input_Control);
	keyboard.Create(App.m_hWnd);
	
	Graphics::DirectX::iVertexBuffer Vertbuf(&Direct3D);
	Vertbuf.SetSize_f(6);
	
	Vertbuf.Create(D3DUSAGE_WRITEONLY,FVF, D3DPOOL_DEFAULT);

	Graphics::DirectX::iFVF *verts;
	
	Vertbuf.Fill((void**)&verts);
	verts[0].pos = D3DXVECTOR3(0.0f, 100.0f, 1.0f);
	verts[0].normal = D3DXVECTOR3(0.0f, 0.0f, 0.0f);
	verts[1].pos = D3DXVECTOR3(0.0f, 0.0f, 1.0f);
	verts[1].normal = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
	verts[2].pos = D3DXVECTOR3(100.0f, 100.0f, 1.0f);
	verts[2].normal = D3DXVECTOR3(0.5f, 1.0f, 0.0f);
	verts[3].pos = D3DXVECTOR3(100.0f, 100.0f, 1.0f);
	verts[4].pos = D3DXVECTOR3(0.0f, 100.0f, 1.0f);
	verts[5].pos = D3DXVECTOR3(100.0f, 0.0f, 1.0f);
	
	Vertbuf.Done();
	Graphics::DirectX::iMaterial Mater;
	Mater.Create(255.0f, 255.0f, 255.0f, 0.0f);
	Mater.SetAmbient(255.0f, 255.0f, 255.0f);
	Mater.SetDiffuse(255.0f, 255.0f, 255.0f);
	Mater.SetEmissive(255.0f, 255.0f, 255.0f);
	Mater.SetSpec(255.0f, 255.0f, 255.0f, 1.0f);
	Vertbuf.SetMater( &Mater );
	Graphics::DirectX::iTexture texture(&Direct3D);
	texture.Load("s1.png");
	Vertbuf.SetTexture(&texture);

	



	
	
	
	bool on = true;
	
	
	while(on)
	{
		App.MsgLoop();
		App.Update();
		if(App.Active)
		{
		
		
		Direct3D.StartRender();
		Vertbuf.RenderDefault(sizeof(Graphics::DirectX::iFVF));
		//This is a "badly behaved message loop"
		Direct3D.EndRender();

		keyboard.Scan();
		//methods of escape
		if(keyboard.CheckKey(DIK_ESCAPE))
			break;
		if(keyboard.CheckKey(DIK_M))
			PostMessage(App.m_hWnd, WM_ACTIVATEAPP, false, NULL);
		if(App.Done)
			break;
		Direct3D.ClearScreen();
		Direct3D.Present();
		}
	
	}
	App.End();
	Direct3D.End();

	return 0;
}


Heh, I know I have other strange h files in there, but I wanted to keep this post relatively short. If you need it I can post them

Share this post


Link to post
Share on other sites
Advertisement
I don't know the cause of your problem, but I have two suggestions:
  1. Check the return codes of every DirectX function that returns one, and turn on debugging in the D3D control panel. If something is wrong with the way you set up D3D or the data that you send it, it will tell you.
  2. Move #define WIN32_LEAN_AND_MEAN" to after #include "stdafx.h". If you are using precompiled headers, then everything before the #include "stdafx.h" is ignored by the compiler.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!