objects on terrain

Started by
31 comments, last by Hodgman 15 years, 7 months ago
I don't know much about opengl, but logic dictates that if you can render a terrain - you can render other objects like a tree. Export a textured quad that looks like a tree, possibly with some alpha blending - then render it in the same way you rendered your terrain.

The rotation is neccessary if you want the tree to always face the camera to trick the viewer into thinking it's 3d - i.e. billboarding.
Advertisement
i understand what u are saying, but..

see i have a tga file with the image of a tree, now i want to render it on the terrain. i know i have to first load the file and then render it..

but i am not able to do it..

can anyone suggest a simple code for doing the same??

with anticipation
regards
Does the word "texture" mean something for you ? If no you should start to learn it first, and how to use it (cf. nehe tutorial about texture in OpenGL). Then your problem is solved: drawing trees as billboards is just drawing a quad and applying your tree texture on it.
Some of my previous work on my personal webpage
i know you all are experts in the domain on this forum, but please understand that i am just a beginner..so sorry if u feel i am asking nonsensical questions.

i have the image of a tree do i still have to draw a quad??

can u please post a simple code wherein i load the file,render it to the terrain??
Create a quad with the texture of the tree. This will allow you to draw the tree as a quad.

Now, there are two problems here:

First, the quad is flat, so if you look at it sideways, the 3D illusion will be ruined. To fix this, you have to make sure that the quad always faces the camera, and this will make it look like a 3D tree (well sort of). This is called billboarding and is covered in the articles linked earlier.

Second, you need the tree to be placed on the terrain. You can decide on the tree's x and z position, but the y position will be determined by the height of the terrain at that coordinate, so the tree's world position would be:

(x, terrainHeightAt(x, z), z)

So given an (x, z) pair, you need to know the terrain's height at that location. You can find a good explanation of that here.

If this doesn't answer your question, you'll need to be more specific.
i understand i have to create a quad for the tree, but how do i do it??

in case of terrain i had the height values which i used to display the heightmap..
but in case of tree i have a image file, how do i do the tree??

pleaseee give me an example..
I don't use OpenGL so I don't know it well enough to write the code, but there are some video tutorials here that you might want to go over. Look at their outline to see what's covered (you'll probably find tutorial 11 especially interesting).

Of course, doing a google search will turn up many more tutorials.
If you've drawn the terrain already, you either know how to create quads and/or triangles, or else you've just copy/pasted some source and don't understand it.

Read the tutorials linked-to above; you'll see both the why and the how explained in them.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Quote:Original post by Wyrframe
If you've drawn the terrain already, you either know how to create quads and/or triangles, or else you've just copy/pasted some source and don't understand it.



are you angry with me for asking questions?? i have no experience in this hence i am asking you questions..

ok, i have gone thru some of the links but what i understand is that they tell how to texture the whole object after reading a single bmp file.

thats fine, i understood.

but whats happening with me is that the terrain has one texture and i am trying to put a tree with another texture.there are 2 files. when i read and load the texture, the texture of the terrain gets changed and the tree is not displayed.


Quote:Original post by vpk
whats happening with me is that the terrain has one texture and i am trying to put a tree with another texture.there are 2 files. when i read and load the texture, the texture of the terrain gets changed and the tree is not displayed.


You need to set the texture for each object before drawing it, so your code should look something like this:

setTexture(terrainTexture);drawTerrain();setTexture(treeTexture);drawQuad();

This topic is closed to new replies.

Advertisement