PDA

View Full Version : problem on scaling the image



pnpvivek
12-30-2008, 09:06 PM
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() ;
}

dletozeun
12-31-2008, 04:48 AM
First, one precision, glTranslate is not for display, as its name says, it just applies a translation on the current selected matrix (In this case, the modelview one).
All what glTranslate does here is moving the rendered quad along the Z-axis, the one perpendicular to the screen in this case. So as far as you translate the quad toward negative Z the quad will get smaller.
IMO, this is not a good solution to rescale the quad, (since you cannot push z at the infinite, the quad will be clipped after the far clipping plane). As you said it is better to use glScale and it should work for what you want to do. Now if you want us to help you, you should show us how you use glScalef in your code.