Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have been learning C++ for long time (but only learning game development for eight days) and I have made a simple game using 2D textures.

I was thinking of starting on 3D game development. I wanted to begin by loading and rendering a 3D model on the program, but I dont know how.

Can anybody tell me if this function could be changed to output 3D model:

GLuint loadTexture( const string &fileName )
{
SDL_Surface *image = IMG_Load( fileName.c_str() );

SDL_DisplayFormatAlpha(image);

unsigned object(0);

glGenTextures(1, &object);

glBindTexture(GL_TEXTURE_2D, object);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image -> w, image -> h, 0, GL_RGBA,     
GL_UNSIGNED_BYTE, image -> pixels);

//Free surface
SDL_FreeSurface(image);

Also what format should I use for this? I am using Blender, and I have seen it can export to a variety of formats. I don't know which would be the best for this kind of stuff and for serious game development.

share|improve this question

migrated from superuser.com Jul 9 '11 at 0:25

This question came from our site for computer enthusiasts and power users.

    
Mmm idk how to traslade it to there can a moderator help me? –  Leandro Jul 8 '11 at 23:10
    
Yes i requested a moderator to move it but it hastn be checked yet i would be right if I repos this on any of the sites you tell me guys –  Leandro Jul 9 '11 at 0:20
    
Thank you moderators –  Leandro Jul 9 '11 at 0:28
    
You're gonna want to spend some time here: nehe.gamedev.net Google searches on topics like '3d models, opengl' will turn up lots of tutorials and helpful pages. –  Amplify91 Jul 9 '11 at 0:40

2 Answers 2

Be warned that the transition into 3D graphics from 2D is much more difficult than the transition into 2D graphics initially. It is much more important to understand the fundamental mathematics involved in 3D graphics, lest you end up breaking your code in ways that won't seem to obvious. I would recommend you familiarize yourself with basic linear algebra, matrices and vectors. If you have the resources, purchasing the books "A Geometry Toolbox" and/or "Fundamentals of Computer Graphics, 3rd Ed," would be great.

That said, it sounds like the crux of your specific question has to do with loading 3D models. You won't really be able to adapt your existing texture loading function for that purpose (although you will still find texture loading useful when you want to apply textures to your models).

Blender can indeed export a variety of formats -- there is no such thing as the "best" choice here, as all options have pros and cons. Some, however, have more of one or the other. Starting out, I would recommend you try to parse and load the .obj file format. It's very straightforward, and you should be able to find a variety of example code and tutorials online to help you load it if you get stuck.

There's also the .smd file format, which is only slightly more complex and supports animation.

If you prefer to avoid writing the loaders yourself, you can use a 3rd party library like the Open Asset Importer Library.

share|improve this answer
    
Interesting obj file seems to have a lot of info –  Leandro Jul 9 '11 at 2:55

This function (loadTexture()) appears to be for loading textures, not rendering 3D models.
Here is a tutorial on C++ OpenGL, it starts out basic, but goes into 3D rendering farther on in the tutorial

share|improve this answer
    
Cool man ill check this –  Leandro Jul 8 '11 at 23:35
    
Well seems to teach how to render the drawed 3D texture but not actually how to load my 3ds model created externally –  Leandro Jul 8 '11 at 23:57
    
you can always use the XNA Framework with C# but if youre doing OpenGL it is doubtful you have any experience with .NET... –  Nate Koppenhaver Jul 18 '11 at 17:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.