Raster Image Loading

Hello,

I am working on development of a graphical application where in one can draw lines, circles, points, load images, scale them and rotate, zooom in and out…

Well, I’m new to this world, but by hook or crook i am able to draw lines, polygons and load image. I’m also able to Zoom upto some extent. I am using wxWidgets for the GUI implementation Using C++.

Here’s my initialization of code for graphics.

int w,h;

GetClientSize(&w,&h); // function which returns the canvas’s height and width
glViewport( 0, 0, (GLint)w, (GLint)h);

if(h==0) h=1;

left=0;
right=(double)w;
top=(double)h;
bottom=0;
near=0;
far=1;

double aspect_ratio = (double)w/(double)h;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if ( w > h)
glOrtho( leftaspect_ratio, rightaspect_ratio, bottom, top, near, far);
else
glOrtho( left, right, bottomaspect_ratio, topaspect_ratio, near, far);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

Then later i catch the mouse scrolling event and write the following code:

if( event.GetWheelRotation() < 0 )
{
left *= 0.75f;
right *= 0.75f;
bottom *= 0.75f;
top *= 0.75f;
near *= 0.75f;
far *= 0.75f;
}
else
{
left *= 1.33f;
right *= 1.33f;
bottom *= 1.33f;
top *= 1.33f;
near *= 1.33f;
far *= 1.33f;
}

int cw,ch;
GetClientSize(&w, &h);
double aspect_ratio = (double)w/(double)h;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if ( w > h)
glOrtho( leftaspect_ratio, rightaspect_ratio, bottom, top, near, far);
else
glOrtho( left, right, bottomaspect_ratio, topaspect_ratio, near, far);

glMatrixMode(GL_MODELVIEW);
this->Refresh(false);

this event catching code is written for mouse scroll of canvas. It works absolutely fine… But it zooms with reference to the origin only… how do i do it with reference to the point where mouse is pointing to.??

Secondly, when i load a high resolution image, it takes lot of time to zoom in / out… in other applications it zooms very fast… if i load low resolution image then it works file… what can be done to improve this drawback…?? is there any way to reduce the resolution of the image before loading.??

Thanks in advance

The usual way is to translate that point to the origin, scale, and then translate back (if desired).

A scale implicitly about 0. So just change what’s 0.

Well amd using true zooming method. as far as my knowledge is concerned, there is no scaling used in this. Well i was wondering if gluLookAt() will help me ore not here…

Anyways, what about my first problem of image resolution.??

Depending on how you’re rendering you could use that.

Anyways, what about my first problem of image resolution.??

From your description, doesn’t sound like an OpenGL problem. You’re saying your loading (from disk?) is too slow. Yeah, you can precompute reduced res versions (say power-of-two reductions down to 1x1), store them on disk with the image, and then when you load, you can load them smallest to largest, and load each power-of-two larger image into a successively larger MIPmap level of the same texture. If you set the MIN_LOD and MAX_LOD on the texture so that only the levels you’ve loaded are used for rendering, you can show your users the texture well before the texture finishes loading. It’ll just get “crisper” as successively larger MIPs load.

Actually the file which i was trying to load is having 96bpi and 12041455 … it does loading and zooming… but very slowly. on the other hand i tried with same res size 12041455, but with 24bpi file… this works absolutely fine and much faster than the previous one…