Sign in to follow this  

Vertex Buffers? (EDIT: SOLVED) (Direct3D)

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

Aren't most 3D games consisting of more model rendering than using primitives? If so why should I learn vertex buffers instead of trying to learn how to render models? [Edited by - dist0rted on July 22, 2006 12:39:00 PM]

Share this post


Link to post
Share on other sites
well in order to render a model you need to dump all the vertex positions and tex coord etc. into a vertex buffer that gets locked to the video memory. index buffers are useful as you can use one vertex's information to describe many verticies.

So basically you need to learn about VBs/IBs because that is how DirectX renders. The primitives you are talking about are the polygons used to create the model.

Share this post


Link to post
Share on other sites
Ah, I figured they were only used to make a faster method than DrawPrimitiveUP(). The reason why I asked is because until I started trying to define a custom VertexBuffer and IndexBuffer class, all my code was fine. Now I'm getting errors every time I declare a class/struct where it says "error C2236: unexpected 'struct' '<class name here>'. Did you forget a ';'?"

Share this post


Link to post
Share on other sites
Draw[Indexed]Primitive() (i.e., vertex buffers) should be your standard rendering method. Draw[Indexed]PrimitiveUP() should be used only for quick-and-dirty debug rendering, if at all. It is quite slow.

Share this post


Link to post
Share on other sites
Quote:
Original post by dist0rted
Ah, I figured they were only used to make a faster method than DrawPrimitiveUP(). The reason why I asked is because until I started trying to define a custom VertexBuffer and IndexBuffer class, all my code was fine. Now I'm getting errors every time I declare a class/struct where it says "error C2236: unexpected 'struct' '<class name here>'. Did you forget a ';'?"


Well, *did* you forget a ';'? (Remember that you need one after each class/struct body.)

Share this post


Link to post
Share on other sites
Of course not, as a matter of fact - here's the code for the header file with errors:

CDGApplication.h:

#pragma once

#include "dgproject.h"

struct CDGApplication
{
CDGApplication(void);
virtual ~CDGApplication(void) { Shutdown(); }

HINSTANCE m_hInstance;
HWND m_hWnd;
MSG m_Msg;
WNDCLASSEX m_WndClass;

char *m_pszAppTitle;
DGINT m_nWidth;
DGINT m_nHeight;
DGBOOL32 m_bWindowed;

LPDIRECT3D9 m_pD3D;
LPDIRECT3DDEVICE9 m_pd3dDevice;
D3DPRESENT_PARAMETERS m_PresentParameters;

static LRESULT WINAPI m_fnWndProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam);

DGRESULT Init(char *pszAppTitle, DGINT nWidth, DGINT nHeight, DGBOOL32 bWindowed);
void EventLoop(void);
void Shutdown(void);

virtual DGRESULT OneTimeSceneInit(void) { return DG_OK; }
virtual DGRESULT InitDeviceObjects(void) { return DG_OK; }
virtual DGRESULT RestoreDeviceObjects(void) { return DG_OK; }
virtual DGRESULT InvalidateDeviceObjects(void) { return DG_OK; }
virtual DGRESULT DeleteDeviceObjects(void) { return DG_OK; }
virtual DGRESULT Render(void) { return DG_OK; }
virtual DGRESULT FinalCleanup(void) { return DG_OK; }
};

Share this post


Link to post
Share on other sites
Quote:
Original post by dist0rted
Of course not, as a matter of fact - here's the code for the header file with errors:

CDGApplication.h:
*** Source Snippet Removed ***


You may have forgotten a ';' somewhere inside dgproject.h. Remember, when you include a file, its contents are practically copied in place of the include statement. So if you're 100% sure that there are no problems in a specific file, but the compiler still generates errors, look into your includes.

Share this post


Link to post
Share on other sites
I swear upon all that's holy, none of my files had changed besides the four new files I created: CDGVertexBuffer.h/cpp and CDGIndexBuffer.h/cpp. After defining those classes gave me errors, I deleted them and now I'm getting errors on CDGApplication (it's the only class I have now where I define method functions in a seperate source file, now).

Share this post


Link to post
Share on other sites
a syntax error is hardly reason enough for you to not learn the necesseties of your graphics API of choice :) Vertex Arrays are a very important step in graphics programming, don't let a trivial error like this get in the way of becoming a better graphics programmer.

As V0dKA said, this missing semicolon could be elsewhere in your program (often times errors point you in the totally wrong direction). The most likely culprit is any file that is being included in the file the error is coming from.

good luck

Share this post


Link to post
Share on other sites
Freaky things happen with Visual Studio. I once fixed errors by moving the definition of a function into a different file. I would similarly be willing to swear upon everything that's holy that there was nothing wrong with the old file.

Try temporarily moving just the function definitions to just after your main() or WinMain(), or whatever it would be in your case.

