Load obj mtl Direct3D 11 - c++

Quick question, how do i load a .obj modle into directx 11 (d3d11.h) and also the .mtl file for materials. Thanks in advance.

You can write your own parser, obj is a pretty simple text format (format description)
Otherwise some loaders already exists, like Assimp .It only deals with decoding, you will still need to create vertex/index buffers from decoded data.

DirectX no longer comes with any libraries to load object files, such as *.obj, *.x and so on after version 9. You need to either download a library to open these files, or do it yourself since OBJ files are reasonably simple to parse.
See here for an example of this using OpenGL: http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Load_OBJ - the concepts should be reasonably easy to transition across.

Related

OBJ Loader for OpenGL + Glut

I'm working on a game for open GL, and I want to simply be able to load OBJ files, with their textures into my game. I want the loader to contain all the necessary code to map the textures to the object.
(Note I have scoured google, and not one example I've seen has been simple enough to bolt onto my currently existing code, I'm talking 2 headers, and 2 cpps maximum)
Could anybody provide me with one?
you could get started by this simple loader which loads objects in a wavefront .obj file into a OpenGL scene. This code restricts to just scanning the vertex information out of OBJ. You could enhance it further may be after getting the basic idea.
http://netization.blogspot.in/2014/10/loading-obj-files-in-opengl.html
https://github.com/nanosmooth/opengl_objloader
You can find mine at: https://github.com/NewbiZ/sandbox/tree/master/mar_tp1
It's a pretty simple one, but clean.
you will only need the Model class, which will load an OBJ file by filename: https://github.com/NewbiZ/sandbox/blob/master/mar_tp1/inc/mar_tp1/model.h
You may need to remove some things to make it fit on your project. Namely the dependency to ResourceManager which loads the textures and return their id, but that should not be much work.
Hope it helps.

How to convert .obj file to openGL?

I am finding difficulty in converting .obj file into openGL. I have found my model and here i have attach the main.cpp file for your reference. I am unsure of how to run the files.
Which file should I run when I called all these files in openGL.
Initially when I open OpenGL in Visual studio I called main.cpp file and run the file. But it shows many errors. The error says that cant find PDB file. What is that?
I'm just throwing in my answer to clear up the misconception leading to a question like that one:
How to convert .obj file (human head) to openGL?
The answer is: You don't.
OpenGL is a drawing API called from a program. It there for a program to make calls to draw points, lines and triangles. OpenGL is not a file format.
.OBJ is actually not very well defined name for a file format (there are literally hundreds of file formats that end .OBJ). But I take it you mean Wavefront OBJ. Anyway, files contain data. And while a program is data as well, a Wavefront OBJ file is not a program and can not be executed. Hence it makes no sense to even try to formulate a OBJ to OpenGL conversion.
What you need to do is writing a program, that reads the data from the Wavefront OBJ file, and uses that data to make the right calls to OpenGL. The other answers you already got link to such tutorials.
You will need to parse the .obj file then (depending on OpenGL version) load the parsed data into array/element_array buffers then use glDraw[Elements/Arrays] to work with in glsl or draw all the vertices using fixed functions.
But I think the real answer here lies in more study and not jumping in the deep water when you can hardly doggy paddle. You should do more basic exercises and get an understanding of the API.
Oh, and a .pdb file is for debugging in visual studio; I think it stands for program database.
Here is good tiny parser for obj
https://github.com/syoyo/tinyobjloader
You need:
1. parse data
2. create buffer object with data
3. draw buffer object
Yet another OBJ-loading tutorial http://www.opengl-tutorial.org/beginners-tutorials/tutorial-7-model-loading/

Recommended file formats and graphics libraries for importing 3D model into OpenGL/C++ project?

