Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problems in windowed mode (MacOS 8 or 9)



Hello !

We are currently trying to implement OpenGL in our online product but we
have to deal with a few problems (Tested on numerous systems, including
MacOS 9.04 & OpenGL 1.2.1)

First we setup the OpenGL environment using the AGL API. It might be
important to note that we are in "windowed" mode and not in fullscreen. The
init code is the following:

SInt32 attrib[] = {AGL_RGBA,AGL_DOUBLEBUFFER,AGL_DEPTH_SIZE,16,AGL_NONE};

if (!mainglrc)
{
mainglrc = CreateMainContext();
}

fmt = aglChoosePixelFormat(NULL,0,attrib);
hglrc = aglCreateContext(fmt,mainglrc);
aglDestroyPixelFormat(fmt);

aglSetCurrentContext(hglrc);
aglSetDrawable(hglrc,window);

Next we render the polygons with the following code:

int DoM3DPolys (camera c, polw poly)
{
int hRes;
int CurrMat = 0;
int CurrClamp = 0;
bool dolight = false;
GLint wrap;
float u, v;
int n;
pointw p = NULL;
float r, g, b, a;
float x, y, z;
short* pal;

while(poly)
{
inum = vnum = 0;
CurrMat = poly->handmat;
CurrClamp = poly->clamp;

//----------- Texturing -----------//
if(poly->type & 1)
{
glEnable(GL_TEXTURE_2D);
//Set the right texture
GLTexture *text = (GLTexture*) poly->bitmap;

if (text->list == -1)
{
glGenTextures(1,(unsigned long*)&text->list);
glBindTexture(GL_TEXTURE_2D,text->list);


glTexImage2D(GL_TEXTURE_2D,0,GL_RGB5_A1,text->width,text->height,0,GL_RGBA,G
L_UNSIGNED_BYTE,text->image);
//glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
free(text->image);
text->image=NULL;
}
glBindTexture(GL_TEXTURE_2D,text->list);

if (poly->clamp) wrap=GL_CLAMP;
else wrap=GL_REPEAT;

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
}
else glDisable(GL_TEXTURE_2D);
//---------------------------------//

//----------- Blending ------------//
if(poly->type & 2) glEnable(GL_BLEND);
else glDisable(GL_BLEND);
//---------------------------------//


//----------- Alpha test ----------//
if(poly->type & 4)
{
glEnable(GL_BLEND);
if (poly->color16 != COLORTRANSP)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL ,0);
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_NOTEQUAL, 0);
}
}
else
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glAlphaFunc(GL_ALWAYS,0);
glDisable(GL_ALPHA_TEST);
}
//---------------------------------//


//----------- Texturing -----------//
while( (poly->handmat == CurrMat) && (poly->clamp == CurrClamp) )
{
p = &poly->p;

glBegin(GL_TRIANGLE_FAN);
for (n = poly->np-1; n >= 0; n--)
{
if (poly->type & 1)
{
float l = p->light;
if (l >= 31)
{
r = b=g=1;
dolight=true;
}
else
{
r=g=b=l/32.0;
}
}
else
{
pal=&pal16[96*p->light];
r=pal[64+(poly->color16>>10)&31]/31.0;
g=pal[32+(poly->color16>>5)&31]/31.0;;
b=pal[(poly->color16)&31]/31.0;
}

a=(poly->type&2)?1.0-(poly->coef/255.0):1.0;

glColor4f(r,g,b,a);

u=p->u/255.0f;
v=p->v/255.0f;

glTexCoord2f(u,v);
x=p->p.x;
y=p->p.y;
z=-p->p.z;

glVertex3f(x,y,z);
p++;
}
glEnd();

if (dolight)
{
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT |
GL_ENABLE_BIT );
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glDepthMask(0);
glDepthFunc(GL_LEQUAL);

glBegin(GL_TRIANGLE_FAN);
p=&poly->p;
for (n=poly->np-1;n>=0;n--)
{
a=0;
if (p->light>=31)
{
a = (p->light-31.0)/31.0;
}

glColor4f(1,1,1,a);

glVertex3f(p->p.x,p->p.y,-p->p.z);
p++;
}
glEnd();
glPopAttrib();

dolight=false;
}

poly=poly->nxt;
if(!poly)break;
}
}
return 0;
}

The problem we face is that even when only 100 polygons are rendered in the
buffer, it is extremely slow.
For example, on a G3 300Mhz with an ATI Rage Pro 6Mb, it takes something
like 40 milliseconds to render 100 polygons. In the best case, we can only
render 25 frames per second. It is possible that the "windowed" mode tends
to slow things down? Or is there a problem with our OpenGL implementation?

The frame is flipped using:

aglSwapBuffers(hglrc);

The second problem we face is when we try to resize the OpenGL. The current
method used to resize the OpenGL buffer is the following:

aglEnable(hglrc,AGL_BUFFER_RECT);
aglSetInteger(hglrc,AGL_BUFFER_RECT,param);

The problem is, sometimes it works, sometimes it crashes, or the textures
disappear from the buffer. What the right method to properly resize an
OpenGL window?


Thanks a lot!




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.