try disabling or enabling vsync in your graphics card options (that limits the fps to whatever your refresh monitor rate is... at least in opengl)
try disabling or enabling vsync in your graphics card options (that limits the fps to whatever your refresh monitor rate is... at least in opengl)
"uh uh uh, you didn't say the magic word"
-Jurassic Park
VSync was already disabled, enabling it only made it worse, by keeping the FPS at ~75 (which is my refresh rate)
TexturedPlane.h
TexturedPlane.cppCode:#include <d3dx9.h> #include <string> class TexturedPlane { private: IDirect3DDevice9 *_Device; IDirect3DTexture9 *_Texture; IDirect3DVertexBuffer9 *_VBuf; IDirect3DIndexBuffer9 *_IBuf; std::string TextureFile; float _height; float _scale; public: TexturedPlane(); ~TexturedPlane(); Init(IDirect3DDevice9 *device,std::string File,float height,float scale); Render(D3DXVECTOR3 &cameraVec); };
Code:#include "TexturedPlane.h" struct PlaneVertex { PlaneVertex(float x,float y,float z,float u,float v):x(x),y(y),z(z),u(u),v(v) {}; float x,y,z,u,v; static const DWORD FVF; }; const DWORD FVF=D3DFVF_XYZ | D3DFVF_TEX1; TexturedPlane::TexturedPlane() { _Device=0; _Texture=0; _height=0.0f; _scale=0.0f; _VBuf=0; _IBuf=0; } void TexturedPlane::Init(IDirect3DDevice9 *device,std::string File,float height,float scale) { _Device=device; _height=height; _scale=scale; TextureFile=File; D3DXCreateTextureFromFile(Device,File.c_str(),&Texture); _Device->CreateVertexBuffer(4*sizeof(SkyPlaneVertex), D3DUSAGE_WRITEONLY, PlaneVertex::FVF, D3DPOOL_MANAGED, &_VBuf, 0); PlaneVertex* v=0; _VBuf->Lock(0,0,(void **)&v,0); v[0]=SkyPlaneVertex(-1.0f*scale,-1.0f*height,-1.0f*scale,0.0f,1.0f); v[1]=SkyPlaneVertex(-1.0f*scale,-1.0f*height, 1.0f*scale,0.0f,0.0f); v[2]=SkyPlaneVertex( 1.0f*scale,-1.0f*height, 1.0f*scale,1.0f,0.0f); v[3]=SkyPlaneVertex( 1.0f*scale,-1.0f*height,-1.0f*scale,1.0f,1.0f); _VBuf->Unlock; _Device->CreateIndexBuffer(6*sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &_IBuf, 0); WORD *indices=0; _IBuf->Lock(0,0,(void **)&indices,0); //Counter clockwise winding order - can see when below //0,1,2 3,5,4 -> clockwise winding order - can see when above indices[0]=0;indices[1]=2;indices[2]=1; indices[3]=0;indices[4]=3;indices[5]=2; _IBuf->Unlock(); } void TexturedPlane::Render(D3DXVECTOR3 &cameraVec) { D3DXMATRIX W; D3DXMatrixTranslation(&W, cameraVec.x, cameraVec.y, cameraVec.z); _Device->SetTransform(D3DTS_WORLD,&W); _Device->SetStreamSource(0,VB,0,sizeof(SkyPlaneVertex)); _Device->SetFVF(SkyPlaneVertex::FVF); _Device->SetIndices(IB); _Device->SetTexture(0,_Texture); _Device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0,0,4,0,2); }
That should work. Create the plane like this:
TexturePlane MyTexPlane;
Init the plane like this, where device is a valid IDirect3DDevice9 interface
MyTexPlane.Init(Device,"somefile.bmp",-200.0f,400.0f);
Draw the plane like this, where camera is a valid D3DXVECTOR3.
MyTexPlane.Render(camera);
You will have to alter the plane vertexes to create a flat plane that faces the viewer - this creates a plane that 'slides' on the y axis - thus the plane can be used as a sky or water. For sky the vertexes must be in the order specified - for water they must be reversed - this is because the backface cull will remove the plane.
A simple test is to test the y of the plane against the y of the camera and set the winding order via SetRenderState() in Direct3D. Don't forget to reset the winding order to the default prior to leaving the function or your other geometry will be culled.
Here are the coords for a plane that faces the viewer and has a clockwise winding order (clockwise cull).
-1.0f,1.0f,1.0f,0.0f,0.0f
-1.0f,-1.0f,1.0f,0.0f,1.0f
1.0f,-1.0f,1.0f,1.0f,0.0f
1.0f,1.0f,1.0f,1.0f,1.0f
Or you could simply rotate the plane I have to the desired angle - but this would be a waste since you could just re-specify the vertexes.
Last edited by VirtualAce; 04-05-2004 at 04:23 PM.