PDA

View Full Version : Raster Image Loading



rakesh_thp
06-30-2009, 03:05 AM
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( left*aspect_ratio, right*aspect_ratio, bottom, top, near, far);
else
glOrtho( left, right, bottom*aspect_ratio, top*aspect_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(&amp;w, &amp;h);
double aspect_ratio = (double)w/(double)h;

glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if ( w > h)
glOrtho( left*aspect_ratio, right*aspect_ratio, bottom, top, near, far);
else
glOrtho( left, right, bottom*aspect_ratio, top*aspect_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

Dark Photon
06-30-2009, 06:47 AM
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.??
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.

rakesh_thp
07-01-2009, 05:04 AM
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.??

Dark Photon
07-01-2009, 09:14 AM
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..
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.

rakesh_thp
07-01-2009, 11:36 PM
Actually the file which i was trying to load is having 96bpi and 1204*1455 ... it does loading and zooming.. but very slowly. on the other hand i tried with same res size 1204*1455, but with 24bpi file.. this works absolutely fine and much faster than the previous one..