#54593 - Extreme Coder - Tue Sep 20, 2005 6:40 pm
Hi there.
I needed a glortho function, but since there isnt one, i took the one Dovoto at irc gave me:
And I use it in my program like this:
But i get black screens. I tried changing glOrtho(0,256,192,0,0,1); to glOrtho(0,256,192,0,-1,1);, yet same results. And i changed glVertex's z coordinate aswell, no luck.
Does anyone know whats wrong with this code?
Or if you think the problem is with the function, then whats wrong when i use glfrustum with the same arguments and get the same results?
Oh, and please, add a working Glortho function in the next libnds:D
Thanks so much in advance.
Last edited by Extreme Coder on Wed Sep 21, 2005 1:42 pm; edited 1 time in total
I needed a glortho function, but since there isnt one, i took the one Dovoto at irc gave me:
Code: |
//--------------------------------------------------------------------------------- void glOrtho3f32(f32 left, f32 right, f32 bottom, f32 top, f32 near, f32 far) { //--------------------------------------------------------------------------------- glMatrixMode(GL_PROJECTION); MATRIX_LOAD4x4 = divf32(intof32(2), right - left); MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = divf32(right + left, right - left); MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = divf32(intof32(2), top - bottom); MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = divf32(top + bottom, top - bottom); MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = -divf32(intof32(-2), far - near); MATRIX_LOAD4x4 = divf32(far + near, far - near); MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = 0; MATRIX_LOAD4x4 = floatof32(-1.0F); glStoreMatrix(0); } |
And I use it in my program like this:
Code: |
/**************************************** * NDS NeHe Lesson 06 * * Author: Dovoto * ****************************************/ // include your ndslib #include <nds.h> #include <malloc.h> //needed to load pcx files #include <nds/arm9/image.h> #include "drunkenlogo_pcx.h" //Glortho3f32 function in the same post above //--------------------------------------------------------------------------------- void glOrtho(float left, float right, float bottom, float top, float near, float far) { //--------------------------------------------------------------------------------- glOrtho3f32(floatof32(left), floatof32(right), floatof32(bottom), floatof32(top),floatof32(near), floatof32(far)); } int DrawGLScene(); int texture[1]; // Storage For One Texture ( NEW ) void image8to16(sImage* img) { int i; u16* temp = (u16*)malloc(img->height*img->width*2); for(i = 0; i < img->height * img->width; i++) temp[i] = img->palette[img->data8[i]] | (1<<15); img->data16 = temp; } int LoadGLTextures() // Load PCX files And Convert To Textures { sImage pcx; //////////////(NEW) and different from nehe. //load our texture loadPCX((u8*)drunkenlogo_pcx, &pcx); image8to16(&pcx); glGenTextures(1, &texture[0]); glBindTexture(0, texture[0]); glTexImage2D(0, 0, GL_RGB, TEXTURE_SIZE_128 , TEXTURE_SIZE_128, 0, TEXGEN_TEXCOORD, pcx.data8); return TRUE; } int main() { // Turn on everything powerON(POWER_ALL); irqInit(); irqEnable(IRQ_VBLANK); // Setup the Main screen for 3D videoSetMode(MODE_0_3D); vramSetBankA(VRAM_A_TEXTURE); //NEW must set up some memory for textures // Set our viewport to be the same size as the screen glViewPort(0,0,255,191); // Specify the Clear Color and Depth glClearColor(0,0,0); glClearDepth(0x7FFF); LoadGLTextures(); while (1) { scanKeys(); // Reset the screen and setup the view glReset(); //gluPerspective(i, 256.0/192.0,0.1, 100); glOrtho(0,256,192,0,0,1); glColor3f(1,1,1); glPushMatrix(); glMatrixMode(GL_TEXTURE); glIdentity(); glMatrixMode(GL_MODELVIEW); //ds specific, several attributes can be set here glPolyFmt(POLY_ALPHA(31) | POLY_CULL_NONE); // Set the current matrix to be the model matrix glMatrixMode(GL_MODELVIEW); //Push our original Matrix onto the stack (save state) glPushMatrix(); DrawGLScene(); // Pop our Matrix from the stack (restore state) glPopMatrix(1); // flush to screen glFlush(); } return 0; } int DrawGLScene() // Here's Where We Do All The Drawing { glLoadIdentity(); // Reset The View glTranslatef(0,0,0); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); // Front Face glTexCoord2f(0, 0); glVertex3f( 0, 0, 0.0); glTexCoord2f(1, 0); glVertex3f(10, 0, 0.0); glTexCoord2f(1, 1); glVertex3f(10, 10, 0.0); glTexCoord2f(0, 1); glVertex3f( 0, 10, 0.0); glEnd(); return TRUE; } |
But i get black screens. I tried changing glOrtho(0,256,192,0,0,1); to glOrtho(0,256,192,0,-1,1);, yet same results. And i changed glVertex's z coordinate aswell, no luck.
Does anyone know whats wrong with this code?
Or if you think the problem is with the function, then whats wrong when i use glfrustum with the same arguments and get the same results?
Oh, and please, add a working Glortho function in the next libnds:D
Thanks so much in advance.
Last edited by Extreme Coder on Wed Sep 21, 2005 1:42 pm; edited 1 time in total