Jump to content
  • Advertisement
Sign in to follow this  
adam23

Win32 Question

This topic is 4377 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

I am in the middle of attempting to create a WIN32 program that creates two 3D wire cubes and positions them in 3D space. I am doing this so I have to create the functions to rotate, translate, and convert to screen space. Here is my problem. I am getting nothing to show up on my screen. It doesn't make any since. The only thing that shows up is 0 FPS, but I implemented logging and it is definately cycling through the program correctly. If anyone can help me I would greatly appreciate it. //Main.cpp
#include "CPolygon.h"
#include <windows.h>
#include "Vector3.h"
#include "Cube.h"
#include "Win32.h"

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
	Engine *g_engine = new Engine();
	if(!g_engine->InitEngine(hInstance, lpCmdLine, iCmdShow))
	{
		::MessageBoxA(0,"Engine could not be initialized","Error",MB_OK);
		return 0;
	}
	g_engine->BeginGame();
	
	
	
	if(!g_engine->ShutDown())
	{
		::MessageBox(0,"Game could not be shut down", "Error",MB_OK);
	}
	delete g_engine;



	return 0;
}

//Win32.cpp
#include "Win32.h"
#include "resource.h"

Engine::Engine()
{
	DisableLogging();
	WriteToLog("Constructor for engine entered");
	m_hWnd = NULL;
	width = 400;
	height = 400;
	degrees = 60;
	m_hWnd = NULL;  //Main window handle;
	m_hdcFrameBuffer= NULL;	//Frame Buffer Device Context
	m_hbmFrameBuffer= NULL;	//Frame buffers Bitmap
	m_hbmSelectOut = NULL;	
	cubes[0] = new Cube(4);
	cubes[1] = new Cube(6);
	cubes[0]->WorldPos.x = 8;
	cubes[0]->WorldPos.y = 7;
	cubes[0]->WorldPos.z = 12;
	cubes[1]->WorldPos.x = -8;
	cubes[1]->WorldPos.y = -7;
	cubes[1]->WorldPos.z = 25;
}
Engine::~Engine()
{
	WriteToLog("Engine Destructor");
	delete cubes[0];
	cubes[0] = NULL;
	delete cubes[1];
	cubes[1] = NULL;
	//Destructor
}
bool Engine::InitEngine(HANDLE hInstance, LPCTSTR lpCmdLine, int iCmdShow)
{
	WriteToLog("Initializing Engine");
	PI = 3.141592654f;
	if(!CreateWin())
		return false;

	//Set view matrix to equal 0
	//Set projection matrix to all 0's
	for(int i = 0; i<4; i++)
	{
		for(int j = 0; j<4; j++)
		{
			viewMatrix[j] = 0;
			projMatrix[j] = 0;
		}
	}
	//Create Projection matrix with 60 degree viewport
	float AspectRatio = (float)width/height;
	double radians = degrees * (PI/180);
	projMatrix[0][0]=(float)(1/(tan(radians/2)*AspectRatio));
	projMatrix[1][1]=(float)(1/(tan(radians/2)));
	projMatrix[2][2] = 1;

	return true;

}
bool Engine::CreateWin()
{
	WriteToLog("Creating Window");
	LPTSTR WindowTitle = _T("Adam Larson's Software Render");
	USHORT	Width = 400;
	USHORT	Height = 400;
	HDC		hDC = NULL;
	RECT rc;

	//Register the new windows class
	WNDCLASS wc;
	wc.style		= CS_BYTEALIGNCLIENT | CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc	= StaticWndProc;
	wc.cbClsExtra	= 0;
	wc.cbWndExtra	= 0;
	wc.hInstance	= (HINSTANCE)GetModuleHandle(NULL);
	wc.hIcon		= LoadIcon(wc.hInstance, MAKEINTRESOURCE(IDI_ICON));
	wc.hCursor		= LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground= (HBRUSH) GetStockObject(BLACK_BRUSH);
	wc.lpszClassName= WindowTitle;
	wc.lpszMenuName = NULL;
	RegisterClass(&wc);

	//Create the rendering window
	m_hWnd = CreateWindow(WindowTitle, WindowTitle, WS_OVERLAPPEDWINDOW,
							CW_USEDEFAULT, CW_USEDEFAULT, Width, Height, NULL,
							LoadMenu( wc.hInstance,MAKEINTRESOURCE(IDR_MENU1)),
							wc.hInstance,this);
	if(!m_hWnd)
		return false;
	
	//Retrieve teh final client size of the window
	::GetClientRect(m_hWnd, &rc );
	m_nViewX	= rc.left;
	m_nViewY	= rc.top;
	m_nViewWidth= rc.right - rc.left;
	m_nViewHeight= rc.bottom-rc.top;

	//Build the frame buffer
	if(!BuildFrameBuffer(width, height))
		return false;

	//Show the window
	ShowWindow(m_hWnd, SW_SHOW);
	//Success
	return true;
}