Beyond that, I have no clue...

Share this post


Link to post
Share on other sites
Alrighty, I'll keep messing around, but here's the complete list of errors:


1&gt;------ Build started: Project: DGLIB, Configuration: Debug Win32 ------
1&gt;Compiling...
1&gt;CDGApplication.cpp
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.h(6) : error C2236: unexpected 'class' 'CDGApplication'. Did you forget a ';'?
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.h(6) : error C2143: syntax error : missing ';' before '{'
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.h(6) : error C2447: '{' : missing function header (old-style formal list?)
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(3) : error C2653: 'CDGApplication' : is not a class or namespace name
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(4) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(5) : error C2065: 'm_hInstance' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(6) : error C2065: 'm_hWnd' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(7) : error C2065: 'm_Msg' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(7) : error C2070: ''unknown-type'': illegal sizeof operand
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(8) : error C2065: 'm_WndClass' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(8) : error C2070: ''unknown-type'': illegal sizeof operand
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(10) : error C2065: 'm_pszAppTitle' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(11) : error C2065: 'm_nWidth' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(12) : error C2065: 'm_nHeight' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(13) : error C2065: 'm_bWindowed' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(15) : error C2065: 'm_pD3D' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(16) : error C2065: 'm_pd3dDevice' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(17) : warning C4508: 'CDGApplication' : function should return a value; 'void' return type assumed
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(19) : error C2653: 'CDGApplication' : is not a class or namespace name
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(43) : error C2653: 'CDGApplication' : is not a class or namespace name
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(54) : error C2228: left of '.cbClsExtra' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(55) : error C2228: left of '.cbSize' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(56) : error C2228: left of '.cbWndExtra' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(57) : error C2228: left of '.hbrBackground' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(58) : error C2228: left of '.hCursor' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(59) : error C2228: left of '.hIcon' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(60) : error C2228: left of '.hIconSm' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(61) : error C2228: left of '.hInstance' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(62) : error C2228: left of '.lpfnWndProc' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(63) : error C2228: left of '.lpszClassName' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(64) : error C2228: left of '.lpszMenuName' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(65) : error C2228: left of '.style' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(107) : error C2227: left of '-&gt;GetAdapterDisplayMode' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(113) : error C2227: left of '-&gt;GetDeviceCaps' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(142) : error C2065: 'm_PresentParameters' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(142) : error C2070: ''unknown-type'': illegal sizeof operand
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(153) : error C2227: left of '-&gt;CheckDeviceFormat' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(155) : error C2228: left of '.AutoDepthStencilFormat' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(162) : error C2227: left of '-&gt;CheckDeviceFormat' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(164) : error C2228: left of '.AutoDepthStencilFormat' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(171) : error C2227: left of '-&gt;CheckDeviceFormat' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(173) : error C2228: left of '.AutoDepthStencilFormat' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(180) : error C2228: left of '.BackBufferCount' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(181) : error C2228: left of '.BackBufferFormat' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(182) : error C2228: left of '.BackBufferWidth' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(183) : error C2228: left of '.BackBufferHeight' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(184) : error C2228: left of '.EnableAutoDepthStencil' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(185) : error C2228: left of '.FullScreen_RefreshRateInHz' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(186) : error C2228: left of '.hDeviceWindow' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(187) : error C2228: left of '.MultiSampleQuality' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(188) : error C2228: left of '.MultiSampleType' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(189) : error C2228: left of '.PresentationInterval' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(190) : error C2228: left of '.SwapEffect' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(191) : error C2228: left of '.Windowed' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(194) : error C2227: left of '-&gt;CreateDevice' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(203) : error C3861: 'OneTimeSceneInit': identifier not found
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(208) : error C3861: 'InitDeviceObjects': identifier not found
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(213) : error C3861: 'RestoreDeviceObjects': identifier not found
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(221) : error C2653: 'CDGApplication' : is not a class or namespace name
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(224) : error C2070: ''unknown-type'': illegal sizeof operand
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(226) : error C2228: left of '.message' must have class/struct/union
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.cpp(226) : fatal error C1903: unable to recover from previous error(s); stopping compilation
1&gt;Main.cpp
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.h(6) : error C2236: unexpected 'class' 'CDGApplication'. Did you forget a ';'?
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.h(6) : error C2143: syntax error : missing ';' before '{'
1&gt;d:\my documents\visual studio 2005\projects\dglib\cdgapplication.h(6) : error C2447: '{' : missing function header (old-style formal list?)
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(6) : error C2504: 'CDGApplication' : base class undefined
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(19) : error C2065: 'm_pd3dDevice' : undeclared identifier
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(19) : error C2227: left of '-&gt;SetTransform' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(20) : error C2227: left of '-&gt;SetTransform' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(23) : error C2227: left of '-&gt;SetTransform' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(25) : error C2227: left of '-&gt;SetRenderState' must point to class/struct/union/generic type
1&gt; type is ''unknown-type''
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(44) : error C2039: 'Init' : is not a member of 'CMyDGApplication'
1&gt; d:\my documents\visual studio 2005\projects\dglib\main.cpp(5) : see declaration of 'CMyDGApplication'
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(46) : error C2039: 'EventLoop' : is not a member of 'CMyDGApplication'
1&gt; d:\my documents\visual studio 2005\projects\dglib\main.cpp(5) : see declaration of 'CMyDGApplication'
1&gt;d:\my documents\visual studio 2005\projects\dglib\main.cpp(49) : error C2039: 'Shutdown' : is not a member of 'CMyDGApplication'
1&gt; d:\my documents\visual studio 2005\projects\dglib\main.cpp(5) : see declaration of 'CMyDGApplication'
1&gt;Generating Code...
1&gt;Build log was saved at "file://d:\My Documents\Visual Studio 2005\Projects\DGLIB\Debug\BuildLog.htm"
1&gt;DGLIB - 73 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Share this post


