From: Dan P. <ba...@al...> - 2001-11-29 02:28:18
|
On Nov 29, Joachim Jaeckel wrote: > I started to create a small gl-program, which shows a cube, zooming from the > distance to the front, starts to rotate to show me all his 4 textured faces. > The zooming works fine, untill to the point, where the cube should start to > rotate. At this point, my code to do the rotating seems to have no effect. > Additionally the texturing seems to be wrong... Nearly the same program works > fine (without texturing) under Mesa on FreeBSD. > > Maybe you can have a look in my attached source and point me to my mistakes? Yeah. I think I see why it's not working, and this might point to an important difference between KGL and the spec. Someone more versed in GL will have to say for sure... comments below. > #include <kos.h> > #include <GL/gl.h> > #include <GL/glu.h> > > /* the textures for the intro-cube */ > GLuint texture; > > int zoom = -100; /* the counter for zooming the cube */ > GLfloat yrot = 0.0f; > > void cube() { > > glTranslatef(0.0f, 0.0f, (zoom * 1.0f)); > > glBegin(GL_QUADS); > /* First face */ > glBindTexture(GL_TEXTURE_2D, texture/*1*/); > glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.0f); > glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, 0.0f); > glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, 0.0f); > glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.0f); > > /* Second face */ > glBindTexture(GL_TEXTURE_2D, texture/*2*/); > glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f, -0.5f, 0.0f); > glTexCoord2f(1.0f, 0.0f); glVertex3f(0.5f, -0.5f, 1.0f); > glTexCoord2f(1.0f, 1.0f); glVertex3f(0.5f, 0.5f, 1.0f); > glTexCoord2f(0.0f, 1.0f); glVertex3f(0.5f, 0.5f, 0.0f); > > /* Third face */ > glBindTexture(GL_TEXTURE_2D, texture/*3*/); > glTexCoord2f(0.0f, 0.0f); glVertex3f(0.5f, -0.5f, 1.0f); > glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 1.0f); > glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 1.0f); > glTexCoord2f(0.0f, 1.0f); glVertex3f(0.5f, 0.5f, 1.0f); > > /* Fourth face */ > glBindTexture(GL_TEXTURE_2D, texture/*4*/); > glTexCoord2f(0.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 1.0f); > glTexCoord2f(1.0f, 0.0f); glVertex3f(-0.5f, -0.5f, 0.0f); > glTexCoord2f(1.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 0.0f); > glTexCoord2f(0.0f, 1.0f); glVertex3f(-0.5f, 0.5f, 1.0f); > glEnd(); > > glTranslatef(0.0f, 0.0f, 0.5f); > if (zoom >= -3) > glRotatef(yrot-=0.01f, 0.0f, 1.0f, 0.0f); > > glTranslatef(0.0f, 0.0f, (zoom * -1.0f - 0.5f)); Ok, here's why your zooms and translates don't work: they are being done after the vertex submission. I think even in the regular GL this would happen because the transformations only happen to vertices after the glTranslatef(), glRotatef(), etc. > if (zoom < -3) zoom++; > } > > /* Load a texture using pcx_load_texture and glKosTex2D */ > void loadtxr(const char *fn, GLuint *txr) { > uint32 txaddr; > int w, h; > if (pcx_load_texture(fn, 1, 0, &txaddr, &w, &h) < 0) { > printf("can't load %s\n", fn); > return; > } > > glGenTextures(1, txr); > glBindTexture(GL_TEXTURE_2D, *txr); > glKosTex2D(GL_RGB565_TWID, (GLsizei) w, (GLsizei) h, txaddr); > } > > extern uint8 romdisk[]; > int main(int argc, char **argv) { > cont_cond_t cond; > uint8 c; > int i; > > /* Initialize KOS */ > kos_init_all(THD_ENABLE | IRQ_ENABLE | TA_ENABLE, romdisk); > > printf("gltest beginning\n"); > > /* Get basic stuff initialized */ > glKosInit(); > glMatrixMode(GL_PROJECTION); > glLoadIdentity(); > gluPerspective(30.0f, 640.0f / 480.0f, 0.1f, 100.0f); > glMatrixMode(GL_MODELVIEW); > glEnable(GL_TEXTURE_2D); > > /* Load the textures */ > //loadtxr("/rd/title.pcx", &texture1); > //loadtxr("/rd/created.pcx", &texture2); > //loadtxr("/rd/kalist.pcx", &texture3); > loadtxr("/rd/copyr.pcx", &texture); > > c = maple_first_controller(); > while(1) { > for (i = 0; i < 1000; i++){ > } > > /* Check key status */ > if (cont_get_cond(c, &cond) < 0) { > printf("Error reading controller\n"); > break; > } > if (!(cond.buttons & CONT_START)) > break; > if (!(cond.buttons & CONT_DPAD_UP)) > break; > if (!(cond.buttons & CONT_DPAD_DOWN)) > break; > if (!(cond.buttons & CONT_DPAD_LEFT)) > break; > if (!(cond.buttons & CONT_DPAD_RIGHT)) > break; > if (!(cond.buttons & CONT_A)) > break; > > /* Begin frame */ > glKosBeginFrame(); > > /* Handle the cube */ > glLoadIdentity(); > cube(); > > /* Finish the frame */ > glKosFinishFrame(); > } > > return 0; > } The rest looks ok to me. On the textures looking wrong, did you mean that they actually look incorrect, or that they are rotated wrong? I'm not sure that I matched the texture system of GL so the rotation problems might happen. If it's the other, then the first thing is to make sure that it's a power of 2 in size. If it's not, then there might be a bug (send me the PCX file and I'll take a look). As a side point, does anyone know if it's valid in GL to do ortho mapped graphics by simply doing a glLoadIdentity() on the PROJECTION matrix? I'm doing that in the project I'm working on now to do 2D graphics without having to use TA primitives, but I don't know if it's portable or not. |