bool Engine::BuildFrameBuffer(ULONG Width, ULONG Height)
{
	WriteToLog("Entering BuildFrameBuffer");
	HDC hDC = ::GetDC( m_hWnd );
	if(!m_hdcFrameBuffer ) 
		m_hdcFrameBuffer = ::CreateCompatibleDC( hDC );

	//Create a bitmap that is compatible with the application window
	m_hbmFrameBuffer = CreateCompatibleBitmap( hDC, Width, Height );
	if( !m_hbmFrameBuffer )
		return false;

	//Select bitmap into the device context
	m_hbmSelectOut = (HBITMAP)::SelectObject(m_hdcFrameBuffer, m_hbmFrameBuffer);

	//Release the window DC and set the frame buffer DC so that it renders transparently
	::ReleaseDC( m_hWnd, hDC );
	::SetBkMode( m_hdcFrameBuffer, TRANSPARENT );
	return true;
}
void Engine::ClearFrameBuffer(ULONG Color)
{
	WriteToLog("Entering ClearFrameBuffer");
    LOGBRUSH logBrush;
    HBRUSH   hBrush = NULL, hOldBrush = NULL;
    
    // Set up the rendering brush
    logBrush.lbStyle = BS_SOLID;
    
    // Set up the colour, converted to BGR & stripped of alpha
    logBrush.lbColor = 0x00FFFFFF & RGB2BGR( Color );
    
    // Create the rendering brush
    hBrush = ::CreateBrushIndirect( &logBrush );
    if (!hBrush) return;

    // Select into the frame buffer DC
    hOldBrush = (HBRUSH)::SelectObject( m_hdcFrameBuffer, hBrush );

    // Draw the rectangle
    Rectangle( m_hdcFrameBuffer, m_nViewX, m_nViewY, m_nViewWidth, m_nViewHeight );
    
    // Destroy rendering brush
    ::SelectObject( m_hdcFrameBuffer, hOldBrush );
    ::DeleteObject( hBrush );

}
void Engine::PresentFrameBuffer()
{
	WriteToLog("Entering PresentFrameBuffer()");
	HDC hDC = NULL;
	//Retrieve the DC of the window
	hDC = ::GetDC(m_hWnd);
	//Blit the frame buffer to the screen
	::BitBlt(hDC, m_nViewX, m_nViewY, m_nViewWidth, m_nViewHeight,
				m_hdcFrameBuffer, m_nViewX, m_nViewY, SRCCOPY);

	//Clean up 
	::ReleaseDC(m_hWnd, hDC);
}
int Engine::BeginGame()
{
	WriteToLog("Entering BeginGame()");
	MSG msg;
	//Start main loop
	while(1)
	{
		//Check if received message
		if( PeekMessage(&msg, NULL, 0,0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
				break;
			TranslateMessage( &msg);
			DispatchMessage(&msg);
		}
		else
		{
			FrameAdvance();
		}
	}
	return 0;
}
LRESULT CALLBACK Engine::StaticWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	if(Message == WM_CREATE ) SetWindowLong(hWnd, GWL_USERDATA, (LONG)((CREATESTRUCT FAR*) lParam)->lpCreateParams);

	Engine *Destination = (Engine*)GetWindowLong( hWnd, GWL_USERDATA);

	if(Destination)
		return Destination->DisplayWndProc(hWnd, Message, wParam, lParam);
	//No destination found
	return DefWindowProc(hWnd, Message, wParam, lParam);
}

