• 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.
Sign in to follow this  
Followers 0
LeLorrain

At the gate to Window Graphics

0 posts in this topic

Hello people,

I am new to windows graphic on my way to learn directx by myself, and, of course, I hit a brick wall!

To start in the tutorial I use, the display of my rendering is done with GDI and all I get is a black window. I wonder if any of you would be nice enough to take a look at my code and tell me what I did wrong.

Please, no comment on the use of GDI, I'll get to display with DirectX in the next lesson. The first lesson was to teach me about rendering 3D on a 2D screen and the various transformations to do it, although we use DirectX to handle the matrices.

From what I see, the vertex coordinates at the "DrawLine" method are correct and fit in the window Rect. The objects are two rotating cubes in wireframe.

Here is the relevant code:

[CODE]
bool
GameApp::BuildBuffer ( long width, long height )
{
HDC hDC = ::GetDC (m_hWnd);
if (NULL == m_hDC) {
m_hDC = ::CreateCompatibleDC (hDC);
}
m_hBackBuffer = ::CreateCompatibleBitmap (hDC, width, height);
if (NULL == m_hBackBuffer) {
return false;
}
m_hSavedBuffer = (HBITMAP)::SelectObject (hDC, m_hBackBuffer);
::ReleaseDC (m_hWnd, hDC);
::SetBkMode (m_hDC, TRANSPARENT);
return true;
}
void
GameApp::SetupGameState ( void )
{
/********************************\
* View matrix with:
*
* Right = ( 1, 0, 0 )
* Up = ( 0, 1, 0 )
* Eye = ( 0, 0, 1 )
* origin = ( 0, 0, 0 )
* (window origin)
*
\********************************/
// Set the View matrice to Identity
D3DXMatrixIdentity (&m_View);
/********************************\
*
* Perspective Matrix with:
*
* FOV: 60°
* Aspect: Width / Height
* Near: 1.01
* Far: 1000.00
*
\********************************/
// Set the Perspective Matrix
D3DXMatrixPerspectiveFovLH (&m_Projection, (float)D3DXToRadian (60.0), (float)m_ViewWidth / (float)m_ViewHeight, 1.01, 1000.0);
return;
}
int
GameApp::BeginGame ( void )
{
MSG msg;
int rc = 0;
// Start main loop
while (true) {
if (::PeekMessage (&msg, NULL, 0, 0,PM_REMOVE)) {
if (WM_QUIT == msg.message) {
rc = msg.wParam;
break;
}
::TranslateMessage (&msg);
::DispatchMessage (&msg);
} else {
FrameAdvance ();
}
}
return rc;
}
void
GameApp::FrameAdvance ( void )
{
// Limit to 60 frames per seconds
m_Timer.LockFPS (60);
// Animate the objects
AnimateObjects ((float)m_Timer.GetIntervalSeconds());
// Clear the buffer
ClearBuffer (0x00FFFFFF);
// Draw objects
for (size_t i = 0; i < m_Objects.size(); ++i) {
Mesh * mesh = &m_Objects[i]->m_Mesh;
// Loop on each polygon
for (size_t j = 0; j < mesh->m_Polygon.size(); ++j) {
DrawPolygon (&mesh->m_Polygon[j], &m_Objects[i]->m_World);
}
}
// Add the frames per second
stringstream ss;
ss << "f/s " << (int)m_Timer.GetFPS() << ends;
TextOut (m_hDC, 5, 5, ss.str().c_str(), ss.str().size());
// Display all
DisplayScene ();
// Success!
return;
}
void
GameApp::AnimateObjects ( float deltaTime )
{
for (size_t i = 0; i < m_Objects.size(); ++i) {
if (m_Objects[i]->m_Rotation) {
D3DXMATRIX rotate;
D3DXMatrixRotationYawPitchRoll (&rotate, (float)(D3DXToRadian (75.0) * deltaTime), (float)(D3DXToRadian (75.0) * deltaTime), (float)(D3DXToRadian (75.0) * deltaTime));
m_Objects[i]->m_World = rotate * m_Objects[i]->m_World;
}
}
return;
}
void
GameApp::ClearBuffer ( D3DCOLOR colour )
{
// Setup the brush to paint the buffer
LOGBRUSH logBrush;
logBrush.lbColor = (COLORREF)(0x00FFFFFF & colour);
logBrush.lbStyle = BS_SOLID;
logBrush.lbHatch = NULL;
// Create the brush
HBRUSH hBrush = ::CreateBrushIndirect (&logBrush);
// Put it into the frame buffer
HBRUSH hOldBrush = (HBRUSH)::SelectObject (m_hDC, hBrush);
LOGPEN pen;
// Setup the pen invisible
pen.lopnStyle = PS_NULL;
pen.lopnWidth.x = 1;
pen.lopnWidth.y = 1;
pen.lopnColor = 0;
// Create the pen
HPEN hPen = ::CreatePenIndirect (&pen);
// Put it into the frame buffer
HPEN hOldPen = (HPEN)::SelectObject (m_hDC, hPen);
// Draw a rectangle covering the Window
::Rectangle (m_hDC, m_ViewX, m_ViewY, (m_ViewX + m_ViewWidth), (m_ViewY + m_ViewHeight));
// Restore the old brush
::SelectObject (m_hDC, hOldBrush);
// Destroy Rendering brush
::DeleteObject (hBrush);
// Restore the old pen
::SelectObject (m_hDC, hOldPen);
// Destroy Rendering pen
::DeleteObject (hPen);
return;
}
void
GameApp::DrawPolygon ( Polygon * polygon, const D3DXMATRIX * world)
{
D3DXVECTOR3 vertex0, vertex1;
size_t n = polygon->m_Vertex.size();
// Loop thru each vector
for (size_t i = 0; i < n + 1; ++i) {
// Transform first vertex to world space
vertex1 = (polygon->m_Vertex[i % n]).SetD3Dvector();
D3DXVec3TransformCoord (&vertex1, &vertex1, world);
// Transform to view space
D3DXVec3TransformCoord (&vertex1, &vertex1, &m_View);
// Convert to screen space
D3DXVec3TransformCoord (&vertex1, &vertex1, &m_Projection);
// Convert to window coords
vertex1.x = m_ViewX + m_ViewWidth * (vertex1.x + 1.0) / 2;
vertex1.y = m_ViewY + m_ViewHeight * (1.0 - vertex1.y) / 2;
// If this is not the first, draw
if (i > 0) {
DrawLine (vertex0, vertex1, 0x00FFFFFF);
}
vertex0 = vertex1;
}
// Success!
return;
}
void
GameApp::DrawLine ( const D3DXVECTOR3 &v0, const D3DXVECTOR3 &v1, const D3DCOLOR colour )
{
LOGPEN pen;
// Setup the rendering pen
pen.lopnStyle = PS_SOLID;
pen.lopnWidth.x = 2;
pen.lopnWidth.y = 1;
pen.lopnColor = (COLORREF)(0x00FFFFFF & colour);
// Create the rendering pen
HPEN hPen = ::CreatePenIndirect (&pen);
// Put it into the frame buffer
HPEN hOldPen = (HPEN)::SelectObject (m_hDC, hPen);
// Draw the line segment
::MoveToEx (m_hDC, (long)v0.x, (long)v0.y, NULL);
LineTo (m_hDC, (long)v1.x, (long)v1.y);
// Restore the old pen
::SelectObject (m_hDC, hOldPen);
// Destroy Rendering pen
::DeleteObject (hPen);
// Success!
return;
}
void
GameApp::DisplayScene ( void )
{
HDC hDC = ::GetDC (m_hWnd);
// Move the back buffer to the screen
::BitBlt (hDC, m_ViewX, m_ViewY, m_ViewWidth, m_ViewHeight, m_hDC, m_ViewX, m_ViewY, SRCCOPY);
// Cleanup
::ReleaseDC (m_hWnd, hDC);
return;
}
[/CODE]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0