t3jem
Apr 29 2007, 06:55 PM
Lesson 4 of 6. I hope you are enjoying them  . QUOTE Hello, in this tutorial we will be creating a 3D pyramid. We are building this tutorial from Lesson 3, but I took out the 2D objects and placed a 3D pyramid in there instead. The 3rd axis for drawing can be a litle confusing, but after you get the hand of it you'll do fine. Now when you are setting a 3D vertex just remember that the camera is on the positive end of the z axis. So things that have a more positive z axis value are closer than verteces with a more negative value. Well let's get started We always start by including the glut library CODE #include<glut.h> the time variable will be used to keep track of how much time has passed. CODE float time = 0;// set time variable to 0 Our first new function is glOrtho();, this function is much like gluOrtho2D(), but glOrtho() defines how far along the z axis you can view objects as well, this is very important when drawing 3D objects. Next we want to enable depth testing to let our program test which polygons are where and draw them in the correct order for us, to do this we use glEnable() with the argument GL_DEPTH_TEST. CODE void init() { glClearColor(0,0,0,0); glOrtho(-5,5,-5,5,-5,5);//(NEW) set up our viewing area
glEnable(GL_DEPTH_TEST);//(NEW) Enable depth testing } In our display function we will create a 3D pyramid. To set the verteces we will use glVertex3f() instead of glVertex2f() so we can define where the point is on the z axis to add depth. in our glClear() function we add a new argument that we seperate with a "|". The new argument is GL_DEPTH_BUFFER_BIT to enable the depth buffer so our program can draw 3D objects correctly. CODE void display() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);//(NEW) setup our buffers
glPushMatrix(); glRotatef(time,0.8,5,0);//rotate our objects
glBegin(GL_TRIANGLES); //This is going to be the face facing the camera //We want this face to be red glColor3f(1,0,0); glVertex3f(-1,-1,1);//(NEW) We are now defining the vertex position on all three axis glVertex3f(0,1,0);//the top vertex glVertex3f(1,-1,1);//last vertex of this face
//We do not need to enter glEnd() here because we are still drawing triangles
//The back left face //This face will be green glColor3f(0,1,0); glVertex3f(-1,-1,1);//Vertex closest to us glVertex3f(0,1,0);//The top vertex glVertex3f(0,-1,-1);//The vertex farthest away
//The back right face //This face will be blue glColor3f(0,0,1); glVertex3f(0,-1,-1);//The farthest vertex glVertex3f(0,1,0);//The heighest vertex glVertex3f(1,-1,1);//The closest vertex
//The bottom face //This is face will be white glColor3f(1,1,1); glVertex3f(-1,-1,1);//Each corner of the base of the pyramid glVertex3f(0,-1,-1); glVertex3f(1,-1,1);
glEnd();//done drawing our triangle
glPopMatrix();
glFlush(); glutPostRedisplay();//This function is crucial in animation, it refreshes the screen } next we create our idle function which will update our time variable CODE void idle() { time += 0.1;// increase our time variable
if(time > 360) time = 0;// reset time variable } next is our main function. The only difference is in the gluInitDisplayMode() function, we added GLUT_DEPTH as an argument to tell the program to use the depth buffer. CODE void main(int argc, char ** argv) { glutInit(&argc, argv); glutInitWindowSize(800,600); glutInitWindowPosition(10,50); glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPTH);//tell the program we are running the depth buffer glutCreateWindow("Lesson 4"); init(); glutDisplayFunc(display); glutIdleFunc(idle);// This function calls our idle function to update our variables glutMainLoop(); } depth testing is very important when creating 3D objects, you must enable, tell the program to clear it, and you must tell it that you are using the depth buffer. If you don't do all of these than your program will draw everything in the wrong order and it will look very confusing. I hope you enjoyed yet another GLUT tutorial. The next tutorial will include texturing and keyboard interaction. Edited on December 28 2006 to make more readable.
Reply
Similar Topics
Keywords : programming, glut, lesson, 4, creating, 3d, objects
- Getting Started With Mysql
creating tables and insert data into them. (2)
Bryce 5 --- Boolean Objects
(0) Description Learn to create super sexy booleans with Bryce. This skill will increase your 3D
capabilites, an improve your artistic, or design skills over all. As well it enables you to turn
basic shapes into more complex shapes, allowing you to create more realistic, or even funkier
images/objects than you would have been able to previosly. FINISHED PRODUCT Try It Out
Alright, as this is only a tutorial, we'll be starting with something quite simple. On the
object tool bar, select the sphere twice. After these spheres have been created, move them so the....
Creating Navigation For Html Websites
Have a common navigation menu for the whole website! (12) Pre-requisite: HTML, inline frame tags 1 Attachment(.zip) included. Updates : 29-12-07: Doctype
added in example files (Advised by jlhaslip) Designing a whole website takes a lot of planning
and organization. Designing a proper navigation system is a basic step in building your website. If
you are developing webpages in html you would have observed that as you go on creating pages it
becomes difficult to maintain the links to the pages. This article will guide you in developing a
common navigation menu for your website. It describes three ways, so if you don'....
Programming Using Basic Language!
This topic will be big - PM me for more! (0) --Please tell me if I have errors in this! Thank you!-- Welcome to Ask Andrew D's Guide
to programming in the basic language. I am very experienced with basic and I have used several
different types. I will provide you with each one. I'll assume you have played around with some
type of language for just a short while, but gave up. Well, here are some parts that will help you
in what you want to do! REM // /* */: Rem is the easiest command you will EVER HAVE TO LEARN,
guaranteed. It stands for a remark, or comment. Here is how you use it: CODE #1....
Creating A Resume
10 Tips For Making A Resume (1) I've been working on my Resume for months now. Here is a summary of what I've learned: 1.
Avoid referring to yourself via 1st person or 3rd person terms. Rather than saying "I started this
job in" just say "Began job in"... Employers expect Resumes to be professional and avoid reference
to oneself; and instead speaking in an impersonal tone that presents
achievements/skills/experience/education without personalization. Avoid words like "I", "my", "he",
"she", etc. Leave out personal pronouns and only use the action words/verbs. This also includes
your Ob....
Programming In Glut (lesson 6)
Texture filters and lighting (2) This is the last of the six tutorials I have moved from astahost. I hope you enjoy these and the
rest soon to come. QUOTE This tutorial demonstrates how to use texture filters and will let you
see the differences of each filter. I will also be introducing lighting into this tutorial. We
first have to create our "bitmap.h" header file with the functions we use to load our bitmaps, this
is changed from the last tutorial to fit the needs of this one. The first thing to do is to link
all of our OpenGL libraries and include our needed headers for the functions we w....
Programming In Glut (lesson 5)
Texture mapping and keyboard controls (0) Lesson 5 of 6. These are beginning to be more advanced tutorials. If you are not familiar with my
previous tutorials you may need to go back and read them. QUOTE In this tutorial I am going to
teach you how to texture map your polygons and implement basic keyboard control. There is alot of
new material in this tutorial and I hope I have explained it enough. Before you get started you
will want to name a bmp file "image.bmp" or "image" depending on your computer settings (if one
doesn't work then use the other) and place it in the same folder as your project.....
Programming In Glut (lesson 3)
Animating your objects (0) Lesson 3 of 6. QUOTE In this tutorial I am going to talk about how to get animation in your
program. I will be working directly off of Lesson 2 and will now take out the notes left behind
from Lesson 1, but I will leave the notes from Lesson 2. CODE #include<glut.h>//include
our glut library First we are going to initialize a variable called "time" which will record how
much time has passed so we can use it to determine how to animate the objects. Then we have our
init function that initializes some stuff in GLUT CODE float time = 0;//(NEW....
Programming Glut (lesson 2)
Drawing 2D objects (0) This is the second of the six from astahost, again, I hope you enjoy. /smile.gif"
style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> QUOTE This is the second
lesson in my series of tutorials on how to use GLUT to create graphics. In this tutorial I am going
to be teaching you how to create different types of polygons. I am going to be adding on to last
tutorial's code and will leave the notes in to help you remember what all the function are. I
will also be noting the new functions that we will be using and how to use them. CODE #inc....
Programming In Glut (lesson 1)
Creating a windwo (0) This is the first of six lessons I am transferring from Astahost for programming in GLUT, and after
the six I hope to make more, I hope you enjoy. QUOTE Hello, I'm starting a series on how to
program in OpenGL using the OpenGL Utility Toolkit, a.k.a. GLUT. I chose GLUT because it is quick
and easy to write, and very easy to learn. In this tutorial I am going to teach you how to create a
basic window which we will build off of in later tutorials. Throughout the tutorial I will leave
notes to let you know what each command does, and how you can modify it to fit....
Installing Glut To Dev
(3) Hello, before I came to Trap17 I had a series of GLUT programming tutorials at astahost. Since then
I have moved here and wanted to continue the series. As I am told I cannot just repost the
tutorials here so I will put them into quotes until I start making new tutorials. I hope everyone
will enjoy the tutorials I bring to this community. Ok to get started. Below are some instructions
on installing GLUT, the tool we will be using to program in my tutorials. This was actually given
to me back when I had a programming site and James deserves full credit for this tuto....
Tutorial: Help About C & C++ Programming Langauge
(1) Help About C & C++ Programming Langauge Prologue I remember the time I
started learning C. It was not too long ago. I liked programming, I always did, but I didn't
know a lot of languages. The only languages I knew were useless, such as Visual Basic, PHP, ASP, and
the basics of Javascript and VBScript. So I decided to learn a real language: C. So I downloaded
some tutorials and started reading. The well known "Hello, world!" program didn't cause any
difficulties, nor did the few programs after it. But then some new word showed up ....
Tutorial: Creating Custom Icons For Devices
Give that device a great icon every time you plug it in! (0) Ok for this tutorial I will use the PSP as an example of the device, this should work for every
device. (THIS WILL NOT HARM ANYTHING AT ALL!) First off, open notepad and type in:
ICON=ICONE.ICO Save that as AUTORUN.inf Now, find a picture you like.. make sure its dimensions
are 16X16 pixels. Put it in the main folder of the device, for example, my psp is located at
F:\, i would type in F:\ to the adress bar and put the picture in that folder, as it is
the folder your computer automatically reads, anyways, put your picture in there and name it: ICO....
Creating A Timer Program
Using Visual Basic 2005 (8) This tutorial will explain how to create a basic timer using Visual Basic Express 2005. If you
don't have it, it's free and you can dowload it from Microsoft's website. All you need
is a few minutes to sit down and read this and a version of Visual Basic. OK, so what will this
timer actually do? Well, you are able to enter a number of minutes and a message, and then click a
button. Once the timer is up, your message pops up and you are reminded! So, basically it's
a little reminder system. I use it to remind me when TV programmes start, when I have to....
Creating A Simple Image Viewer
Using Visual Basic 2005 Express Edition (3) I downloaded Microsoft's Visual Studio Express suite a few months ago, but only recently got
around to installing it. I have been practising with Visual Basic and making some rather basic
programs and utilities, but they contain most of the basic concepts. This tutorial will explain how
to create a basic image viewer, and I will try to explain each step from beginning to end as clear
as I can. To start you will need: Microsoft Visual Studio About 10-20 minutes free time OK,
first open up the Visual Basic part of the Studio. I am using the 2005 Express version, so....
Getting Started With Amfphp And Rias
first steps in creating RIAs (0) AMFPHP in a short way is a library of php files that let u manage in JUST ONE FILE what u would do
in many files like for example queries to mysql. So u can have tons of queries to mysql and all of
them in just ONE FILE! so what is a RIA? a RIA is a Rich Internet Application commonly given
to flash applications, not the animations or presentations we see daily on the internet but very
useful and cool programs made in flash. the fisrt step u need to take is to download the AMFPHP
library directly from its site at www.amfphp.org, in some free hosted sites the latest....
Delete Files And Directories Using Php
following up from creating and writing (7) How To Delete Files and Directories follow up from creating them Hello all and
welcome to my second tutorial involving file management. In my previous tutorial , I explained how
to create, write and read files. In this tutorial I'll explain how to remove the files and
directories you took so long to create. I did not explain last time how to create directories as I
did not know, now I do, you can use the mkdir() function. Now with this tutorial.... Removing
Files Removing files can easily be done with the unlink() function: CODE <? un....
Centered Website With Fixed Width
...begginers lesson... (2) This will be tutorial on how to make a simple website design with fixed width and center position.
This is actually rather simple tutorial, but hopefully it will help others that are new in world of
creating websites. Website will also contain header, content area and footer. First we must do
Wrapper. Wrapper is actually an area of fixed width and will be position into center, so that our
page doesn't fall apart. CODE body{ width:100%; margin:0px; padding:
0px; text-align:center; background:#FFFFFF; } This is actually an IE....
Creating Rollovers With Buttons
Short & simple javascript tutorial that shows you how. (2) Javascript in action can render some very neat visual effects, which can make your website more
appealing, and sometimes even easier to navigate. Among the most common effects are the
'button' effect, and the mouseover effect. The buttons are very common, of course; if
nowhere else, most of us have seen them at the end of forms (Click the 'submit' button to
proceed...). The basic idea is to have a 'depressible' object, which can give you the
illusion that you're 'pressing' it when you click it. The rollover effect causes
something to h....
Creating Your Own Icon
(23) It is easy to create your own icon, just pick a bitmap (.bmp) file and change its extension to .ico.
To do so, open the Windows Explorer, click on the View menu (or Tools in WinMe), click Folder
Options, click View tab, remove the check on the "Hide file extensions for known files types"
option, and then click OK. Select a bitmap file, press F2 key, and then change its extension to
.ico. Have fun learning:)....
Creating Personal Alarm
To remind you something (2) Creating Personal Alarm This personal alarm is very useful to remind you something or anything you
would like it to do. Use Task Scheduler application to create your personal alarm. First, click on
Start -> Settings -> Control Panel -> Scheduled Tasks. Now click on the Add Scheduled Task wizard
in the Task Scheduler folder. Click Next, click the Browse button, and then select your favorite
sound files (WAV/MP3/MIDI). Set the file to open as the task daily. Set it at the top of the hour
every day, open up its advanced properties. On the Schedule tab press the Advance....
Web Programming Tuts For The Beginner
HTML for the beginner (8) Hello and welcome to our lil' web programming session. Here we assume that our students are
complete noovices of web programming. If you havent ever done any web prograqming, then you've
come to the right place. HERE WE GO
-------------------------------------------------------------------------------- HTML TAGS HTML
works in a very simple, very logical, format. It reads like you do, top to bottom, left to right.
That's important to remember. HTML is written with TEXT. What you use to set certain sections
apart as bigger text, smaller text, bold text,....
A Guide To Css And Creating A Stylesheet
(15) Table of Contents: I. Introduction II. Starting your stylesheet --A. Starting syntax with
font-family --B. Defining classes --C. Using classes III. The STYLE tag IV. Comments in CSS V. The
"a" tag VI. A quick list of common attributes VII. Notes --A. Universal classes --B. Grouping --C.
Multiple instances VIII. Finding other attributes IX. Closing I. Introduction Firstly, to begin
using a stylesheet, you must have one. Open up your text editor and save as (something).css. I know
NotePad doesn't need quotes for a stylesheet, but I'm not sure about other progr....
Creating Your Own Php News System
(23) Hello, heres a simple tutorial from a script that I made to power my news system. It is written
withthe PHP coding system and consists of 8 files using a flatfile based system, without MySQL
databases. This should be usefull for those who want a simple little news manager and like to have
simplcity without the fancy date strings and sutff. You can see a demo of it at my site @
http://www.xeek.trap17.com . Let's Start! First let's start with the easy stuff,
making the directory first, first create a main directory to hold everything, call this folder "ne....
Looking for programming, glut, lesson, 4, creating, 3d, objects
|
|
Searching Video's for programming, glut, lesson, 4, creating, 3d, objects
|
advertisement
|
|