LRESULT Engine::DisplayWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
	WriteToLog("DisplayWndProc");
	float fAspect;
	float radians = degrees * (PI/180);

	//Determine message type
	switch(Message)
	{
	case WM_CREATE:
		break;
	case WM_CLOSE:
		PostQuitMessage(0);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_SIZE:
		WriteToLog("Entering WM_SIZE");
		//Store any viewport sizes
		width = LOWORD(lParam);
		height = HIWORD(lParam);

		//Set up new perspective projection matrix
		//Create Projection matrix with 60 degree viewport
		fAspect = (float)width/(float)height;
		projMatrix[0][0]=1/(tan(radians/2)*fAspect);
		projMatrix[1][1]=1/(tan(radians/2));
		projMatrix[2][2] = 1;

		//Rebuild the new frame buffer
		BuildFrameBuffer(width, height);
		break;

	case WM_KEYDOWN:
		//Key pressed
		switch(wParam)
		{
		case VK_ESCAPE:
			PostQuitMessage(0);
			return 0;
		}
	case WM_COMMAND:
		//Process Menu items
		switch(LOWORD(wParam))
		{
		default:
			break;
		}
	default:
		return DefWindowProc(hWnd,Message,wParam,lParam);
	}//End Message Switch
	return 0;
}
bool Engine::ShutDown()
{
	WriteToLog("Shutting Down Application");
    // Destroy the frame buffer and associated DC's
    if ( m_hdcFrameBuffer && m_hbmFrameBuffer )
    {
        ::SelectObject( m_hdcFrameBuffer, m_hbmSelectOut );
        ::DeleteObject( m_hbmFrameBuffer );
        ::DeleteDC( m_hdcFrameBuffer );

    } // End if

    // Destroy the render window
    if ( m_hWnd ) DestroyWindow( m_hWnd );
    
    // Clear all variables
    m_hWnd              = NULL;
    m_hbmFrameBuffer    = NULL;
    m_hdcFrameBuffer    = NULL;
    
    // Shutdown Success
    return true;
}

