Sign in to follow this  
skysam

Add 3D model to a game

Recommended Posts

Hi all, I am new to programming and i'm trying to just import or i'll say add a 3D model to show in my game. I do not have to anything special with it. I just want it to show on the screen. Please can anyone help me with this. Cheers sam

Share this post


Link to post
Share on other sites
You need to give WAY more info than that. For instance:


  • What programming language?

  • Have you gotten as far as any form of graphics programming? Can you display things like rotating triangles and the like?

  • OpenGL or DirectX? Or is it something like Allegro/SDL/whatever?

  • Is the model textured at all?

  • Is there to be any lighting in the scene with your model?

  • What format is the model stored in?



If you can't answer these, there's not a lot anyone can do to help you, and depending on the answers you give, you may be sent back to learn a bit more (since you claim to be new to programming).

-Auron

Share this post


Link to post
Share on other sites
Ah, the alure of 3D graphics...

A lot depends on what language you're programming in, but I'll assume you're programming in a common language like C, C++, or Java.

Are you familiar with any APIs that are capable of rendering 3D geometry to the screen (OpenGL, DirectX, ect?). If not, I'd recommend that you find one, and get to know it. NeHe, of course, has some great tutorials on OpenGL.

In any case, there are 2 basic steps you must complete before getting a model into your game:


  1. Read the model data from a stream or file - I suggest you read up on some common formats, such as .obj, .3ds, and .x

  2. Display the model - This is really quite simple once you understand your rendering API.


Of course, each step has its prerequisites. To learn an API, for instance, you need to be pretty familiar with the language you are programming in.

If you don't want to deal with the nitty-gritty file parsing and display setup and whatnot, there are several high-level libraries that can make your life easier, such as SDL and 3DSLib.

Anyway, I imagine the first thing you should do is start google-ing, find some examples, get an idea of what must be done, and start trying to do it yourself.

Have fun, and good luck!

Share this post


Link to post
Share on other sites
Ok
I have not done any graphics progrmming before this is my first time. I am really new to game proamming. I am using C or C++. The model is stored as a 3DS file. I do not really know much on graphics but i'll guess it will be OpenGL or DirectX.

http://www.help3d.com/php/4images/details.php?image_id=6980&s=dec8ddc492783e338d47a4166d115741

That is the link i got the 3D model from.

I am not sure about the textured part. I do not intend to do anything more than just to show the model on the game screen but, if someone can easily help ith lightning or in other thing i'll be grateful.

Thank You.

Share this post


Link to post
Share on other sites
If you are completely new to graphics programming, then start by choosing to learn either OpenGL or DirectX. My preference is inconsequential, but I can assure you that you can get that model on the screen a whole lot sooner if you use Direct3D, since it has built-in facilities for loading and rendering models (provided they're in the .X format, which you can convert to from 3DS using plenty of freely available tools). Either way, you will have to learn a bit about Win32 programming to be able to initialize either library with C++.

Once you've decided which API to use, you should start learning it. For DirectX, I recommend the tutorials at Drunken Hyena and at Toymaker, and for OpenGL, I recommend the fantabulous NeHe. Alternately, you could go out and buy a book on one of the APIs (can only recommend Beginning OpenGL Game Programming, since it's the only book I have, and a mighty fine one at that). The tutorial sites, and the book I mentioned should also give you a primer on the Win32 code necessary to get going. After that, it'll take a bit more work to learn how to import your model (in whatever format it ends up in) and then finally display it.

Texture and lighting details will come up as you learn about the APIs, so by the time you're ready to display the mesh, you shouldn't have too much difficulty setting those up.

I advise you now that will likely be a long-ish and complicated process before you can say you're truly comfortable with either API, but in the end it's well worth it!

-Auron

Share this post


Link to post
Share on other sites
Quote:
Original post by skysam
Ok
I have not done any graphics progrmming before this is my first time. I am really new to game proamming. I am using C or C++. The model is stored as a 3DS file. I do not really know much on graphics but i'll guess it will be OpenGL or DirectX.

http://www.help3d.com/php/4images/details.php?image_id=6980&s=dec8ddc492783e338d47a4166d115741

That is the link i got the 3D model from.

I am not sure about the textured part. I do not intend to do anything more than just to show the model on the game screen but, if someone can easily help ith lightning or in other thing i'll be grateful.

Thank You.


Well, you need to choose some kind of graphics library, as that'll be the way you'll be displaying your graphic. I recommend OpenGL, easy to use, low level enough, and requires a lot less set-up then DX.

First, you'll need to load the file into memory. While doing this, you need to parse through it and find the data that you need. A .3ds file works like a hierarchy, under certain elements are pieces of data. A detailed list can be found at The Labs. A practical way to code this can be found at Space Simulator. Once you understand how to do that, you can create a function to load the data you need into where you want it to be. After you've done that, you can load a texture using another file loader for, say a .bmp file. How you apply the texture to the model is graphics dependant, as is drawing the graphic. Can't give you too much more information, as we don't know the graphics library you're using.

Share this post


Link to post
Share on other sites
Hey all,

I am doing some research on how to load the 3D model. I have a source code but i have an error when i try to compile it. Please does any one want to have a look at the codes?

The error is:

d:\My Documents\CP2082 Games Development 1\d3d_mesh\main.cpp(55): error C2065: 'D3D_SDK_VERSION' : undeclared identifier


Cheers

Sam

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