Link to post
Share on other sites
NOTE: If I rearrange which order I include CDGApplication.h/CDGVertexBuffer.h/CDGIndexBuffer.h, the error output will be different (the errors will come from a different header file). The errors I posted earlier were from when I just included CDGApplication.h and neither of the other two.

EDIT: Just as an explanation, I don't use "#pragma once" because this file is included in just about every file in the project, and doing so will create errors. (And since there's no definitions like functions or classes that will create linker errors, it's no problem.)

dgproject.h:

/*

dgproject.h : Distorted Graphics Library main header file

*/


// link w/ D3D and more!
#pragma comment(lib, "d3d9.lib") // Direct3D 9
#pragma comment(lib, "d3dx9.lib") // D3D X Library
#pragma comment(lib, "dxguid.lib") // DirectX GUI definition
#pragma comment(lib, "winmm.lib") // Windows MultiMedia Library

#include <d3d9.h> // Direct3D 9
#include <d3dx9.h> // D3D X Library
#include <stdio.h> // C Standard I/O
#include <string.h> // C Strings
#include <time.h> // For Time Functions
#include <windows.h> // Windows API

#include "dgdatatypes.h" // Data Types
#include "dgerror.h" // DGRESULT definitions

#include "CDGApplication.h" // class CDGApplication
#include "CDGIndexBuffer.h" // class CDGIndexBuffer
#include "CDGVertex.h" // class CDGVertex
#include "CDGVertexBuffer.h" // class CDGVertexBuffer

#define DGRELEASE(DXObject) { if (DXObject) { DXObject->Release(); DXObject = NULL; } } // Release a DX Object


Share this post


Link to post
Share on other sites
This might not be the source of your problems, but it's well worth noting anyway:

I assume your CDGApplication.cpp file is including CDGApplication.h.
Your CDGApplication.h file includes dgproject.h. But your dgproject.h file is including CDGApplication.h right back! So CDGApplication.h includes dgproject.h which includes CDGApplication.h which includes dgproject.h which includes CDGApplication.h which includes dgproject.h which includes CDGApplication.h which includes dgproject.h which includes CDGApplication.h [...]

I'm not sure if this alone is responsible for causing the problems. In any case, for this reason, having a central header file which includes everything else is a dangerous idea.

I suggest you try commenting out each #include statement one by one and recompiling your project. If the only errors your compiler generates are the ones you would expect due to missing definitions, then whichever header file you commented out could be the culprit. And if switching the order of your includes changes the errors your compiler generates, you could be 95% sure that the problem is within one of your header files.

Share this post


Link to post
Share on other sites
I'll try, and will edit this post with the result, but please remember: I created the entire project this way - it's been working until I created these two new classes. Before that, it compiled just fine and rendered my Direct3D graphics that I'd been doing with DrawPrimitiveUP(). (Also, I have #pragma once to prevent that from happeneing.)

EDIT: Alrighty, the results were quite interesting... I removed the class header files (CDGblahblah.h) from project.h, and just included CDGApplication in my main file... it compiled fine... then I included CDGVertexBuffer/CDGIndexBuffer (and didn't even use the classes in them)... it had compiler errors where I defined a class in WinMain.cpp...

SO! I'm going to host my project files at my web site, to which I will soon edit and put a link on this post.

EDIT: http://www.bulldawggames.com/gamedev/ (It compiles fine, UNLESS I try to include the CDGVertexBuffer.h/CDGIndexBuffer.h files in WinMain.cpp, and I will need to use them!!!)

EDIT (AGAIN!): SOLVED!!!! THANKS to you vodka!

[Edited by - dist0rted on July 22, 2006 12:08:47 PM]

Share this post


Link to post
Share on other sites

This topic is 4164 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.

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