void Engine::FrameAdvance()
{
	TCHAR	lpszFPS[30];
	WriteToLog("Entering Frame Advance()");
	
	m_Timer.Tick( 60.0f);
//	AnimateObjects();
	ClearFrameBuffer(0x00FFFFFF); //Clears with bright white

	for( ULONG i = 0; i<2; i++)
	{
	
		//Loop through each polygon
		for(ULONG f = 0; f<6; f++)
		{
			DrawPrimitive(cubes->sides[f], cubes->WorldPos);
		}
	}
	m_Timer.GetFrameRate( lpszFPS);
	TextOut( m_hdcFrameBuffer, 5, 5, lpszFPS, strlen(lpszFPS));

	PresentFrameBuffer();
}
void Engine::DrawPrimitive(CPolygon &pPoly, CVector3 &worldMatrix)
{
	WriteToLog("Entering DrawPrimitive");
	CVector3 vtxPrevious, vtxCurrent;
	for(USHORT v = 0; v<4+1; v++)
	{
		vtxCurrent = pPoly.p[v%4];
		WorldTransform(vtxCurrent,worldMatrix);
		ProjectionTransform(vtxCurrent);
		vtxCurrent.x = vtxCurrent.x*m_nViewWidth/2 + m_nViewX + m_nViewWidth/2;
		vtxCurrent.y = vtxCurrent.y = -vtxCurrent.y * m_nViewWidth/2 + m_nViewY+m_nViewHeight/2;

		if(v==0)
		{
			vtxPrevious = vtxCurrent;
			continue;
		}
		DrawLine(vtxPrevious,vtxCurrent);
		vtxPrevious = vtxCurrent;
	}
}
void Engine::DrawLine(CVector3 &v1, CVector3 &v2)
{
	WriteToLog("Drawing Line");
	LOGPEN logPen;
	HPEN hPen = NULL, hOldPen = NULL;
	ULONG Color = 0;

	//Set up rendering pen
	logPen.lopnStyle = PS_SOLID;
	logPen.lopnWidth.x = 1;
	logPen.lopnWidth.y = 1;

	//Set up the color converted to BGR & stripped of alpha
	logPen.lopnColor = 0x00FFFFFF & RGB2BGR(Color);

	//Create the rendering pen
	hPen = ::CreatePenIndirect(&logPen);
	if(!hPen)
		return;

	//Select into the frame buffer DC
	hOldPen = (HPEN)::SelectObject(m_hdcFrameBuffer,hPen);

	//Draw the line segmen
	MoveToEx(m_hdcFrameBuffer, (long)v1.x, (long)v1.y,NULL);
	LineTo( m_hdcFrameBuffer, (long)v2.x,(long)v2.y);

	//Destroy rendering pen
	::SelectObject(m_hdcFrameBuffer, hOldPen);
	::DeleteObject( hPen);
}
void Engine::WorldTransform(CVector3 &v, CVector3 &World)
{
	WriteToLog("Entering World Transform");
	v.x += World.x;
	v.y += World.y;
	v.z += World.z;
}
void Engine::ProjectionTransform(CVector3 &v)
{
	WriteToLog("Entering Screen and ProjectionTransform()");
	v.x /=v.z; //Converts to 2D screen space
	v.y /=v.z;
	//Convert to screen coordinates
	v.x = v.x*m_nViewWidth/2 + m_nViewX + m_nViewWidth/2;
	v.y = -v.y*m_nViewHeight/2 + m_nViewY+m_nViewHeight/2;
	
	v.x = projMatrix[0][0]*v.x+projMatrix[1][0]*v.x+projMatrix[2][0]*v.x;
	v.y = projMatrix[0][1]*v.y+projMatrix[1][1]*v.y+projMatrix[2][1]*v.y;
	v.z = projMatrix[0][2]*v.z+projMatrix[1][2]*v.x+projMatrix[2][2]*v.z;

}
void Engine::EnableLogging()
{
	//Setting name of log file
	name = "EngineLog.txt";
	filename = name;
	fileJustOpened = true;
	f_log = true;

}
void Engine::WriteToLog(std::string a)
{
	
	if(f_log)
	{
		if(filename == name)
		{
			if(fileJustOpened)
			{
				fout.open(filename.c_str());
				fout<<a<<"\n";
				fout.close();
				fileJustOpened = false;
			}
			else
			{
				fout.open(filename.c_str(),std::ios::app);
				fout<<a<<"\n";
				fout.close();
				fileJustOpened = false;
			}
		}
		else
		{
		//Engine not logged
		}
	}
}
void Engine::DisableLogging()
{
	f_log = false;
}

//Cube.cpp
#include "Cube.h"

