the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 393 lines 8.1 kB view raw
1#include "stdafx.h" 2#include "..\Minecraft.World\FloatBuffer.h" 3#include "..\Minecraft.World\IntBuffer.h" 4#include "..\Minecraft.World\ByteBuffer.h" 5 6void glViewport(int x, int y, int w, int h) 7{ 8 // We don't really need anything here because minecraft doesn't current do anything other than the default viewport 9} 10 11void glTranslatef(float x,float y,float z) 12{ 13 RenderManager.MatrixTranslate(x,y,z); 14} 15 16void glRotatef(float angle, float x, float y, float z) 17{ 18 RenderManager.MatrixRotate(angle*(PI/180.0f),x,y,z); 19} 20 21void glPopMatrix() 22{ 23 RenderManager.MatrixPop(); 24} 25 26void glPushMatrix() 27{ 28 RenderManager.MatrixPush(); 29} 30 31void glScalef(float x, float y, float z) 32{ 33 RenderManager.MatrixScale(x,y,z); 34} 35 36void glMultMatrixf(float *m) 37{ 38 RenderManager.MatrixMult(m); 39} 40 41void glMatrixMode(int type) 42{ 43 RenderManager.MatrixMode(type); 44} 45 46void glLoadIdentity() 47{ 48 RenderManager.MatrixSetIdentity(); 49} 50 51extern int g_iScreenWidth; 52extern int g_iScreenHeight; 53 54void gluPerspective(float fovy, float aspect, float zNear, float zFar) 55{ 56 float dynamicAspect = (float)g_iScreenWidth / (float)g_iScreenHeight; 57 RenderManager.MatrixPerspective(fovy, dynamicAspect, zNear, zFar); 58} 59 60void glOrtho(float left,float right,float bottom,float top,float zNear,float zFar) 61{ 62 RenderManager.MatrixOrthogonal(left,right,bottom,top,zNear,zFar); 63} 64 65void glScaled(double x,double y,double z) 66{ 67 RenderManager.MatrixScale((float)x,(float)y,(float)z); 68} 69 70void glGetFloat(int type, FloatBuffer *buff) 71{ 72 memcpy(buff->_getDataPointer(),RenderManager.MatrixGet(type),64); 73} 74 75void glDeleteLists(int first,int count) 76{ 77 RenderManager.CBuffDelete(first,count); 78} 79 80int glGenLists(int count) 81{ 82 return RenderManager.CBuffCreate(count); 83} 84 85void glNewList(int index, int mode) 86{ 87 RenderManager.CBuffStart(index); 88} 89 90void glEndList(int vertexCount) 91{ 92#ifdef _XBOX 93 RenderManager.CBuffEnd(vertexCount); 94#else 95 RenderManager.CBuffEnd(); 96#endif 97} 98 99void glCallList(int index) 100{ 101 RenderManager.CBuffCall(index); 102} 103 104void glCallLists(IntBuffer *ib) 105{ 106 for(unsigned int i = 0; i < ib->limit(); i++) 107 { 108 RenderManager.CBuffCall(ib->get(i)); 109 } 110} 111 112void glClear(int flags) 113{ 114 RenderManager.Clear(flags); 115} 116 117void glClearColor(float r, float g, float b, float a) 118{ 119#ifdef _XBOX 120 int ir = (int)(r * 255.0f); if( ir < 0 ) ir = 0; if( ir > 255 ) ir = 255; 121 int ig = (int)(g * 255.0f); if( ig < 0 ) ig = 0; if( ig > 255 ) ig = 255; 122 int ib = (int)(b * 255.0f); if( ib < 0 ) ib = 0; if( ib > 255 ) ib = 255; 123 int ia = (int)(a * 255.0f); if( ia < 0 ) ia = 0; if( ia > 255 ) ia = 255; 124 125 RenderManager.SetClearColour(D3DCOLOR_RGBA(ir,ig,ib,ia)); 126#else 127 float rgba[4] = {r,g,b,a}; 128 RenderManager.SetClearColour(rgba); 129#endif 130} 131 132void Display::update() 133{ 134} 135 136void Display::swapBuffers() 137{ 138} 139 140void glBindTexture(int target,int texture) 141{ 142 RenderManager.TextureBind(texture); 143} 144 145void glTexImage2D(int target,int level,int internalformat,int width,int height,int border,int format,int type, ByteBuffer *data) 146{ 147 RenderManager.TextureData(width,height,data->getBuffer(),level); 148} 149 150void glDeleteTextures(IntBuffer *ib) 151{ 152 for(unsigned int i = 0; i < ib->limit(); i++) 153 { 154 RenderManager.TextureFree(ib->get(i)); 155 } 156} 157 158// 4J Stu - I'm pretty sure this is what it should do 159void glDeleteTextures(int id) 160{ 161 RenderManager.TextureFree(id); 162} 163 164void glGenTextures(IntBuffer *ib) 165{ 166 for(unsigned int i = 0; i < ib->limit(); i++) 167 { 168 ib->put(RenderManager.TextureCreate()); 169 } 170} 171 172// 4J Stu - I'm pretty sure this is what it should do 173int glGenTextures() 174{ 175 return RenderManager.TextureCreate(); 176} 177 178void glColor3f(float r, float g, float b) 179{ 180 RenderManager.StateSetColour(r,g,b,1.0f); 181} 182 183void glColor4f(float r, float g, float b, float a) 184{ 185 RenderManager.StateSetColour(r,g,b,a); 186} 187 188void glDisable(int state) 189{ 190 switch(state) 191 { 192 case GL_TEXTURE_2D: 193 RenderManager.TextureBind(-1); 194 break; 195 case GL_BLEND: 196 RenderManager.StateSetBlendEnable(false); 197 break; 198 case GL_CULL_FACE: 199 RenderManager.StateSetFaceCull(false); 200 break; 201 case GL_DEPTH_TEST: 202 RenderManager.StateSetDepthTestEnable(false); 203 break; 204 case GL_ALPHA_TEST: 205 RenderManager.StateSetAlphaTestEnable(false); 206 break; 207 case GL_FOG: 208 RenderManager.StateSetFogEnable(false); 209 break; 210 case GL_LIGHTING: 211 RenderManager.StateSetLightingEnable(false); 212 break; 213 case GL_LIGHT0: 214 RenderManager.StateSetLightEnable(0,false); 215 break; 216 case GL_LIGHT1: 217 RenderManager.StateSetLightEnable(1,false); 218 break; 219 } 220} 221 222void glEnable(int state) 223{ 224 switch(state) 225 { 226 case GL_BLEND: 227 RenderManager.StateSetBlendEnable(true); 228 break; 229 case GL_CULL_FACE: 230 RenderManager.StateSetFaceCull(true); 231 break; 232 case GL_DEPTH_TEST: 233 RenderManager.StateSetDepthTestEnable(true); 234 break; 235 case GL_ALPHA_TEST: 236 RenderManager.StateSetAlphaTestEnable(true); 237 break; 238 case GL_FOG: 239 RenderManager.StateSetFogEnable(true); 240 break; 241 case GL_LIGHTING: 242 RenderManager.StateSetLightingEnable(true); 243 break; 244 case GL_LIGHT0: 245 RenderManager.StateSetLightEnable(0,true); 246 break; 247 case GL_LIGHT1: 248 RenderManager.StateSetLightEnable(1,true); 249 break; 250 } 251} 252 253void glDepthMask(bool enable) 254{ 255 RenderManager.StateSetDepthMask(enable); 256} 257 258void glBlendFunc(int src, int dst) 259{ 260 RenderManager.StateSetBlendFunc(src,dst); 261} 262 263void glAlphaFunc(int func,float param) 264{ 265 RenderManager.StateSetAlphaFunc(func, param); 266} 267 268void glDepthFunc(int func) 269{ 270#ifdef _XBOX 271 RenderManager.StateSetDepthFunc(func); 272#else 273 RenderManager.StateSetDepthFunc(func); 274#endif 275} 276 277void glTexParameteri(int target, int param, int value) 278{ 279 RenderManager.TextureSetParam(param,value); 280} 281 282void glPolygonOffset(float factor, float units) 283{ 284#ifdef __PS3__ 285 RenderManager.StateSetDepthSlopeAndBias(factor, units); 286#else 287 // DirectX specifies these offsets in z buffer 0 to 1 sort of range, whereas opengl seems to be in a 0 -> depth buffer size sort of range. 288 // The slope factor is quite possibly different too. Magic factor for now anyway. 289 const float magicFactor = 65536.0f; 290 RenderManager.StateSetDepthSlopeAndBias(factor / magicFactor, units / magicFactor); 291#endif 292} 293 294void glFogi(int param, int value) 295{ 296 if( param == GL_FOG_MODE ) 297 { 298 RenderManager.StateSetFogMode(value); 299 } 300} 301 302void glFogf(int param, float value) 303{ 304 switch(param) 305 { 306 case GL_FOG_START: 307 RenderManager.StateSetFogNearDistance(value); 308 break; 309 case GL_FOG_END: 310 RenderManager.StateSetFogFarDistance(value); 311 break; 312 case GL_FOG_DENSITY: 313 RenderManager.StateSetFogDensity(value); 314 break; 315 } 316} 317 318void glFog(int param,FloatBuffer *values) 319{ 320 if( param == GL_FOG_COLOR ) 321 { 322 float *data = values->_getDataPointer(); 323 RenderManager.StateSetFogColour(data[0],data[1],data[2]); 324 } 325} 326 327void glLight(int light, int mode,FloatBuffer *values) 328{ 329 int idx; 330 if( light == GL_LIGHT0 ) 331 { 332 idx = 0; 333 } 334 else if( light == GL_LIGHT1 ) 335 { 336 idx = 1; 337 } 338 else return; 339 float *data =values->_getDataPointer(); 340 switch( mode ) 341 { 342 case GL_POSITION: 343 RenderManager.StateSetLightDirection(idx, data[0], data[1], data[2]); 344 break; 345 case GL_DIFFUSE: 346 RenderManager.StateSetLightColour(idx, data[0], data[1], data[2]); 347 break; 348 case GL_AMBIENT: 349 break; 350 case GL_SPECULAR: 351 break; 352 } 353} 354 355void glLightModel(int mode, FloatBuffer *values) 356{ 357 float *data =values->_getDataPointer(); 358 if( mode == GL_LIGHT_MODEL_AMBIENT ) 359 { 360 RenderManager.StateSetLightAmbientColour(data[0],data[1],data[2]); 361 } 362} 363 364void glLineWidth(float width) 365{ 366 RenderManager.StateSetLineWidth(width); 367} 368 369void glColorMask(bool red, bool green, bool blue, bool alpha) 370{ 371 RenderManager.StateSetWriteEnable(red, green, blue, alpha); 372} 373 374void glMultiTexCoord2f(int, float u , float v) 375{ 376 // Clamp these values just to be safe - the lighting code can get broken if we pass things to StateSetVertexTextureUV that are >= 1 377 if( u > 255.0f ) u = 255.0f; 378 if( v > 255.0f ) v = 255.0f; 379 380 RenderManager.StateSetVertexTextureUV( u / 256.0f, v / 256.0f); 381} 382 383void glTexGen(int coord, int mode, FloatBuffer *vec) 384{ 385 float *data = vec->_getDataPointer(); 386 387 RenderManager.StateSetTexGenCol( coord, data[0], data[1], data[2], data[3], mode == GL_EYE_PLANE ); 388} 389 390void glCullFace(int dir) 391{ 392 RenderManager.StateSetFaceCullCW( dir == GL_BACK); 393}