#140083 - Jesse - Thu Sep 13, 2007 1:03 pm
I've been trying to use the 3d-hardware to replace my sprites, since I want access to the nice alpha-formats. The problem is that I can't seem to control in what order my polygons are rendered in. I've been trying to find topics about this and found some that discuss turning off the automatic y-sorting, but it doesn't seem to make a difference for me.
The code below is a good example where the order that the two polygons is rendered on the screen only depends on the y-position, even though I use GL_TRANS_MANUALSORT. On a side-note, it's the other way around when running in DeSmuME where it always render in the call-order.
Does anyone have any idea of how to solve this?
The code below is a good example where the order that the two polygons is rendered on the screen only depends on the y-position, even though I use GL_TRANS_MANUALSORT. On a side-note, it's the other way around when running in DeSmuME where it always render in the call-order.
Does anyone have any idea of how to solve this?
Code: |
#include <nds.h>
#include <stdlib.h> void DrawQuad(int _PosX, int _PosY, int _Color, int _TextureID) { int Size = 64; int x0 = (1 << 11) / 256 + (_PosX - 128) * (1 << 12) / 128; int x1 = (1 << 11) / 256 + (_PosX + Size - 128) * (1 << 12) / 128; int y0 = (1 << 11) / 192 + (96 - _PosY) * (1 << 12) / 96; int y1 = (1 << 11) / 192 + (96 - _PosY - Size) * (1 << 12) / 96; glBindTexture(0, _TextureID); glBegin(GL_QUAD); glNormal(NORMAL_PACK(0,inttov10(-1),0)); glColor3b(_Color >> 16, _Color >> 8, _Color); glTexCoord2t16(inttot16(64), 0); glVertex3v16(x1, y0, 0); glTexCoord2t16(0, 0); glVertex3v16(x0, y0, 0); glTexCoord2t16(0, inttot16(64)); glVertex3v16(x0, y1, 0); glTexCoord2t16(inttot16(64), inttot16(64)); glVertex3v16(x1, y1, 0); glEnd(); } int main() { powerON(POWER_ALL); irqInit(); irqEnable(IRQ_VBLANK); lcdMainOnBottom(); videoSetMode(MODE_0_3D); vramSetMainBanks(VRAM_A_TEXTURE_SLOT0, VRAM_B_LCD, VRAM_C_LCD, VRAM_D_LCD); glInit(); glEnable(GL_TEXTURE_2D); glViewPort(0,0,255,191); short *pBuf = new short[64 * 64]; for(int i = 0; i < 64 * 64; i++) { int x = (i & 63); int y = (i >> 6); if(x == 0 || x == 63 || y == 0 || y == 63) pBuf[i] = 0x801f; else if((x & 1) || (y & 1)) pBuf[i] = 0xffff; else pBuf[i] = 0x8000; } int textureID; glGenTextures(1, &textureID); glBindTexture(0, textureID); glTexImage2D(0, 0, GL_RGBA, TEXTURE_SIZE_64, TEXTURE_SIZE_64, 0, TEXGEN_TEXCOORD, (u8*)pBuf); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMaterialf(GL_AMBIENT, RGB15(16,16,16)); glMaterialf(GL_DIFFUSE, RGB15(16,16,16)); glMaterialf(GL_SPECULAR, BIT(15) | RGB15(8,8,8)); glMaterialf(GL_EMISSION, RGB15(16,16,16)); glMaterialShinyness(); glPolyFmt(POLY_ALPHA(31) | POLY_CULL_BACK); int nFrame = 0; while(1) { nFrame = (nFrame + 1) & 127; DrawQuad(nFrame, nFrame, 0xffffffff, textureID); DrawQuad(128 - nFrame, 128 - nFrame, 0xffff00ff, textureID); glFlush(GL_TRANS_MANUALSORT); swiWaitForVBlank(); } return 0; } |