This topic is now archived and is closed to further replies.


Sigh, Why can't I draw a 2D quad on top of my 3d scene?

Recommended Posts

oxygen_728    122
I've tried for so long to get this to work... I put the code to create & display a quad in my main render() function. Of course this will be hidden away in some other functions, but to figure out how to get it to work I put it in my render function. Basically.... Begin Scene 1. Setup Matrices 2. Process Input 3. Draw 3d Scene (building and bouncing balls) 4. "HOPEFULLY" overlay a quad (2 triangles with triangle strip) 5. Draw text End Scene Perhaps from seeing those steps you can see something wrong... I'm out of ideas. I've looked at so many tutorials that my eyes hurt... my code LOOKS right... I just don't see any results no matter how I flip around my vertices. Here's my code, Thank you VERY much for your help & time.
VOID Render()
	// Process Keyboard Input & Update Objects accordingly

		MessageBox(NULL,"Failed to Update Objects", "Update Objects (main)", MB_OK);

    // Clear the backbuffer and the zbuffer

    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
                         D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
    // Begin the scene

    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
		RECT destRect;
		SetRect( &destRect, 1, 1, 0, 0 );

        // Setup the world, view, and projection matrices


		// Render our 3D stuff ... Building + Bouncing Balls


//Code to Draw a Square////////////////////////////////

	CPVertex g_square_vertices[] ={
		{ 250.0f,  200.0f, 1.0f, 0.5f, 0xFFFFFFFF }, // x, y, z, rhw, color

		{ 250.0f,  50.0f,  1.0f, 0.5f, 0xFFFFFFFF },
		{ 400.0f,  200.0f, 1.0f, 0.5f, 0xFFFFFFFF },
		{ 400.0f,  50.0f,  1.0f, 0.5f, 0xFFFFFFFF } };

	if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4*sizeof(CPVertex),
													0, D3DFVF_CUSTOMVERTEX,
													D3DPOOL_DEFAULT, &g_square, NULL ) ) )
		// handle case


	VOID* pVertices;
	if( FAILED( g_square->Lock( 0, sizeof(g_square_vertices), (void**)&pVertices, 0 ) ) )
	memcpy( pVertices, g_square_vertices, sizeof(g_square_vertices) );

	g_pd3dDevice->SetStreamSource(0,g_square,0, sizeof(CPVertex));

//END code to draw a square//////////////////////////////////

	// Begin Font Stuff

	// Display frames per second.

	char buffer[20];
	long debugFPS = timeGetTime();
	if( debugFPS - FPSTIME2 > 250 ){
		DEBUGNUM = 1000.0f / (debugFPS - FPSTIME);
		FPSTIME2 = debugFPS;
	FPSTIME = debugFPS;

	g_pd3dxFont->DrawText( NULL,
		strcat(buffer, " fps"), 
		D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f) );
	// End Font Stuff

        // End the scene


    // Present the backbuffer contents to the display

    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

[edited by - oxygen_728 on March 29, 2004 2:13:32 AM] [edited by - oxygen_728 on March 29, 2004 2:15:00 AM]

Share this post

Link to post
Share on other sites
oxygen_728    122
I''ll answer my question now... I found a great tutorial by Andy Pike that explains this.

First off, you render your 3d stuff & end your scene.

Second, you setup a new set of matrices for your 2D stuff. (World Matrix etc)

THEN you can render your 2d stuff!

Here''s a link

Share this post

Link to post
Share on other sites
Okay, I'm not sure about the world, view, and projection matrices. They seem to be the same as when you render the normal scene. Since you're using transformed vertices I think that you're going to want to reset the World, View, and Projection matrices back to NULL. (and as a side note: Creating a vertex buffer each frame!? You should create it as little as possible, and since it appears to be the same from frame to frame you should create it at load time and then use when rendering. Now if you used a varying amount of vertices on each frame I could see a justification for creating one each frame, but yours is static so you should create it ONCE.)

Edit: Or you could answer your own question while I'm answering it.

[edited by - Erzengeldeslichtes on March 29, 2004 2:38:48 AM]

Share this post

Link to post
Share on other sites