How to scale the image

Hi experts,
I am loading an image using OpenGL texturing in MDI CView in VC++.I am displaying an image using the Command
glTranslatef(0.0f,0.0f,-250.0f). Now I want to Enlarge the image.so i change the zvalue of the glTranslatef like glTranslatef(0.0f,0.0f,-350.0f).
so, the image enlarged.But, I want to enlarge the image using glScalef().if i give glScalef it didn’t work.
what can i do? any help.

coding is following :

void CLoadMapView::OnPaint()
{
CPaintDC dc(this);
glClearColor(0.0, 0.0, 0.0, 0) ;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;
glEnable(GL_TEXTURE_2D) ;
glPushMatrix() ;
glTranslatef( 0.0f,0.0f,-250.0f) ;
glBindTexture(GL_TEXTURE_2D, m_textureID);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glBegin(GL_QUADS);
glTexCoord2f(1.0,0.0) ;
glVertex3f((GLdouble)m_width/8 ,(GLdouble)-m_height/8,-0.5) ;
glTexCoord2f(0.0,0.0) ;
glVertex3f((GLdouble)-m_width/8,(GLdouble) -m_height/8,-0.5) ;
glTexCoord2f(0.0,1.0) ;
glVertex3f((GLdouble)-m_width/8,(GLdouble) m_height/8,-0.5) ;
glTexCoord2f(1.0,1.0) ;
glVertex3f((GLdouble)m_width/8, (GLdouble)m_height/8,-0.5) ;
glEnd() ;
glPopMatrix() ;
glDisable(GL_TEXTURE_2D) ;
SwapBuffers(dc) ;
}
void CLoadMapView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy) ;
GLdouble fAspect ;
fAspect = 1.0f ;
HWND hWnd = GetSafeHwnd() ;
HDC hDc = ::GetDC(hWnd) ;
wglMakeCurrent(hDc, m_hGLContext) ;
m_width = cx ;
m_height = cy ;
fAspect = (GLdouble)m_width /(GLdouble)m_height ;
if(m_width== 0 || m_width == 0)
return ;
glMatrixMode (GL_PROJECTION) ;
glLoadIdentity() ;
gluPerspective(40.0f, fAspect, 1.0f, 500.0f) ;
glViewport (0, 0, m_width, m_height) ;
glMatrixMode(GL_MODELVIEW) ;
glLoadIdentity() ;
}

glScalef should work if you call it on the MODELVIEW matrix. i dont see glScalef in your code though. what do you mean by “it doenst work”?

I don’t think that posting the same message multiple time will help.

Just substitute

glTranslatef( 0.0f,0.0f,-250.0f);

with

glScalef(scaleFactor,scaleFactor, 1.0);

where scaleFactor != 0.
And should work.

Actually you are not scaling the image, you are scaling the polygons where the image is mapped. :slight_smile:

Hi Rosario Leonardi,
Thanks for reply.I just substitude the code. but also it didn’t work.
Absolutely, I am scaling the polygon where the image is mapped.

when i substitude the code, the image did’nt display on the window. what can i do.?

Hi Rosario Leonardi,
Thanks for reply.I just substitude the code. but also it didn’t work.
Absolutely, I am scaling the polygon where the image is mapped.

when i substitude the code, the image did’nt display on the window. what can i do.?

your transformations are messed up. the polygon (not the image) is not displayed because its either very small depending on your scale values or its out of the viewport (clipped). how do you control your view/camera?

Yes the quad is clipped (the vertexes are in -0.5 and the clip plane is at 1.0).
Place the quad vertexes at somewhere between 1.0 ~ 500.0

Also check the vertex order. They should be in counterclockwise order. When you will enable the face culling the quad will be culled.

Hi experts,
Thanks for the reply. Now it works fine. The image displayed. I am scaling using glScalef(1.0, 1.0, 500.0).
when I decrease 50 to the z scale factor,it will enlarge. but x and y positions of the window is varying after i enlarged. I want to same x y position when i am enlarging the image . what can i do? awaiting your reply?

this

glScalef(1.0, 1.0, 500.0);

don’t look like this

glScalef(scaleFactor,scaleFactor, 1.0);

I think that it’s time to stop random programming and read a good 3d math book.
http://www.amazon.com/exec/obidos/ASIN/1556229119/

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.