Advertisement

non-scaleable textures in OpenGL

Started by May 09, 2002 06:41 PM
7 comments, last by shurcool 22 years, 9 months ago
hi, i''m pretty good with OpenGL, so no need to send me to nehe, i just have one question, and i hope some of you might know the answer. anyway, i want to figure out if it''s possible to somehow render textures (on a quad) in such a way, that the textures wouldn''t get scaled, or streteched. for example, if my texture is 64x64, and how would i render it (in 2d ortho perspective, of course) so that it would take up exactly 64x64 pixels on the screen? is there any "official" way to do it, or would i just have to manually sync the size of the quad to the size of the textures? the problem is that i will have a large number of textures, that are 256x256, and i will use portions of it. any ideas? oh, now that i''m asking that, i also wanted to know if the textures that are loaded in all (early, at least) nehe tutorials in a GLuint are stored in RAM, or video memory? help would be greately appreciated. --- umm... bah?
quote:
Original post by shurcool
anyway, i want to figure out if it''s possible to somehow render textures (on a quad) in such a way, that the textures wouldn''t get scaled, or streteched.


Set up ortho projection and viewport so that your viewport width/height are the same as width/height of the client area of your window. Then just render 64x64 or whatever quads.
quote:

oh, now that i''m asking that, i also wanted to know if the textures that are loaded in all (early, at least) nehe tutorials in a GLuint are stored in RAM, or video memory?


It depends. Someone more knowledgeable than me can probably provide more details.
---visit #directxdev on afternet <- not just for directx, despite the name
Advertisement
Unless I''m sorely mistaken, both textures and display lists are stored in video memory. What else would you use 128mb of memory on a gf4 for besides frame buffers etc?
quote:
Original post by DC_Tsunami
Unless I'm sorely mistaken, both textures and display lists are stored in video memory. What else would you use 128mb of memory on a gf4 for besides frame buffers etc?


that's true, but then again, unless u only use the GLuint for loading textures in ram, but then OpenGL puts it in video memory from there, i don't see how else it would get there.

and about IndirectX's solution. first of all, my resolution can be changed (in what game it CAN'T BE?). secondly, to keep game fair for all online players, no matter what resolution you will have, u still will only be able to see the same amount of the map (think of this game as of a 2d side-scroller). therefore, to keep the player (they're textured quads) sizes equal on all resolutions, you'd of course have to scale them. but for the hud, and font, etc. i would like to not stretch/scale it at all, if possible. hopefully that explains what i need in a bit more detail. thanks again!

---
umm... bah?

[edited by - shurcool on May 9, 2002 8:40:54 PM]
quote:

Shurcool:
first of all, my resolution can be changed


Surely, as IndirectX said, just re-issuing the projection matrix & viewport via 'glOrtho' and 'glViewport' with the new display dimensions will solve this?

quote:

Shurcool:
but for the hud, and font, etc. i would like to not stretch/scale it at all, if possible.


Which you won't need to do if your projection changes with your resolution surely?!?
quote:

Shurcool:
but then again, unless u only use the GLuint for loading textures in ram, but then OpenGL puts it in video memory from there, i don't see how else it would get there.


What do you mean??? The GLuint is only a handle, you have no direct control over where GL stores its texels. You can use 'glAreTexturesResident' to find out where named textures are being stored and 'glPrioritizeTextures' to hint that certain named textures should be kept in video memory, but that's about it.

*confused*

Jans.

[edited by - jansic on May 9, 2002 9:12:55 PM]
As Jansic said: keep two ortho matrices around. One is fixed, let''s say, to 800x600 and the other one changes with resolution. Use the first matrix to draw HUD and the second one to draw players. As long as you have the same aspect ratio in all modes, you''ll be fine.
---visit #directxdev on afternet <- not just for directx, despite the name
Advertisement
Your question is nebulous...

Having said that, I personally have a function in my engine called SetRenderMode, which takes a parameter of an enumerated type equal to one of these values:
CAFFEINE_RENDERMODE_PERSPECTIVE,
CAFFEINE_RENDERMODE_ORTHO

If I select the orthographic mode, OpenGL uses a "virtual" resolution of 640x480 so that I can display images (for HUDs, fonts, etc.) without stretching them unnecessarily.

I''m not sure if that''s what you''re asking, but I''ll gladly post code if you want it.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

that''s pretty much it, and i wouldn''t mind some code! :D

---
umm... bah?
Awright. It''s a tad messy, but it''s rather easy to figure out.


  void CEngine::SetRenderMode(RenderMode NewMode){	static RenderMode CurMode;	if(NewMode != CurMode)	{		CurMode = NewMode;		switch(CurMode)		{			case CAFFEINE_PERSPECTIVE:					glMatrixMode(GL_PROJECTION);				glLoadIdentity();				glFrustum (Left, Right, Bottom, Top, Near, Far);				glMatrixMode(GL_MODELVIEW);				break;			case CAFFEINE_ORTHO:				glMatrixMode(GL_PROJECTION);				glLoadIdentity();				glOrtho(0,640,480,0,-1,1);				glMatrixMode(GL_MODELVIEW);				break;			default: break;		}	}}  


That was the SetRenderMode function. You''ll notice the values for the dimensions of the view frustrum. Here''s the SizeGL function, which sets their values (note that this code can be greatly simplified with the gluPerspective function. I simply choose to not use the GLU library.)


  ErrorCode CEngine::SizeOpenGL(){	RECT WindowRect;	GetClientRect(WindowHandle, &WindowRect);	glViewport(0, 0, WindowRect.right, WindowRect.bottom);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();		Far = 2500.0f;	Near = 0.2f;	Aspect = WindowRect.right/(float)WindowRect.bottom;	Top = tanf(0.3927f)*Near; //0.392699081698625 is the view angle in radians	Bottom = -Top;	Left = Aspect*Bottom;	Right = Aspect*Top;	glFrustum (Left, Right, Bottom, Top, Near, Far);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	return CAFFEINE_OK;}  


And that should get you well on your way. Feel free to ask or email if you have any questions.

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

[twitter]warrenm[/twitter]

This topic is closed to new replies.

Advertisement