开发者

Replace these OpenGL functions with OpenGL ES?

开发者 https://www.devze.com 2023-02-03 09:45 出处:网络
I search for a possibility to migrate my PC Open开发者_如何学CGL application and an iPhone App into one XCode project (for convenience). So if I make chances to these source files I want to apply this

I search for a possibility to migrate my PC Open开发者_如何学CGL application and an iPhone App into one XCode project (for convenience). So if I make chances to these source files I want to apply this for both plattforms and want to be able to compile for both plattforms from one project. How could I accomplish this? Is there a way to do so in XCode 4 or 3.25? Any help would be highly appreciated

edit: Okay, I went so far - All in all, it seems to work with XCode 4. My only problems are these openGL/Glut functions, that aren't working on iPhone:

glPushAttrib( GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT );
glPopAttrib();
glutGet(GLUT_ELAPSED_TIME);
glutSwapBuffers();

Any ideas how to fix these issues?


PushAttrib/PopAttrib you'll need to replace yourself with code which manually tracks those states, or you could rewrite your code in such a way that anything which relies on those states, sets them itself.

glutGet(GLUT_ELAPSED_TIME) could be replaced by mach_absolute_time (not particularly easy, but the right thing to use) or [NSDate timeIntervalSinceReferenceDate] (easy, but potentially problematic since it's not guaranteed to be monotonically increasing, or to increase at 1.0 per second)

glutSwapBuffers will be replaced by -presentRenderbuffer: on your EAGLContext (but it sounds like you're already doing this; if you weren't, you wouldn't be able to see anything).


You could use dgles to wrap your desktop OpenGL implementation and provide a OpenGL ES 1.x interface.


I found this documentation online in regards to the OpenGL ES 1.0 specification

There are several reasons why one type or another of internal state needs to be queried by an ap- plication.The application may need to dynamically discover implementation limits (pixel component sizes, texture dimensions, etc.), or the application might be part of a layered library and it may need to save and restore any state that it disturbs as part of its rendering.PushAttrib andPopAttrib can be used to perform this but they are expensive to implement and use and therefore not supported.Gen- erally speaking state queries are discouraged as they are often detrimental to performance.Rather than trying to partition different types of dynamic state that can be queried, tops of matrix stacks for example, no dynamic state queries are supported and applications must shadow state changes rather than querying the pipeline.This makes things difficult for layered libraries, but there hasn’t been enough justification to retain dynamic state queries or attribute pushing and popping.

That and this other link here seems to indicate that you'll need to keep track of those bits yourself. No help for you there.

glut just calls the system code, yeah? (wglSwapBuffers, glxSwapBuffers)

Try this here eglSwapBuffers and maybe this book out

Sorry I don't have a more concrete answer for you.


very annoyed by this lack seemingly simple functionality of pushing attribs, but you can use glGetto get the state of something before you set the param , like this which worked for me:

Boolean tmpB;
int tmpSrc,tmpDst;

glGetBooleanv(GL_BLEND,&tmpB);
glGetIntegerv(GL_BLEND_SRC_ALPHA,&tmpSrc);
glGetIntegerv(GL_BLEND_DST_ALPHA,&tmpDst);    


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//draw rectangle
CGSize winSize=[[CCDirector sharedDirector] winSize];
CGPoint vertices[] = { ccp(0,0), ccp(winSize.width,0), ccp(winSize.width,20), ccp(0,20) };
glColor4ub(255, 0, 255, 55);
ccFillPoly( vertices, 4, YES);


if(!tmpB)
    glDisable(GL_BLEND);

glBlendFunc(tmpSrc, tmpDst);
0

精彩评论

暂无评论...
验证码 换一张
取 消