Skip to main content
gamedev.net
🔒 Locked

Loading Multiple Textures

Started by Mattman Oct 29, 2002 at 12:12 AM 2 replies 300+ views
Original Post
Mattman
Mattman
I have two VertexBuffers, and I want each to have a different texture. Presently, my code must call D3DXCreateTextureFromFileEx and D3DDevice->SetTexture before each VertexBuffer is rendered to the Device. Is there any way to have the texture be loaded once and be done with it, or do I have to have them constantly restored from the file with these two lines every cycle of execution?
krumms
krumms
You only need to load your textures ONCE: at the start of your program.

You do NOT need to load textures once every frame! This will cause a plethora of things to go wrong (memory leaks, framerate issues, the odd crash) and is simply not right.

You load the textures ONCE, then use SetTexture once per vertex buffer per frame in your case.

Again, DON''T load textures more than once. Especially don''t reload them every frame. I can''t stress it enough!!!

Tom L
refrain_from_stupidity( &me );
lubby
lubby
No way,!! your fps must be very slow if you are loading the texture every frame!!

only load your textures at init. you only need to load them once and use as many times as you like.

  

init{
D3DXCreateTextureFromFileEx(...tex1
D3DXCreateTextureFromFileEx(...tex2
}


render{
device->SetTexture(tex1);
render_vertex_buffer1();
device->SetTexture(tex2);
render_vertex_buffer2();
}

cleanup:
texture1->Release();
texture2->Release();



You prolly find your current method is failing after the first attempt. Im not sure here, but unless you release your texture LPDIRECT3DTEXTURE8::Release . you should really get an error. Maybe it just over writes not sure. But what you are doing is incorrect.


Mattman
Mattman
Wow...that was a really obvious answer...I don''t know why I even needed to ask. I feel really dumb now hehe, thanks for reminding me that I''m dumb

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.