Cube::Cube()
{
	//initialize all variables to zero
	WorldPos.x = 0;
	WorldPos.y = 0;
	WorldPos.z = 0;

	sides[0].p[0].x = -2; sides[0].p[0].y = 2; sides[0].p[0].z = -2;
	sides[1].p[1].x = 2; sides[1].p[1].y = 2; sides[1].p[1].z = -2;
	sides[2].p[2].x = 2; sides[2].p[2].y = -2; sides[2].p[2].z = -2;
	sides[3].p[3].x = -2; sides[3].p[3].y = -2; sides[3].p[3].z = -2;
	sides[4].p[4].x = 2; sides[4].p[4].y = 2; sides[4].p[4].z = 2;
	sides[5].p[5].x = -2; sides[5].p[5].y = 2; sides[5].p[5].z = 2;
	sides[6].p[6].x = -2; sides[6].p[6].y = -2; sides[6].p[6].z = 2;
	sides[7].p[7].x = 2; sides[7].p[7].y = -2; sides[7].p[7].z = 2;

	float degreesX, degreesY, degreesZ;
	degreesX = 30;
	degreesY= 5;
	degreesZ = 17;
	RotX = degreesX*(3.14f/180.0f);
	RotY = degreesY*(3.14f/180.0f);
	RotZ = degreesZ*(3.14f/180.0f);
}
Cube::Cube(int size)
{
	//initialize all variables to zero
	WorldPos.x = 0;
	WorldPos.y = 0;
	WorldPos.z = 0;
	float coord = (float)size/2;

	sides[0].p[0].x = -coord; sides[0].p[0].y = coord; sides[0].p[0].z = -coord;
	sides[0].p[1].x = coord; sides[0].p[1].y = coord; sides[0].p[1].z = -coord;
	sides[0].p[2].x = coord; sides[0].p[2].y = -coord; sides[0].p[2].z = -coord;
	sides[0].p[3].x = -coord; sides[0].p[3].y = -coord; sides[0].p[3].z = -coord;
	sides[1].p[0].x = coord; sides[1].p[0].y = coord; sides[1].p[0].z = coord;
	sides[1].p[1].x = -coord; sides[1].p[1].y = coord; sides[1].p[1].z = coord;
	sides[1].p[2].x = -coord; sides[1].p[2].y = -coord; sides[1].p[2].z = coord;
	sides[1].p[3].x = coord; sides[1].p[3].y = -coord; sides[1].p[3].z = coord;
	sides[2].p[0].x = -coord; sides[2].p[0].y = coord; sides[2].p[0].z = coord;
	sides[2].p[1].x = coord; sides[2].p[1].y = coord; sides[2].p[1].z = coord;
	sides[2].p[2].x = coord; sides[2].p[2].y = coord; sides[2].p[2].z = -coord;
	sides[2].p[3].x = -coord; sides[2].p[3].y = coord; sides[2].p[3].z = -coord;
	sides[3].p[0].x = coord; sides[3].p[0].y = coord; sides[3].p[0].z = -coord;
	sides[3].p[1].x = coord; sides[3].p[1].y = coord; sides[3].p[1].z = coord;
	sides[3].p[2].x = coord; sides[3].p[2].y = -coord; sides[3].p[2].z = coord;
	sides[3].p[3].x = coord; sides[3].p[3].y = -coord; sides[3].p[3].z = -coord;
	sides[4].p[0].x = -coord; sides[4].p[0].y = -coord; sides[4].p[0].z = -coord;
	sides[4].p[1].x = -coord; sides[4].p[1].y = -coord; sides[4].p[1].z = coord;
	sides[4].p[2].x = coord; sides[4].p[2].y = -coord; sides[4].p[2].z = coord;
	sides[4].p[3].x = coord; sides[4].p[3].y = -coord; sides[4].p[3].z = -coord;
	sides[5].p[0].x = -coord; sides[5].p[0].y = coord; sides[5].p[0].z = coord;
	sides[5].p[1].x = -coord; sides[5].p[1].y = coord; sides[5].p[1].z = -coord;
	sides[5].p[2].x = -coord; sides[5].p[2].y = -coord; sides[5].p[2].z = -coord;
	sides[5].p[3].x = -coord; sides[5].p[3].y = -coord; sides[5].p[3].z = coord;
	float degreesX, degreesY, degreesZ;
	degreesX = 30;
	degreesY= 5;
	degreesZ = 17;
	RotX = degreesX*(3.14f/180.0f);
	RotY = degreesY*(3.14f/180.0f);
	RotZ = degreesZ*(3.14f/180.0f);
}
Cube::~Cube()
{
//Destructor
}
void Cube::scaleCube(int value)
{
	for(int i = 0; i<8; i++)
	{
		sides.p.x *= value;
		sides.p.y *= value;
		sides.p.z *= value;
	}
}

//Vector3.cpp
//===============================
//CVector3.cpp
//Written by Adam Larson
//===============================
#include "Vector3.h"
#include <math.h>
#include <iostream>

CVector3::CVector3():x(0.0f),y(0.0f),z(0.0f)
{
}
CVector3::CVector3(float X, float Y, float Z)
{
	x = X;
	y = Y;
	z = Z;
}
CVector3::CVector3(CVector3 &v)
{
	x = v.x;
	y = v.y;
	z = v.z;
}
CVector3::~CVector3()
{
	//Destructor Data here
}

//==============================
//Function: length
//returns the length of the vector
//==============================
float CVector3::length(CVector3 &v)
{
	return sqrt((v.x*v.x)+(v.y*v.y)+(v.z*v.z));
}
//==============================
//Function Normalize
//Returns normalized vector
//==============================
CVector3 CVector3::Normalize(CVector3 &v)
{
	float len = length(v);
	CVector3 temp;
	temp.x = v.x/len;
	temp.y = v.y/len;
	temp.z = v.z/len;
	return temp;
}
//===============================
//Function AddVectors
//Return New vector
//===============================

