Click to See Complete Forum and Search --> : Advice on OpenGL project...


yamokosk
November 5th, 2004, 11:25 PM
Bear with me because although I am somewhat experienced in C++, an amateur in MFC, I am just getting started with OpenGL.

I am trying to write an application where you can display a tiff image and on top of that tiff image, manipulate (rotate/translate) a 3-D model. Obviously, OpenGL is capable of handling the 3-D model stuff.. but what about the tif image? Can images be displayed by GL?

If this explanation of the problem is to vague let me know and I can elaborate further.

Gabriel Fleseriu
November 6th, 2004, 03:03 PM
OpenGL doesn't have primitives for loading images, AFAIK. But you can use some image library to do the job, Here is a link:

http://www.codeproject.com/bitmap/graphicsuite.asp?print=true

yamokosk
November 7th, 2004, 09:21 PM
Thanks for the insight. I am aware of code or libraries to load/save/display images but I really need to be able to overlay a 3D graphics model on top of a tiff image... in the same view. Is this just not possible with OpenGL?

If not, does anyone have a better idea?

wien
November 8th, 2004, 02:05 AM
Yes, it's possible. You you need to load the tiff image (using some kind of library) as a texture and map it onto a quad or something. Draw that in the background of your OpenGL scene, and draw your 3D objecs on top of that.

wolamp
November 8th, 2004, 05:27 AM
search vc7-help for: "OpenGL, texture mapping"

there is an article series... 1 to 7:

Rogerson, Dale. "OpenGL I: Quick Start." December 1994. (MSDN Library, Technical Articles)

chapter 7 is important:

"OpenGL VII: Scratching the Surface of Texture Mapping"

---

here is a code fragment I did a while ago:

first you have to load the bitmap:

//
// load Bitmap, and convert to OpenGL format
//
void CToolDoc::prepBitmap()
{
m_bmpBitmap.LoadBitmap(IDB_BACKGND);

BITMAP bm;
m_bmpBitmap.GetBitmap(&bm);

WORD nBits = bm.bmBitsPixel;

m_bmw = bm.bmWidth;
m_bmh = bm.bmHeight;

m_bmsiz = m_bmw * m_bmh * nBits;
m_bmsiz /= 8;

m_Bdata = new BYTE[m_bmsiz];
m_bmpBitmap.GetBitmapBits(m_bmsiz, m_Bdata); // must be correct size !

// swap red / blue
BYTE tcol;
for(int ii=0; ii<m_bmsiz; ii+=4) {
tcol = m_Bdata[ii ];
m_Bdata[ii] = m_Bdata[ii +2];
m_Bdata[ii +2] = tcol;
}
}

then in your output function:

// draw a surfice

double s = 1.8;

::glBegin(GL_QUADS);

glNormal3d(0, 0, -s);

glTexCoord2d(0, 0);
glVertex3d(-s, s, -s);

glTexCoord2d(1, 0);
glVertex3d(s, s, -s);

glTexCoord2d(1, 1);
glVertex3d(s, -s, s);

glTexCoord2d(0, 1);
glVertex3d(-s, -s, s);

::glEnd();

// and texture it

::glTexImage2D(GL_TEXTURE_2D, 0, 3, m_bmw, m_bmh, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_Bdata);
---------

good luck!

hemmul
November 9th, 2004, 07:04 AM
Bear with me because although I am somewhat experienced in C++, an amateur in MFC, I am just getting started with OpenGL.

I am trying to write an application where you can display a tiff image and on top of that tiff image, manipulate (rotate/translate) a 3-D model. Obviously, OpenGL is capable of handling the 3-D model stuff.. but what about the tif image? Can images be displayed by GL?


sure thing! somewhere on NeHe Productions (http://nehe.gamedev.net) there is a tutorial N41 that deals with IPicture, and the link to the basecode for that. But i doubt that IPicture supports *.tiff... anyway on wotsit (http://wotsit.org) You can search for specifications for *.tiff format, and find out how to retrieve pixel color bits from the file. After that You are ready to create a texture (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06) in OpenGL, and apply it to whatever object You want - whether it is a simple quad, or even a complex 3D object :) Check out other tutorials on NeHe Productions for various texture mapping techniques :)