bool GLS_IMG_Image::_Init (const char *lpsz_image_path) { // set bitmap size m_textid = SOIL_load_OGL_texture ( lpsz_image_path, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | /*SOIL_FLAG_INVERT_Y |*/ SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); /* check for an error during the load process */ if( 0 == m_textid ) { printf ( "SOIL loading error: '%s'\n", SOIL_last_result() ); return false; } // m_bmp_width = (short)bmphdr.biWidth; // m_bmp_height = (short)bmphdr.biHeight; // m_width = m_bmp_width; // m_height = m_bmp_height; // setup vertices array... SetupVertices (); SetupTextureVertices (); m_initialized = true; return true; }
void CDirect3D::SetViewport() { D3DXMATRIX matIdentity; D3DXMATRIX matProjection; D3DXMatrixOrthoOffCenterLH(&matProjection,0.0f,1.0f,0.0f,1.0f,0.0f,1.0f); D3DXMatrixIdentity(&matIdentity); pDevice->SetTransform(D3DTS_WORLD,&matIdentity); pDevice->SetTransform(D3DTS_VIEW,&matIdentity); pDevice->SetTransform(D3DTS_PROJECTION,&matProjection); SetShaderVars(true); RECT drawRect = CalculateDisplayRect(afterRenderWidth,afterRenderHeight,dPresentParams.BackBufferWidth,dPresentParams.BackBufferHeight); D3DVIEWPORT9 viewport; viewport.X = drawRect.left; viewport.Y = drawRect.top; viewport.Height = drawRect.bottom - drawRect.top; viewport.Width = drawRect.right - drawRect.left; viewport.MinZ = 0.0f; viewport.MaxZ = 1.0f; HRESULT hr = pDevice->SetViewport(&viewport); SetupVertices(); }
bool COpenGL::ChangeDrawSurfaceSize(unsigned int width, unsigned int height) { DestroyDrawSurface(); CreateDrawSurface(width, height); SetupVertices(); return true; }
bool COpenGL::ChangeDrawSurfaceSize(unsigned int scale) { filterScale = scale; DestroyDrawSurface(); CreateDrawSurface(); SetupVertices(); return true; }
void DiInstanceBatch::Build( const DiSubMesh* baseSubMesh ) { if( CheckSubMeshCompatibility( baseSubMesh ) ) { SetupVertices( baseSubMesh ); SetupIndices( baseSubMesh ); CreateAllInstancedModels(); } }
/* CDirect3D::ChangeDrawSurfaceSize changes the draw surface size: deletes the old textures, creates a new texture and calculate new vertices IN: scale - the scale that has to fit into the textures ----- returns true if successful, false otherwise */ bool CDirect3D::ChangeDrawSurfaceSize(unsigned int scale) { filterScale = scale; if(pDevice) { DestroyDrawSurface(); CreateDrawSurface(); SetupVertices(); return true; } return false; }
bool COpenGL::ChangeRenderSize(unsigned int newWidth, unsigned int newHeight) { RECT displayRect, windowSize; if(newWidth==0||newHeight==0) { GetClientRect(hWnd,&windowSize); newWidth = windowSize.right; newHeight = windowSize.bottom; } displayRect=CalculateDisplayRect(afterRenderWidth,afterRenderHeight,newWidth,newHeight); glViewport(displayRect.left,newHeight-displayRect.bottom,displayRect.right-displayRect.left,displayRect.bottom-displayRect.top); SetupVertices(); return true; }
HRESULT STDMETHODCALLTYPE GLS_IMG_Image::put_height (float height) { m_height = height; SetupVertices (); return NOERROR; }
HRESULT STDMETHODCALLTYPE GLS_IMG_Image::put_width (float width) { m_width = width; SetupVertices (); return NOERROR; }
HRESULT STDMETHODCALLTYPE GLS_IMG_Image::put_y (float y) { m_y = y; SetupVertices (); return NOERROR; }
HRESULT STDMETHODCALLTYPE GLS_IMG_Image::put_x (float x) { m_x = x; SetupVertices (); return NOERROR; }
bool GLS_IMG_Image::_Init (const char *lpsz_image_path) { // bitmap data FILE *fp; BITMAPFILEHEADER hdr; BITMAPINFO bmpinfo; BITMAPINFOHEADER &bmphdr = bmpinfo.bmiHeader; // open texture file fp = fopen ( lpsz_image_path, "rb" ); if (fp == NULL) { return false; } // check magic bytes fread (&hdr, sizeof(hdr), 1, fp); if (hdr.bfType != BMP_SIG) { fclose (fp); return false; } // must be 24 bits RGB fread (&bmpinfo, sizeof(bmpinfo), 1, fp); if (bmphdr.biBitCount != 24) { fclose (fp); return false; } // read texture data int size = bmphdr.biWidth * bmphdr.biHeight * 3; BYTE *pBits = new BYTE [size]; if (!pBits){ fclose (fp); return false; } // read pixels int pad; char padbuff[3]; BYTE *ptr, temp; pad = (bmphdr.biWidth * 3) % 4; pad = 4 - (pad == 0 ? 4 : pad); fseek (fp, hdr.bfOffBits, SEEK_SET); ptr = pBits; for (int i=0; i<bmphdr.biHeight; i++) { for (int j=0; j<bmphdr.biWidth; j++) { fread (ptr, 3, 1, fp); temp = ptr[0]; ptr[0] = ptr[2]; ptr[2] = temp; ptr+= 3; } fread (padbuff, pad, 1, fp); } // close file fclose (fp); // set bitmap size m_bmp_width = (short)bmphdr.biWidth; m_bmp_height = (short)bmphdr.biHeight; // fix the inverted bitmap FixBMPUpDown (pBits, m_bmp_width, m_bmp_height); // make Open GL texture glPixelStorei (GL_UNPACK_ALIGNMENT, 1); // generate single texture and bind it glGenTextures ( 1, &m_textid); glBindTexture ( GL_TEXTURE_2D, m_textid ); m_width = m_bmp_width; m_height = m_bmp_height; // set texture parameters glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR/*GL_NEAREST*/); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR/*GL_NEAREST*/); // set texture environemnt glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); // define texture image glTexImage2D ( GL_TEXTURE_2D, 0, /* mipmap level 0 */ 3, /* internal format */ bmphdr.biWidth, bmphdr.biHeight, 0, /* border */ GL_RGB, GL_UNSIGNED_BYTE, pBits ); // do cleanup delete [] pBits; // setup vertices array... SetupVertices (); SetupTextureVertices (); m_initialized = true; return true; }