* * Objectives * Contribution of vines to the wealth of tropical rainforests * Distribution * Ecological and physiological aspects * Negative effects of lianas on host trees * Conclusions * Bibliography 1. INTRODUCTION Lianas are an important component of plant diversity in tropical rain forests. Provide much of the forest biomass, competing with trees for light, moisture and nutrients and provide food for various species of animals and humans. In tropical rain forests lianas are generally more abundant than in any other ecosystem. In the Neotropics, there are 133 plant families that include at least some species of climbers. Vines grow abundantly in both sunlit areas and inside the …
Texture shading. Texturing
*
Abstract
* Introduction
* Loading texture memory
* Moving to OpenGL textures
* Parameters of textures
* Rendering with textures
* Colors, lights and textures
* Algorithms
* Conclusions
* Bibliography
ABSTRACT
In this work we will see a basic aspect if we are to a scene containing a minimum of realism: The texturing. For texturing understand the process of assigning an image (bitmap) to a polygon, so that instead of seeing this on a flat color or gradient of colors, see the image projected on it.
INTRODUCTION
So far the primitives in OpenGL are drawn with a single color or
various colors by interpolating between the vertices of a primitive. OpenGL has specific functions for texture mapping (paste images on the surface of the primitives drawn), adding realism to the scene. This paper explains the process of texture mapping through a simple example, then use the textures in the application.
The textures in OpenGL can be 1D, 2D or 3D. The 1D have width but not height, the 2D are images that have a width and a height of more than 1 pixel, and are usually loaded from a file. Bmp (although it can be in principle any format). In this paper does not discuss 3D textures (volume). A very important aspect to consider is that in OpenGL the size of the images must be a power of 2.
This work is limited to study 2D texturing, and propose implementations for a better texture loaded and renderer.
DEVELOPMENT
1.1. Loading textures into memory
The process of loading the texture memory, OpenGL is not proper, what we must do ourselves. However, we must consider some limitations that the library imposes. First, the size of all textures we load must be powers of 2, such as 64×64, 128×64, etc.
We must also bear in mind that if we are drawing in RGB, not indexed color or texture load or convert RGB to RGB. That is, if we load a GIF image, which has indexed color is on us to pass it to RGB. Whichever method you choose, the end will have a pointer to a memory segment that contains the image:
unsigned char * texture;
It is also important to keep the texture properties, namely its width and height dimensions and its bit depth. If you’re working in RGB, the depth is 24 bits.
1.2. Moving to OpenGL textures
Now we have the texture RAM. However, OpenGL can not work directly with this report, must use their own memory to store textures. The must be kept in RAM memory space, or directly pass them to the accelerator card. Once we pass the texture to OpenGL, it will return an identifier that will save. Each texture will handle itself, then we have to use when drawing. Consider the process of obtaining this ID. Let’s create a variable to store:
IdTextura GLuint;
Then call the function glGenTextures (…), to which we pass the number of textures that we generate, and an array of identifiers where we want to store. In this case, we just want a texture, and therefore no need to pass an array, but a pointer to a variable of type GLuint.
glGenTextures (1, & idTextura)
This OpenGL textures look how many have already saved, and this function will idTextura the value of the identifier. Then, use glBindTexture (…) function to assign the value of idTextura, a target texture. It is as if the texture will activate idTextura assigned to, and modify all the properties thereafter, will amend this texture only, not the other, just as we activate a light and define their properties.
glBindTexture (GL_TEXTURE_2D, idTextura)
Now it remains the most important step, which is to pass the texture to OpenGL. To do this we will use the function glTexImage2D (…)
GlTexImage2D (GL_TEXTURE_2D, 0, 3, anchoTextura, altoTextura, 0,
GL_RGB, GL_UNSIGNED_BYTE, texture);
But see all the parameters, see the parameters of this function one
by one:
void glTexImage2D (
GLenum tipoTextura,
Glint nivelMipMap,
Glint formatoInterno,
GLsizei width,
GLsizei height,
Glint edge
GLenum format
GLenum type,
const GLvoid * pixels
)
. TipoTextura: The type of texture you’re trying. It must be
GL_TEXTURE_2D.
. NivelMipMap: mipmapping level we want. At the moment
will ’0 ‘, which means we will see later.
. FormatoInterno: The number of components in the texture. That is, if
we are working in RGB format, the number of components is 3.
. Width, height, width and height of the texture. Must be powers of 2.
. Edge: The width of the border. Can be 0.
. Format: The format of the texture that is stored in memory. We
GL_RGB will use.
o Type: The type of variables in which we stored the texture. If
we have stored in an unsigned char, use GL_UNSIGNED_BYTE.
. Pixels: The pointer to the memory region where image is stored.
An observation. RAM had in a texture loaded from a file. This texture, we have come to OpenGL, which has stored in its memory. So now we have two copies of the same texture memory, only one is no longer needed, ours. It is therefore advisable to remove our memory textures once we have passed to OpenGL.
free (texture);
1.3. Texture parameters
For each texture we can assign a certain characteristics. The first is the view filter. A texture is a bitmap consisting of a set of pixels, arranged on a regular basis. If the texture is 64 x 64 pixel, i show it in a window full resolution 1024×768 pixels OpenGL scaled these so that each pixel of the texture (texel hereafter) occupy 16×12 pixels on the screen.
1024 pixels wide / 64 texels wide = 16;
768 pixels high / 64 texels high = 12;
That means that we will be “square” 16×12, each representing a texel of the texture. Visually it is very unrealistic to see a texture ‘pixelated’, so we apply filters to avoid it. The most common is the ‘linear filter, “which is based on making an interpolation at each pixel on screen drawing. Although it may seem costly in computational level, this is done by hardware and does not affect performance.
Let’s see how we can implement:
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
With this we are parametrizing two filters. One for when the texture is larger than it really is (the example we discussed) and one for when the texture is smaller: GL_TEXTURE_MAG_FILTER and GL_TEXTURE_MIN_FILTER, respectively. In both tell him to do a linear filter. We may also tell you not to apply any filters (GL_NEAREST).
Usually when texturing a scene, the model applies a small texture is repeated across a surface, so that by sacrificing realism, use less
memory. We tell OpenGL to prepare the texture to be drawn so
of ’tile’ or to be drawn only once. For example, a poster on a wall. On the wall there would be a small brick texture, which is repeated n times along the entire wall surface. Instead, the bill is drawn only once. Brick texture should prepare to be repeated, and no poster. OpenGL really really does, to draw the texture and apply the linear filter is at the edges, interpolate the texels on the opposite edge, to give a more realistic appearance.
If we turn this option would:
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
If we are interested in this effect:
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
For GL_TEXTURE_WRAP_T GL_TEXTURE_WRAP_S and we refer to
filter to the rows and columns, respectively.
1.4. Rendering with textures
Now that you have the textures loaded and adjusted to our liking, let’s see how we can draw polygons with textures applied. Suppose we want to draw a simple square, with a texture you’ve previously uploaded.
If no texture draw would be:
glBegin (GL_QUADS)
glVertex3i (-100, -100, 5);
glVertex3i (-100, 100, 5);
glVertex3i (100, 100, 5);
glVertex3i (100, -100, 5);
glEnd ();
Let us now as we would apply a texture:
glEnable (GL_TEXTURE_2D);
glBindTexture (GL_TEXTURE_2D, idTextura)
glBegin (GL_QUADS)
glTexCoord2f (0.0f, 0.0f);
glVertex3i (-100, -100, 5);
glTexCoord2f (1.0f, 0.0f);
glVertex3i (-100, 100, 5);
glTexCoord2f (1.0f, 1.0f);
glVertex3i (100, 100, 5);
glTexCoord2f (0.0f, 1.0f);
glVertex3i (100, -100, 5);
glEnd ();
glDisable (GL_TEXTURE_2D);
Consider the code step by step:
glEnable (GL_TEXTURE_2D);
OpenGL glEnable function allows us to turn on and off properties that are applied when rendering. In this case, we are saying that you enable texturing
glBindTexture (GL_TEXTURE_2D, idTextura)
As we had seen before, glBindTexture function is responsible for activating the texture you want, referenced by the ID that you previously saved in idTextura.
glBegin (GL_QUADS)
glTexCoord2f (0.0f, 0.0f);
glVertex3i (-100, -100, 5);
Here we see something that was not before, we refer to glTexCoord2f (). This feature introduces a new concept: the texture coordinates, and refer to them generally as ‘s’ and ‘t’, where ‘s’ horizontal axis and ‘t’ the vertical. Used to refer to a position of the texture. Generally move in the interval [0,1].
The coordinate (0, 0) refers to the lower left corner, and (1, 1) to upper right. Therefore, if you look at the code, each vertex we assign a texture coordinate, always in order counter clockwise, but the texture would be reversed.
We have commented that the texture coordinates are moving in the interval [0,1], but OpenGL allows for other values. We could consider that the texture is repeated infinitely in all directions so that the coordinate (1, 0) would be the same texel that (2, 0), (3, 0), etc. However, if we draw a square and assign it to an end (2, 2) instead of (1, 1), draw the texture repeated 2 times in each direction, a total of 4 times. We can play and assign values (-1, -1) to (1, 1), etc.
Once we have drawn the geometry you want, it is important to turn off texturing, if we do, if you later want to draw an object without texture, OpenGL will try to do, even if we pass texture coordinates, producing strange effects. Thus:
glDisable (GL_TEXTURE_2D);
1.5. Colors, lights and textures
We have been talking about a surface texture, but what about color Can we really continue to use, it is more, OpenGL texture and color at a time. We can turn red, and all the textures to be drawn from then, will the same color tinted.
Similarly with the lights. There is no problem in combining colors, lights and textures at once. If you do not want any light, just not set the lighting, and if we want to go textures tinted a color, simply set the current color as white.
Algorithm:
# Include
# Include “bitmap.h”
BITMAPINFO * texinfo / * Texture bitmap information * /
TexBits GLubyte * / * Texture pixel bitmap bits * /
void display (void) {
glClearColor (1.0, 0.0, 0.0, 0.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
LoadDIBitmap TexBits = (“escudo.bmp”, & texinfo);
glTexImage2D (GL_TEXTURE_2D, 0, 3, texinfo-> bmiHeader.biWidth, texinfo-> bmiHeader.biHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, TexBits)
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)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glColor3f (1.0, 1.0, 1.0);
/ / Activate the mapping detexturas
glEnable (GL_TEXTURE_2D);
glBegin (GL_POLYGON)
glTexCoord2f (0.0, 0.0);
glVertex2f (-1.0, -1.0);
glTexCoord2f (1.0, 0.0);
glVertex2f (1.0, -1.0);
glTexCoord2f (1.0, 1.0);
glVertex2f (1.0, 1.0);
glTexCoord2f (0.0, 1.0);
glVertex2f (-1.0, 1.0);
glEnd ();
glDisable (GL_TEXTURE_2D);
glutSwapBuffers ();
}
void reshape (int width, int height) {
glViewport (0, 0, width, height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60.0, (GLfloat) height / (GLfloat) width, 1.0, 128.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
gluLookAt (0.0, 1.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
int main (int argc, char ** argv)
{
glutInit (& argc, argv);
glutInitDisplayMode (GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE)
glutInitWindowSize (400, 400);
glutInitWindowPosition (100, 100);
glutCreateWindow (tecnunLogo “);
glutReshapeFunc (reshape);
glutDisplayFunc (display);
glutMainLoop ();
return 0;
}
Load Texture
bool CTextura: CargarBMP (char * szNombreFichero)
{
FILE * hFichero;
AUX_RGBImageRec * Image;
bool bResult = false;
if (szNombreFichero)
/ / Check that the filename is correct
{
hFichero = fopen (szNombreFichero, “r”);
/ / Check if file exists (if we can open it)
if (hFichero) / / file exists
{
fclose (hFichero) / / Close the handle
Create (szNombreFichero)
Image = auxDIBImageLoad (szNombreFichero)
/ / Load the BMP
m_nAncho = image-> sizeX;
m_nAlto = image-> SizeY;
glTexImage2D (GL_TEXTURE_2D, 0, 3, m_nAncho, m_nAlto, 0, GL_RGB, GL_UNSIGNED_BYTE, Image-> data);
bResult = true;
}
}
delete Image-> data;
delete Image;
return bResult;
}
CONCLUSIONS
Texture mapping can be summarized in four steps:
1. Loads an image and is defined as a texture.
2. Shows how the texture will be applied to each pixel of the surface.
3. Activated texture mapping.
4. Draw the scene, indicating the correspondence between the coordinates
the texture and the vertices of the surface.
Normally in a scene tend to have many different textures. If we draw all geometry disorderly, it is possible that every few triangles have to change texture. The process of change in texture is a certain cost, so it is advisable to organize our geometry, making groups of surfaces having the same texture, so do the least possible changes. We can also do the same with the materials in the case that we make use of them.
Bibliography
1. [IPG04]
Introduction to Graphics Programming with OpenGL
(Oscar Garcia and Alex Guevara) La Salle 2004
2. [Map01]
Texture mapping tutorial
(Fernando Jose Serrano) 25/04/1901
3. [Ham99]
Hammersley, T., “Texture Shading” GameDev.Net Website at October, 1999.
Additional items from "Architecture and Interior Design"
- Morphology Greek monastery in space
- Theory of architectural design guidelines
- Graphic Design Notes
- The Pyramids of Egypt
- CallBack Pattern
- Analysis and technical infrastructure rehabilitation, environmental and Santo services ..
- Project outline fixed floating house (CATT) “House Anti Tsunamis and Earthquakes
- The jars (Olive Jars) Its reuse in three colonial buildings Havana
- Home Automation – Intelligent Architecture
- Architectural history
Recent Articles
The penal system as an instrument of social control
* The Social Order and Social Control * The Penal System * Criminal Classification System * Primary and secondary Criminalization * Final assessment I. – INTRODUCTION The penal system is establishing representations and social relations, public policy, discourses of power, and even their own language settings, criminal law, in sum represents the daily life of societies. It is therefore necessary to assess the state penal system and the role it plays in the democratization of punitive power. Moreover if in criminal matters following on from recent years: increasing penalties, in fact, this is virtually the only criminal policy in the fight against crime, because he mistakenly thought that the increased …
Human Digestive System
* Your Anatomy * Synthesis and Organic Substances Denigration * Vitamins In humans, the digestive system consists of a conduit along which are arranged various organs and structures that are traversed by the food during its transformation process, those parts by passing the solid portion of the food is expelled as waste. The basic constituents of the human digestive tract are the mouth, pharynx, esophagus, small intestine and large intestine, liver, pancreas and gallbladder. The glands that secrete digestive juices include the salivary glands and gastric glands. The mouth forms the opening of the digestive tract and is the cavity that penetrates the food. The oral cavity is limited by …
Thinking and strategies of power: the case of pension reform
* 1. The controversy over the financial crisis of public pensions * 2. The goodness of the alternative systems In recent years there has been a truism that has penetrated deeply into public opinion: the current public pension system is in crisis and need to modify it without remedy and without delay. In the largest circulation magazines, in newspapers and in general, in all media has multiplied news and analysis aimed at trying to justify that view citizens and to take the undisputed evidence of its certainty. Based on high-impact renew intuitive reasoning (with such high levels of unemployment not generated sufficient contibuciones for States to pay the pensions, …
The guardian and the formation of values in the New Cuban University
Introduction The tutor is considered now as one of the key components of comprehensive education process for students, is an educator responsible for integrating the system of educational influences, which focuses on guiding mode in the various areas the student’s education, promoting personal growth and development of self-determination: one who accompanies the student throughout their career by providing the necessary support for decision making to problems, from a custom action. The main goal is mentoring, advising and guiding the students during their studies, to contribute to their comprehensive training, educational activities systematically by custom. The tutor is an essential factor in the ideological, political and moral development of students, along …