If you wanted to:
model an object in a 3D editor, e.g. Blender, Maya, etc
export the model into a data/file format
import the model into an project using OpenGL and C/C++
Then:
What file format would you recommend exporting to, i.e. in terms of simplicity, portability, and compatibility (i.e. common/popular)?
What graphics libraries would you recommend using to import the model into your OpenGL C/C++ project (i.e. preferably open source)?
Additionally, are there data/file formats that also capture animation, i.e. an "animated model" format, such that the animation could be modeled in the 3D editor and somehow invoked inside the code (e.g. accessibility to frames in the animation sequence or some other paradigm for saving/loading details related to changes over time)?
Generally speaking, I'm seeking simplicity as the priority, i.e. help to get started with combining my backgrounds in both art and computer science. I am a computer science major at UMass while at the same time, sort of a "pseudo" double-major in art by taking electives in graphic design at my university as well as classes at the Art Institute of Boston during summer/winter sessions So, in other words, I am not a complete newbie, but at the same time I don't really want options that are so overloaded with crazy advanced configurations making it too difficult to get started with a basic demonstration project; i.e. as a first step to understanding how to bridge the gap between these two worlds, e.g. creating a program featuring a 3D character that the user can interact with.
COLLADA (I'm saying it with a "ah" at the end), and Assimp (ple as that).
And so, why COLLADA? Simple:
COLLADA is an open standard made by Khronos (Sony specifically). The beauty of an open standard format is that it's, well, a standard! You can be assured that any output of a standard-conformant product would also read correctly by another standard-conformant product. Sad to say though, some 3d modelling products aren't that particular in their measures for standards conformance for COLLADA. But still be rest assured: Blender, Maya, 3ds Max and all the other big names in 3d modelling has good support for the format.
COLLADA uses XML. This makes it much more simpler for you if your planning to create your own reader or writer.
ADDITIONAL: COLLADA is, I think, the only format that is not tied to a specific company. This is a very good thing for us, you know.
ADDITIONAL 2: It is known that COLLADA is slow to be parsed. That's true. But think of it: all other non-binary formats (like fbx) have also the same issues. For your needs, COLLADA should suffice.
ADDITIONAL 3: COLLADA supports animations!
For the importer library, I highly recommend Assimp. Why?
Assimp has support for any popular format you can imagine. It has a unified interface for all formats so that switching to another format is less of a pain.
Assimp is extensible. You can thus import your proprietary format and still not modify your code.
ADDITIONAL 4: Assimp is open source! Let's support open source software!
First , here you can read about suggested model loading lbs.Lib Assimp is really good and supports many formats.For the preferred formats.Collada-I wouldn't recommend because that is XML (text) based formats which is slow to parse. Obj format is also widespread but suffers from the same problems as Collada.It is still good if you want to write your own parser as its structure is very simple.But Instead I would suggest 3Ds which is binary.It doesn't support animations though.The most popular format today which supports both static mesh and animation is FBX.You can download for free FBX SDK from Autodesk and connect it to your engine.The reason I would choose FBX is because both SDK and the format are really robust.For example ,in FBX you can embed not just geometry and animation but also scene objects as lights ,cameras etc.Autodesk docs are very nice too.
Hope it helps.
I would reccomend using your own custom format that basically just a binary dump of the vertex buffer and index buffers used in your program. (Using d3d terms there, I know opengl has the same concepts but can't remember if they have different names).
I would then write a separate program using assimp that takes pretty much any format and writes out the file in your custom format. Then you can use collada or whatver to store your actual models in, but not have the complixity and slowness of loading that format at run time.

generate 3dsMax object

Im coding Computer Graphich project which draws a glass in OpenGL, so I did make a glass model in 3dsMax but dont know how to generate it to file which contains co-ordinate of points of glass to use for OpenGL code. Anyone know?
You need to write 3ds max exporter plugin using 3ds max sdk and export the model. For a beginner this is going to be extremely difficult.
Alternatively, you could export from 3dsmax into some kind of format that is easy to parse and write importer for that format in your program.
Or you could try searching for the library that can parse one of the formats 3dsmax can export.
The following link is to a partially implemented .3ds loader written by: Matthew Fairfax
http://www.garagegames.com/community/resources/view/506
This was what I used while I was at university to read in objects. This loader only really includes the mesh data and possibly the material data. But if you look at the 3ds file format it should be fairly easy to get the rest of the parts reading in as well.
using google for about 20s I also found the following link which looks fairly detailed for the file format and has code at the bottom that should help you work out the loading.
http://www.martinreddy.net/gfx/3d/3DS.spec

C++ Importing and Renaming/Resaving an Image

Greetings all,
I am currently a rising Sophomore (CS major), and this summer, I'm trying to teach myself C++ (my school codes mainly in Java).
I have read many guides on C++ and gotten to the part with ofstream, saving and editing .txt files.
Now, I am interested in simply importing an image (jpeg, bitmap, not really important) and renaming the aforementioned image.
I have googled, asked around but to no avail.
Is this process possible without the download of external libraries (I dled CImg)?
Any hints or tips on how to expedite my goal would be much appreciated
Renaming an image is typically about the same as renaming any other file.
If you want to do more than that, you can also change the data in the Title field of the IPTC metadata. This does not require JPEG decoding, or anything like that -- you need to know the file format well enough to be able to find the IPTC metadata, and study the IPTC format well enough to find the Title field, but that's about all. Exactly how you'll get to the IPTC metadata will vary -- navigating a TIFF (for one example) takes a fair amount of code all by itself.
When you say "renaming the aforementioned image," do you mean changing metadata in the image file, or just changing the file name? If you are referring to metadata, then you need to either understand the file format or use a library that understands the file format. It's going to be different for each type of image file. If you basically just want to copy a file, you can either stream the contents from one file stream to another, or use a file system API.
std::ifstream infs("input.txt", std::ios::binary);
std::ofstream outfs("output.txt", std::ios::binary);
outfs << insfs.rdbuf();
An example of a file system API is CopyFile on Win32.
It's possible without libraries - you just need the image specs and 'C', the question is why?
Targa or bmp are probably the easiest, it's just a header and the image data as a binary block of values.
Gif, jpeg and png are more complex - the data is compressed