CVector3 CVector3::AddVectors(CVector3 &v1, CVector3 &v2)
{
	CVector3 temp;
	temp.x = v1.x+v2.x;
	temp.y = v1.y+v2.y;
	temp.z = v1.z+v2.z;
	return temp;
}

//================================
//Function SubtractVectors
//Returns new vector
//================================

CVector3 CVector3::SubtractVectors(CVector3 &v1, CVector3 &v2)
{
	CVector3 temp;
	temp.x = v1.x - v2.x;
	temp.y = v1.y - v2.y;
	temp.z = v1.z = v2.z;
	return temp;
}

//==================================
//Function ScalarMultiply
//Returns vector multiplied by scalar
//==================================
CVector3 CVector3::ScalarMultiply(CVector3 &v, float scalar)
{
	CVector3 temp;
	temp.x = v.x*scalar;
	temp.y = v.y*scalar;
	temp.z = v.z*scalar;
	return temp;
}

//==================================
//Function CrossProduct
//Returns vector of cross product of
//2 vectors
//==================================
CVector3 CVector3::CrossProduct(CVector3 &v1, CVector3 &v2)
{
	CVector3 temp;
	temp.x = (v1.y*v2.z)-(v1.z*v2.y);
	temp.y = (v1.z*v2.x)-(v1.x*v2.z);
	temp.z = (v1.x*v2.y)-(v1.y*v2.x);
	return temp;
}

//======================================
//Function Dot Product
//Returns a vector of the Dot Product of
//2 vectors
//=======================================

float CVector3::DotProduct(CVector3 &v1, CVector3 &v2)
{
	CVector3 temp1, temp2;
	temp1 = Normalize(v1);
	temp2 = Normalize(v2);
	return ((temp1.x*temp2.x)+(temp1.y*temp2.y)+(temp1.z*temp2.z));
}

//=====================================
//Function Print
//=====================================
void CVector3::print(CVector3 &v)
{
	std::cout<<"("<<v.x<<"  "<<v.y<<"  "<<v.z<<")";
}

//Win32.h
#ifndef _WIN32_H
#define _WIN32_H

#include <windows.h>
#include "CTimer.h"
#include "Vector3.h"
#include <math.h>
#include "Cube.h"
#include "CPolygon.h"
#include <fstream>
#include <iostream>
#include <string>

#define RGB2BGR( Color ) (Color & 0xFF000000) | ((Color & 0xFF0000) >> 16) | (Color & 0x00FF00) | ((Color & 0x0000FF) << 16)

class Engine
{
public:
	
	//public functions
	Engine();
	~Engine();//Destructor

	bool InitEngine(HANDLE hInstance, LPCTSTR lpCmdLine, int iCmdShow);   //Sets up engine
	void DrawLine(CVector3 &v1, CVector3 &v2);
	int BeginGame();
	LRESULT		DisplayWndProc(HWND hWnd, UINT Message, WPARAM wParam,
								LPARAM lParam );
	void EnableLogging();  //Added function to enable writing to a file
	void WriteToLog(std::string a);  //Writes string a to file
	void DisableLogging();

	//public variables
	float viewMatrix[3][3];
	float projMatrix[3][3];


	bool ShutDown();

	float PI;

private:

	bool CreateWin(); // Creates application window
	bool BuildFrameBuffer(ULONG Width, ULONG Height);//Creates Frame Buffer
	void ClearFrameBuffer(ULONG Color = 0x00FFFFFF);//Clears the buffer to bright white
	void PresentFrameBuffer();  //Blits the Frame Buffer to the screen
	void FrameAdvance();
	void DrawPrimitive(CPolygon &pPoly, CVector3 &worldMatrix);

	int width, height;  //Screen width and height
	int degrees;
	void WorldTransform(CVector3 &v, CVector3 &World);
	void ProjectionTransform(CVector3 &v);  //Converts to screen space

	//Stores the two cubes
	Cube		*cubes[2];

