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() );


unsigned object(0);

glGenTextures(1, &object);

glBindTexture(GL_TEXTURE_2D, object);



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

//Free surface

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.

  • \$\begingroup\$ Mmm idk how to traslade it to there can a moderator help me? \$\endgroup\$
    – Leandro
    Commented Jul 8, 2011 at 23:10
  • \$\begingroup\$ 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 \$\endgroup\$
    – Leandro
    Commented Jul 9, 2011 at 0:20
  • \$\begingroup\$ 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. \$\endgroup\$
    – Amplify91
    Commented Jul 9, 2011 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.

  • \$\begingroup\$ Interesting obj file seems to have a lot of info \$\endgroup\$
    – Leandro
    Commented Jul 9, 2011 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

  • \$\begingroup\$ Cool man ill check this \$\endgroup\$
    – Leandro
    Commented Jul 8, 2011 at 23:35
  • \$\begingroup\$ Well seems to teach how to render the drawed 3D texture but not actually how to load my 3ds model created externally \$\endgroup\$
    – Leandro
    Commented Jul 8, 2011 at 23:57
  • \$\begingroup\$ you can always use the XNA Framework with C# but if youre doing OpenGL it is doubtful you have any experience with .NET... \$\endgroup\$ Commented Jul 18, 2011 at 17:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .