Search Results

Search found 27 results on 2 pages for 'ortho'.

Page 2/2 | < Previous Page | 1 2 

  • OpenGL ES functions not accepting values originating outside of it's view

    - by Josh Elsasser
    I've been unable to figure this out on my own. I currently have an Open GLES setup where a view controller both updates a game world (with a dt), fetches the data I need to render, passes it off to an EAGLView through two structures (built of Apple's ES1Renderer), and draws the scene. Whenever a value originates outside of the Open GL view, it can't be used to either translate objects using glTranslatef, or set up the scene using glOrthof. If I assign a new value to something, it will work - even if it is the exact same number. The two structures I have each contain a variety of floating-point numbers and booleans, along with two arrays. I can log the values from within my renderer - they make it there - but I receive errors from OpenGL if I try to do anything with them. No crashes result, but the glOrthof call doesn't work if I don't set the camera values to anything different. Code used to set up scene: [EAGLContext setCurrentContext:context]; glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer); //clears the color buffer bit glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); //sets up the scene w/ ortho projection glViewport(0, 0, 320, 480); glLoadIdentity(); glOrthof(320, 0, dynamicData.cam_x2, dynamicData.cam_x1, 1.0, -1.0); glClearColor(1.0, 1.0, 1.0, 1.0); /*error checking code here*/ "dynamicData" (which is replaced every frame) is created within my game simulation. From within my controller, I call a method (w/in my simulation) that returns it, and pass the result on to the EAGLView, which passes it on to the renderer. I haven't been able to come up with a better solution for this - suggestions in this regard would be greatly appreciated as well. Also, this function doesn't work as well (values originate in the same place): glTranslatef(dynamicData.ship_x, dynamicData.ship_y, 0.0); Thanks in advance. Additional Definitions: Structure (declared in a separate header): typedef struct { float ship_x, ship_y; float cam_x1, cam_x2; } dynamicRenderData; Render data getter (and builder) (every frame) - (dynamicData)getDynRenderData { //d_rd is an ivar, zeroed on initialization d_rd.ship_x = mainShip.position.x; d_rd.ship_y = mainShip.position.y; d_rd.cam_x1 = d_rd.ship_x - 30.0f; d_rd.cam_x2 = d_rd.cam_x1 + 480.0f; return d_rd; } Zeroed at start. (d_rd.ship_x = 0;, etc…) Setting up the view. Prototype (GLView): - (void)draw: (dynamicRenderData)dynamicData Prototype (Renderer): - (void)drawView: (dynamicRenderData)dynamicData How it's called w/in the controller: //controller [glview draw: [world getDynRenderData]]; //glview (within draw) [renderer drawView: dynamicData];

    Read the article

  • SDL+OpenGL app: blank screen

    - by Lococo
    I spent the last three days trying to create a small app using SDL + OpenGL. The app itself runs fine -- except it never outputs any graphics; just a black screen. I've condensed it down to a minimal C file, and I'm hoping someone can give me some guidance. I'm running out of ideas. I'm using Windows Vista, MinGW & MSYS. Thanks in advance for any advice! #include <SDL/SDL.h> #include <SDL_opengl.h> size_t sx=600, sy=600, bpp=32; void render(void) { glEnable(GL_DEPTH_TEST); // enable depth testing glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // clear to black glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color/depth buffer glLoadIdentity(); // reset modelview matrix glColor3b(255, 0, 0); // red glLineWidth(3.0); // line width=3 glRecti(10, 10, sx-10, sy-10); // draw rectangle glFlush(); SDL_GL_SwapBuffers(); } int input(void) { SDL_Event event; while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT || (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)) return 0; return 1; } int main(int argc, char *argv[]) { SDL_Surface* surf; if (SDL_Init(SDL_INIT_EVERYTHING) != 0) return 0; if (!(surf = SDL_SetVideoMode(sx, sy, bpp, SDL_HWSURFACE|SDL_DOUBLEBUF))) return 0; glViewport(0, 0, sx, sy); // reset the viewport to new dimensions glMatrixMode(GL_PROJECTION); // set projection matrix to be current glLoadIdentity(); // reset projection matrix glOrtho(0, sx, sy, 0, -1.0, 1.0); // create ortho view glMatrixMode(GL_MODELVIEW); // set modelview matrix glLoadIdentity(); // reset modelview matrix for (;;) { if (!input()) break; render(); SDL_Delay(10); } SDL_FreeSurface(surf); SDL_Quit(); exit(0); } UPDATE: I have a version that works, but it changes orthographic to perspective. I'm not sure why this works and the other doesn't, but for future reference, here's a version that works: #include <SDL/SDL.h> #include <SDL_opengl.h> size_t sx=600, sy=600, bpp=32; void render(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // set location in front of camera glTranslated(0, 0, -10); glBegin(GL_QUADS); // draw a square glColor3d(1, 0, 0); glVertex3d(-2, 2, 0); glVertex3d( 2, 2, 0); glVertex3d( 2, -2, 0); glVertex3d(-2, -2, 0); glEnd(); glFlush(); SDL_GL_SwapBuffers(); } int input(void) { SDL_Event event; while (SDL_PollEvent(&event)) if (event.type == SDL_QUIT || (event.type == SDL_KEYUP && event.key.keysym.sym == SDLK_ESCAPE)) return 0; return 1; } int main(int argc, char *argv[]) { SDL_Surface *surf; if (SDL_Init(SDL_INIT_EVERYTHING) != 0) return 0; if (!(surf = SDL_SetVideoMode(sx, sy, bpp, SDL_OPENGL))) return 0; glViewport(0, 0, sx, sy); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0, (float)sx / (float)sy, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glClearColor(0, 0, 0, 1); glClearDepth(1.0); glEnable(GL_DEPTH_TEST); for (;;) { if (!input()) break; render(); SDL_Delay(10); } SDL_FreeSurface(surf); SDL_Quit(); return 0; }

    Read the article

< Previous Page | 1 2