	ULONG		m_nViewX;			//X position of render viewport
	ULONG		m_nViewY;			//Y position of render viewport
	ULONG		m_nViewWidth;		//Width of render viewport
	ULONG		m_nViewHeight;//Height of render viewport


	HWND		m_hWnd;   //Main window handle;
	HDC			m_hdcFrameBuffer;	//Frame Buffer Device Context
	HBITMAP		m_hbmFrameBuffer;	//Frame buffers Bitmap
	HBITMAP		m_hbmSelectOut;		//Used for selecting out of the DC

	CTimer		m_Timer;

	//Variables for logging
	std::string filename; //Used to setup the ability to log events
	std::ofstream fout;  //ofstream variable to output to file;
	bool fileJustOpened;  //Variable to detect when the file was first opened
	std::string name;  //Set file name here for log file
	bool f_log;

	//===================================
	//Private Static Functions
	//===================================
	static LRESULT CALLBACK StaticWndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam);
};
#endif

If anyone is interested here is a link to the entire source code. I am using VS 2005. I have limited bandwidth so if it is unavailable please :) try back in an hour. [link] http://www.geocities.com/adam_autum/HelpMe.zip [/link]

Share this post


Link to post
Share on other sites
Advertisement
I'm having a look at it just now. Just a hint - don't include .ncb files in the zip - they're for the classwizard, and you don't need them. That should shrink the zip down to a tiny size.

Share this post


Link to post
Share on other sites
Thank you for taking the time to look at it. I will try to remember to remove .ncb files from now on. Thanks for the tip :)

Share this post


Link to post
Share on other sites

float viewMatrix[3][3];
float projMatrix[3][3];

// Snip

for(int i = 0; i<4; i++)
{
for(int j = 0; j<4; j++)
{
viewMatrix[j] = 0;
projMatrix[j] = 0;
}
}




You're getting a buffer overflow, which is setting width and height to zero. That causes the aspect ratio to be infinity, which causes your projection matrix to be completely fubar, which causes your vertices to get transformed to invalid positions.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
*** Source Snippet Removed ***
You're getting a buffer overflow, which is setting width and height to zero. That causes the aspect ratio to be infinity, which causes your projection matrix to be completely fubar, which causes your vertices to get transformed to invalid positions.



Thank you for spotting that, I have been looking at this code for hours.

Share this post


Link to post
Share on other sites
Changing DrawPrimitive() to comment out lines 311 and 312 seems to almost get the cube displaying, after making both matrices 4x4 arrays, but I don't really understand the maths behind this properly, so I can't help much more. I'll keep tinkering with it though.

The debugger is your friend [wink]

EDIT: Changing the second cubes WorldPos.Y to 8 kinda helps. Although there's still something wrong.

Share this post


Link to post
Share on other sites
I changed the code like this:

for(int i = 0; i<3; i++)
{
for(int j = 0; j<3; j++)
{
viewMatrix[j] = 0;
projMatrix[j] = 0;
}
}



Does it work for you when you change it this way?

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Changing DrawPrimitive() to comment out lines 311 and 312 seems to almost get the cube displaying, after making both matrices 4x4 arrays, but I don't really understand the maths behind this properly, so I can't help much more. I'll keep tinkering with it though.

The debugger is your friend [wink]

EDIT: Changing the second cubes WorldPos.Y to -8 kinda helps. Although there's still something wrong.


Thanks for helping me out :)
Is the FPS showing correctly on yours?
I still get a blank screen with 0 FPS showing, I just don't understand why the BackBuffer isn't presenting itself.

Share this post


Link to post
Share on other sites
I made a typo - I meant changing to 8, not -8. The backbuffer is presenting, from what I can see, but I still get 0 FPS. Again - learn to use the debugger, it makes life a lot easier.

Another edit:

// Calculate Frame Rate
m_FPSFrameCount++;
m_FPSTimeElapsed += m_TimeElapsed;
if ( m_FPSTimeElapsed > 1.0f)
{
m_FrameRate = m_FPSFrameCount;
m_FPSFrameCount = 0;
m_FPSTimeElapsed = 0.0f;
} // End If Second Elapsed


The code in that block never executes, because FPSTimeElapsed is never >0. Looks like your timer code is broken too, unfortunately.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!