File: cs_80.html

package info (click to toggle)
crystalspace 0.94-20020412-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 62,276 kB
  • ctags: 52,843
  • sloc: cpp: 274,783; ansic: 6,608; perl: 6,276; objc: 3,952; asm: 2,942; python: 2,354; php: 542; pascal: 530; sh: 430; makefile: 370; awk: 193
file content (127 lines) | stat: -rw-r--r-- 6,276 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- Created by texi2html 1.64 -->
<!-- 
Written by: Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Olaf Bachmann <obachman@mathematik.uni-kl.de>
Send bugs and suggestions to <texi2html@mathematik.uni-kl.de>
 
-->
<HTML>
<HEAD>
<TITLE>Crystal Space: Simple Loading Material</TITLE>

<META NAME="description" CONTENT="Crystal Space: Simple Loading Material">
<META NAME="keywords" CONTENT="Crystal Space: Simple Loading Material">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META NAME="Generator" CONTENT="texi2html 1.64">

</HEAD>

<BODY LANG="" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080" ALINK="#FF0000">

<A NAME="SEC178"></A>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_79.html#SEC177"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_81.html#SEC179"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_73.html#SEC171"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_79.html#SEC177"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_83.html#SEC181"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<HR SIZE=1>
<H3> 5.3.1 Loading a Material in Memory </H3>
<!--docid::SEC178::-->
<P>

To make this example a little more interesting the material is going to be
loaded <EM>after</EM> the other setup of the texture manager has been done.
This is not really needed but it illustrates how a game might load materials
dynamically later when the application is already running.  So first we edit
`<TT>simple.cpp</TT>' and add the following in <CODE>Simple::Initialize()</CODE>
(between <CODE>txtmgr-&#62;SetPalette()</CODE> and `<SAMP>return true</SAMP>'):
</P><P>

<TABLE><tr><td>&nbsp;</td><td class=example><pre>bool Simple::Initialize(int argc, const char* const argv[])
{
  <small>...</small>
  txtmgr-&#62;SetPalette ();

  // Load a texture for our sprite.
  iTextureWrapper* txt = loader-&#62;LoadTexture ("spark",
  	"/lib/std/spark.png", CS_TEXTURE_3D, txtmgr, true);
  if (txt == NULL)
  {
    csReport (object_reg, CS_REPORTER_SEVERITY_ERROR,
    	"crystalspace.application.simple",
    	"Error loading texture!");
    return false;
  }

  return true;
}
</pre></td></tr></table></P><P>

This code first loads a texture in our engine with
<CODE>iLoader::LoadTexture()</CODE>.  The second argument is the file name for our
texture (VFS path) and the first argument is how that texture should be
named in the engine.  In this case we use `<SAMP>spark</SAMP>' for that because that's
how the `<TT>sprite1</TT>' definition wants it. The third parameter indicates
for what we want to use this texture. In this case we want to use it to texture
map a model for the 3D engine so the texture must be prepared for 3D.
The fourth parameter is the texture manager which will be used to register
and prepare the texture and material. This is done automatically by
this function because the fifth parameter is set to 'true'. In the previous
tutorial we also used this function to load a texture but there we didn't
specify the last three parameters. `<SAMP>CS_TEXTURE_3D</SAMP>' is default so that
doesn't have to be specified and because we were going to call
<CODE>engine-&#62;Prepare()</CODE> later we also didn't specify the texture manager
and the last boolean parameter because <CODE>Prepare()</CODE> automatically
registers and prepares all textures and materials that are loaded.
</P><P>

If this loading succeeds this function will register our texture with the
texture manager. As mentioned above this is needed because we are loading
this texture AFTER <CODE>engine-&#62;Prepare()</CODE>. So this is an easy way to
dynamically add textures and materials even when the engine is already
running. Note that if you plan to load many new textures and materials
it is more efficient to not let this function register automatically but
instead register them manually and then call <CODE>txtmgr-&#62;PrepareTextures()</CODE>
to prepare them all at once.
</P><P>

Note that when you load a texture like this there will also be an
associated material with the same name. The engine itself works with
materials and doesn't directly use textures. The material in this case
is simply a wrapper on top of the texture. But you could also add detail
textures.
</P><P>

<A NAME="Simple Loading Mesh Factory"></A>
<HR SIZE=1>
<TABLE CELLPADDING=1 CELLSPACING=1 BORDER=0>
<TR><TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_79.html#SEC177"> &lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_81.html#SEC179"> &gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_73.html#SEC171"> &lt;&lt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_79.html#SEC177"> Up </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_83.html#SEC181"> &gt;&gt; </A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT"> &nbsp; <TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="index.html#SEC_Top">Top</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_toc.html#SEC_Contents">Contents</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_285.html#SEC711">Index</A>]</TD>
<TD VALIGN="MIDDLE" ALIGN="LEFT">[<A HREF="cs_abt.html#SEC_About"> ? </A>]</TD>
</TR></TABLE>
<BR>  
<FONT SIZE="-1">
This document was generated

using <A HREF="http://www.mathematik.uni-kl.de/~obachman/Texi2html
"><I>texi2html</I></A>

</BODY>
</HTML>