09-24-2002, 08:31 PM
OK, I have two questions about the way OpenGL handles textures. The first deals with switching between full-screen and windowed modes. If I start my app full-screen (like Quake for instance) it runs fine and textures perfectly. However, say I want to go windowed, I hit F12 which switches to windowed mode. When I hit F12, it destroys the OpenGL window, then re-creates it windowed, and then calls "InitGL", my function for setting up culling, rendering, etc etc. When I go windowed however, I see the frame created, then it just exits. I have a feeling it is due to the textures because in the early days of my engine, when I went windowed I would have plain white walls, but going full again made it normal. Am I supposed to somehow clear my texture memory when swapping modes?
This brings me to my next question. Say I load five textures on map A. I then reach the exit and go to map B, which loads ten textures. Is there some way I have to wipe out my five textures first, then use the next set, or am I just supposed to bind to a texture slot I already used and over-write it? Thanks for the help.
Well, I don't know if i've understood your problem correctly, and maybe i'll just tell you what you already know. This is what I think you're getting wrong:
Textures are defined inside a gl context. Whenever you swap modes in your app the context gets destroyed (and any textures within). By the time you create another one your textures are invalid.
In other words, try changing your texture loading code to the InitGL function.
On your second question, you can always keep all your textures loaded. The problem is that you'll probably end up filling all your video memory and performance will suffer. If there is a group of textures that you really don't need, you should use glDeleteTextures *before* loading the next group.
There is also a priority mechanism you can use to tell the driver which textures are important and kept in video mem (as your card permits), but I haven't played with that so I can only tell to look up glPrioritizeTextures in msdn/red book.
09-25-2002, 09:21 AM
OK, glDel* was what I was looking for to clear the memory. As for my first question, the way my functions work is this:
Player hits F12
InitGL() is called, which first calls LoadTextures()
Now InitGL() sets up culling and such
Now why isn't it working? I can post some source if it will help.
For the 1st problem (that I seemed to forget :4), I'm guessing you're having sync problems with your messages.
Creating/destroying windows in WM_CHAR/WM_KEY messages isn't a generally very good thing.
Code would help if you strip it down to the bare essentials and provide the full code so that me (and others) can have a try at home..
09-25-2002, 08:25 PM
OK, here's a basic example.
char TexBuffer, Type;
short int Width, Height;
GLubyte ResA, ResB, ResC, ResD, ResE;
for(short int Loop = 0; Loop < Area.numTextures; Loop++)
sprintf(TexBuffer, "Textures\\%s", Area.TexList[Loop]);
if((TexFile = fopen(TexBuffer, "rb")) == NULL)
fread(&Width, sizeof(short int), 1, TexFile);
fread(&Height, sizeof(short int), 1, TexFile);
Type = 0;
if(Width == 32 && Height == 32)
fread(&ResA, sizeof(ResA), 1, TexFile);
Type = 1;
if(Width == 64 && Height == 64)
fread(&ResB, sizeof(ResB), 1, TexFile);
Type = 2;
if(Width == 96 && Height == 96)
fread(&ResC, sizeof(ResC), 1, TexFile);
Type = 3;
if(Width == 128 && Height == 128)
fread(&ResD, sizeof(ResD), 1, TexFile);
Type = 4;
if(Width == 64 && Height == 96)
fread(&ResE, sizeof(ResE), 1, TexFile);
Type = 5;
if(Type == 0)
MessageBox(NULL, "Bad texture!", "Debug", MB_OK);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if(Type == 1)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, ResA);
if(Type == 2)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, ResB);
if(Type == 3)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, ResC);
if(Type == 4)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, ResD);
if(Type == 5)
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, ResE);
glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
LRESULT CALLBACK MainCalls(...)
keys[cbwp] = true;
keys[cbwp] = false;
int WINAPI WinMain(...)
bool done = false;
//Define and register window class
//Load custom settings
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
if(msg.message == WM_QUIT)
done = true;
//Handles calling screen drawing and such
keys[VK_F12] = false;
That should be all you need. In my "CreateGLWindow" function I have a check on every command, including pixelformat settings and the actual CreateWindowEx() command. The whole function seems to work, but the app just auto-exits for some reason.
I'm sorry... I tryied but I'm not too good at reading other people's code http://www.opengl.org/discussion_boards/ubb/biggrin.gif.
It would be better to post (give a link, etc) to complete/compilable code. Then some debugging could make a difference.
You don't have to post your entire app! Just the important stuff. Maybe you find your bug in the process http://www.opengl.org/discussion_boards/ubb/smile.gif
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.