just a kid...

During development it is usefull to call glGetError at least once per frame so you can detect some errors you may create (e.g. using incorrect enum as function parameter)
Remember that i only use dev-C++ and it automatically get errors, oh and thac for your critics i have used them all to do a better programing thx :slight_smile:

Originally posted by Rapito:
[quote] During development it is usefull to call glGetError at least once per frame so you can detect some errors you may create (e.g. using incorrect enum as function parameter)
Remember that i only use dev-C++ and it automatically get errors
[/QUOTE]C++ compiler will report you lexical (e.g. incorectly written float number), syntactical (e.g. missing part of for command) and some semantical (e.g. use of pointer where float should be used) errors you can made in your C++ source code.
It will not detect many errors you can made in use of OGL api because all it can validate is if parameters given to OGL function have correct type.
Problem is that many parameters are integer values so only thing it can check is that you are passing integer to that parameter because otherwise it would have extensive knowledge of OGL api and target HW program will be run on. Examples of situations not detected by c++ compiler:

  • [li]From compilers point of view glEnable( GL_FLOAT ) is perfectly correct altrough it is nonsense from view of OGL api.[]You can try to enable feature that is not supported by your card like fifth texture unit on card with four texture units.[]Some functions can not be called in specific situation. For example many functions can not be called between calls to glBegin and glEnd.

Program with previous errors will pass the c++ compilation without problems. It will however behave incorrectly when run.
Many from previous situations should generate error that can be detected by glGetError function. The exception is if parameter passed to function is logically incorrect while it is valid value. Example of this is call glEnable( GL_LIGHT0 | GL_LIGHT1 | GL_LIGHT2 ) which incorrect however because accidentaly resulting value is valid value of GL_LIGHT3 you will get incorrect behaviour however error will be not detected by glGetError

Originally posted by Rapito:
[b] Hey guys i havent been online seen afteryesterday…
i just read your messages and the only thing i have to say is “thank you, for helping me so much”.

i’been in a lot of discussion boards and every single one of them have told me “go to bed, your just a kid”

im very greatfull to you guys, if all people were like this there will be no worries in the world…
anyway i just finished reading the tutorials of openGL and i learned a lil bit of something, i will keep studing openGL until i master it, who knows maybe you works for me someday at my company “Rapito’s” :-p (using OpenGl of course)

i thank you again for everything!!! :slight_smile: [/b]
This is just because most of people here aren’t like the majority :wink:

Check what Komat said about glGetError, but don’t check it only once per frame, get it as much often as you can, at least during development time. glGetError will report GL error but won’t say where it is.

lol

thx jide.

hey guys!, right now im reading the red book, yes ANOTHER tutorial, lol, im looking forward to learn hot make Relistic 3d graphics at least to make a 3 seconds game-like animation, but theres something that is driving me crazy: how do i put a timing animation(i mean, make a charcter[polygon, whatever] walk, then after a few seconds do something else)?

Originally posted by Rapito:
but theres something that is driving me crazy: how do i put a timing animation(i mean, make a charcter[polygon, whatever] walk, then after a few seconds do something else)?
OGL itself has no support for animations so it is up to your applications to move and/or modify objects for each frame.
To implement movement you have described your program will remember which animation is currently playing (say some numeric id of the animation), where program is in the animation (e.g. for rotating animation it will be angle by which the object is currently rotated) and for how long from current time that animation should still play. In each frame it will measure time that pass since last frame and will update the progress of the animation (e.g. increase angle of rotation based on time since last frame or, for some animations, move position of object in desired direction). It will also decrease variable indicating for how long the animation should be still playing by time since last frame. If it finds out that animation should not play anymore it will select another animation, new desired duration and progress within the animation and remember that. After all updates are done it will use id of currently selected animation, progress within that animation and other factors (e.g. position of object) to calculate where the object will be and how it will look and will send that to the OGL for rendering.

thx komat, i already found out another way to do it, using GLUT_ELAPSED_TIME, but i have to master it yet (can’t use it so well tough.

here i’ll post another shape i made tell me how u like it please:
RapitoProject2

this is a car shape i wrote two ways of it in the exe file, please check it out and tell me how u like it and tell me if i have any mistakes. :smiley:

Nice looking car :slight_smile: It must take you long time to make it. For the next model I would suggest that you implement loading of model from external format that can be generated by Blender or other modeling tool because complexity of manual model creation goes up really quick especially once you add texture coordinates.

Now some new comments to your program.

In function RAPRuedas you call the glOrtho function on modelview matrix. This is technically possible however it is suspicious because this function is mostly used to generate projection matrix. Additionally all parameters are the same so the function will likely generate error (detectable by glGetError) because in that case calculation of several parts of the matrix will cause division by zero (see documentation of glOrtho for the generated matrix). In case of error the glOrtho operation is ignored so matrix should be unchanged.

In function RAPManecillas you call glBegin(GL_QUADS) within glBegin()/glEnd() pair. This is error and glGetError would report that. The errornous operation will be ignored so rendering works however it is not correct.

Call to glFlush before the glutSwapBuffers is not necessary. Equivalent of this is done automatically by the swapbuffers.

In keyboard handling function. The if conditions should contain == (comparison) instead of = (assignment). I assume that the if command here is optimalization attempt because currently the frenos_luz variable can contain only two possible values. In reality if condition, especially based on float values, is from performance point significantly worse than the simple float assignment it avoids. Generaly optimalizations should be only attempted at places where it really matters (as determined by profiling tools) and only if the gain from those optimalizations is significant because the price for many optimalizations is complex to read and complex to modify code. Also not everything that looks like optimalization really optimalization is because it may have nonobvious consequences. For example using really big table of precalculated values may be much slower than calculating those values each time because of price of memory access if accessed part of the table is not in the CPU cache.

indeed, it took a while to make da car but it was just an idea i got on school while boring class.
about the texture thing im a lil bit of confused cause i dont know how to texture something i was tring a simple texturing of a block wall paint and i couldn’t texture it i dont understand.

i was looking for a way to make my car like a real one, i mean, reflecting light.

thx for telling me the flush and swapbuffer thing(u cant just trust some tutorials, right?)

and in the if thingi i was looking for this:

if i press the key ‘f’ the red lights pop on
and if i press the key ‘f’ AGAIN the red lights pop off, but couldnt make it so can u help me a lil bit more :stuck_out_tongue: .

and thx a lot for helping me.

[b]
about the texture thing im a lil bit of confused cause i dont know how to texture something i was tring a simple texturing of a block wall paint and i couldn’t texture it i dont understand.

[/b]
What step do you not understand and how you tried to texture that block?

[b]
i was looking for a way to make my car like a real one, i mean, reflecting light.

[/b]
To give the car the reflective look you have to apply texture with content that looks like it may be reflection of the surrounding (depending on ammount of reflexity the surface should have this may not necessary resemble real surrounding, several smooth color patterns may be sufficient) and apply it in way that depends on a normal of car surface and position of the camera.
Probably the simplest way to do that is create cube texture containing the “reflected” images and use automatic generation of texture coordinates (glTexGen* functions) in GL_REFLECTION_MAP mode.

[b]
if i press the key ‘f’ the red lights pop on
and if i press the key ‘f’ AGAIN the red lights pop off, but couldnt make it

[/b]

If you wish to toggle between two states (on/off) it is better to use boolean value like you have done with the F1 key in the specialKeyboard(). In your case you will have for example boolean variable lights_enabled that is toggled in same way the fullscreen variable is. In the RAPCarrito you will then calculate color of the lights using something like

const double frenos_luz = lights_enabled ? 1.0 : 0.5 ;

This way there is more obvious that there are two states and the logical act of toggling light is separated from determining what color the light should have on rendered image.

to be honest i dont know a thing of texturing i need a step by step texturing class/tutorial.

about the car reflection thing cant be made until i know to texture, but, cant i reflect just iluminaton(lights) besides the environment?

and about the frenos_luz thing i got it working thx :wink: :smiley:

Originally posted by Rapito:
to be honest i dont know a thing of texturing i need a step by step texturing class/tutorial.
You can look at one from nehe tutorials http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06


about the car reflection thing cant be made until i know to texture, but, cant i reflect just iluminaton(lights) besides the environment?

You can use OGL lights to lit your model if you provide vertex normals for it. Then if the object has sufficiently small triangles and lights and its material are set correctly, you can see specular highlights on it.

ok thx komat im going to try them now.

in the meanwhile i will be putting a simple task to everyone in code advanced: put a project or exe file of any of your owns projects in dev-c++

i tried o use ur advice and this is what i get:

#include <GL/openglut.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#define NUMBEROF(x) ((sizeof(x))/(sizeof(x[0])))

static int function_index;
static int slices = 16;
static int stacks = 16;
static double irad = .25;
static double orad = 1.0;
static int depth = 4;
bool fullscreen = false;
bool mouseDown = false;
bool frenos = false;
bool offset = true;
float xrot = 0.0f;
float yrot = 0.0f;
float xdiff = 0.0f;
float ydiff = 0.0f;
double frenos_luz = 0.5;
double luz1 = 0.5;
double luz2 = 0.4;

void RAPCarrito()
{
glBegin(GL_QUADS);

/*BASE*/
 /*Base del carro [frente]*/
glColor3d (0.2,0,0);         glVertex2f (-0.7,0);    
glColor3d (0.4,0,0);         glVertex2f (-0.7,0.2);
glColor3d (0.7,0,0);         glVertex2f (0.7,0.2);
glColor3d (0.9,0,0);         glVertex2f (0.7,0);    
 /*Base del carro [atras]*/
glColor3d (0.2,0,0);         glVertex3f (-0.7,0,-0.5);    
glColor3d (0.4,0,0);         glVertex3f (-0.7,0.2,-0.5);
glColor3d (0.7,0,0);         glVertex3f (0.7,0.2,-0.5);
glColor3d (0.9,0,0);         glVertex3f (0.7,0,-0.5);    
 /*Base del carro [tapa-abajo]*/
glColor3d (0,0,0);           glVertex3f (0.7,0,-0.5);
glColor3d (0.2,0.2,0.2);     glVertex3f (-0.7,0,-0.5); 
glColor3d (0.15,0.15,0.15);  glVertex3f (-0.7,0,-0.0);
glColor3d (0.2,0.2,0.2);     glVertex3f (0.7,0,-0.0); 
 /*Base del carro [tapa-arriba]*/
glColor3d (0.9,0,0);         glVertex3f (0.7,0.2,-0.5);
glColor3d (0.4,0,0);         glVertex3f (-0.7,0.2,-0.5); 
glColor3d (0.4,0,0);         glVertex3f (-0.7,0.2,-0.0);
glColor3d (0.9,0,0);         glVertex3f (0.7,0.2,-0.0);
 /*Base del carro [tapa-lado-izquierdo]*/
glColor3d (0.2,0,0);         glVertex3f (-0.7,0,-0.5);    
glColor3d (0.4,0,0);         glVertex3f (-0.7,0.2,-0.5);
glColor3d (0.7,0,0);         glVertex3f (-0.7,0.2,0);
glColor3d (0.0,0,0);         glVertex3f (-0.7,0,0);
 /*Base del carro [tapa-lado-derecho]*/
glColor3d (0.4,0,0);         glVertex3f (0.7,0,-0.5);    
glColor3d (0.7,0,0);         glVertex3f (0.7,0.2,-0.5);
glColor3d (0.7,0,0);         glVertex3f (0.7,0.2,0);
glColor3d (0.4,0,0);         glVertex3f (0.7,0,0);

/*CAPOTA*/
 /*Capota del carro [base-frente]*/
glColor3d (0.4,0,0);         glVertex3f (-0.5,0.2,0);    
glColor3d (0.3,0,0);         glVertex3f (-0.3,0.45,0);
glColor3d (0.7,0,0);         glVertex3f (0.3,0.45,0);
glColor3d (0.8,0,0);         glVertex3f (0.5,0.2,0);
 /*Capota del carro [base-atras]*/
glColor3d (0.4,0,0);         glVertex3f (-0.5,0.2,-0.5);    
glColor3d (0.3,0,0);         glVertex3f (-0.3,0.45,-0.5);
glColor3d (0.7,0,0);         glVertex3f (0.3,0.45,-0.5);
glColor3d (0.8,0,0);         glVertex3f (0.5,0.2,-0.5);
 /*Capota del carro [tapa-arriba]*/
glColor3d (0.4,0,0);         glVertex3f (-0.3,0.45,0);    
glColor3d (0.3,0,0);         glVertex3f (-0.3,0.45,-0.5);
glColor3d (0.7,0,0);         glVertex3f (0.3,0.45,-0.5);
glColor3d (0.8,0,0);         glVertex3f (0.3,0.45,0);
 /*Capota del carro [tapa-lados-izquierda]*/
glColor3d (0.5,0,0);         glVertex3f (-0.5,0.2,0);    
glColor3d (0.5,0,0);         glVertex3f (-0.5,0.2,-0.5);
glColor3d (0.3,0,0);         glVertex3f (-0.3,0.45,-0.5);
glColor3d (0.3,0,0);         glVertex3f (-0.3,0.45,0);
 /*Capota del carro [tapa-lados-derecha]*/
glColor3d (0.7,0,0);         glVertex3f (0.5,0.2,0);    
glColor3d (0.7,0,0);         glVertex3f (0.5,0.2,-0.5);
glColor3d (0.8,0,0);         glVertex3f (0.3,0.45,-0.5);
glColor3d (0.8,0,0);         glVertex3f (0.3,0.45,0);

/*LUCES DE FRENTE*/
  /*LADO DERECHO*/
 /*luces de frente [lado-derecho-ATRAS]*/
glColor3d (0.5,0.4,0);       glVertex3f (0.73,0.15,-0.1);    
glColor3d (0.8,0.8,0);       glVertex3f (0.73,0.15,-0.2);
glColor3d (0.8,0.8,0);       glVertex3f (0.73,0.05,-0.2);
glColor3d (0.8,0.8,0);       glVertex3f (0.73,0.05,-0.1);
 /*luces de frente [lado-derecho-FRENTE]*/
glColor3d (0.5,0.4,0);       glVertex3f (0.725,0.15,-0.1);    
glColor3d (0.5,0.4,0);       glVertex3f (0.725,0.15,-0.2);
glColor3d (0.5,0.4,0);       glVertex3f (0.725,0.05,-0.2);
glColor3d (1.0,1.0,0);       glVertex3f (0.725,0.05,-0.1);  
 /*luces de frente [lado-derecho-tapa-derecho]*/
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.15,-0.1);    
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.15,-0.1);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.05,-0.1);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.05,-0.1);
 /*luces de frente [lado-derecho-tapa-izquierdo]*/
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.15,-0.2);    
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.15,-0.2);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.05,-0.2);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.05,-0.2);
 /*luces de frente [lado-derecho-tapa-arriba*/
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.15,-0.1);    
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.15,-0.1);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.15,-0.2);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.15,-0.2);         
 /*luces de frente [lado-derecho-tapa-abajo*/
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.05,-0.1);    
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.05,-0.1);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.05,-0.2);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.05,-0.2); 
        
  /*LADO IZQUIERDO*/
 /*luces de frente [lado-derecho-ATRAS]*/
glColor3d (0.5,0.4,0);       glVertex3f (0.73,0.15,-0.3);    
glColor3d (0.8,0.8,0);       glVertex3f (0.73,0.15,-0.4);
glColor3d (0.8,0.8,0);       glVertex3f (0.73,0.05,-0.4);
glColor3d (0.5,0.4,0);       glVertex3f (0.73,0.05,-0.3);
 /*luces de frente [lado-derecho-FRENTE]*/
glColor3d (0.5,0.4,0);       glVertex3f (0.725,0.15,-0.3);    
glColor3d (0.5,0.4,0);       glVertex3f (0.725,0.15,-0.4);
glColor3d (0.5,0.4,0);       glVertex3f (0.725,0.05,-0.4);
glColor3d (1.0,1.0,0);       glVertex3f (0.725,0.05,-0.3);  
 /*luces de frente [lado-derecho-tapa-derecho]*/
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.15,-0.3);    
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.15,-0.3);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.05,-0.3);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.05,-0.3);
 /*luces de frente [lado-derecho-tapa-izquierdo]*/
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.15,-0.4);    
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.15,-0.4);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.05,-0.4);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.05,-0.4);
 /*luces de frente [lado-derecho-tapa-arriba*/
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.15,-0.3);    
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.15,-0.3);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.15,-0.4);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.15,-0.4);         
 /*luces de frente [lado-derecho-tapa-abajo*/
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.05,-0.3);    
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.05,-0.3);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.7,0.05,-0.4);
glColor3d (0.20,0.20,0.20);       glVertex3f (0.725,0.05,-0.4); 

/*LUCES DE ATRAS*/
  /*LADO IZQUIERDO*/
 /*luces de atras [lado-izquierdo-ATRAS]*/
glColor3d (frenos_luz,0,0);       glVertex3f (-0.73,0.15,-0.3);    
glColor3d (frenos_luz,0,0);       glVertex3f (-0.73,0.15,-0.4);
glColor3d (frenos_luz,0,0);       glVertex3f (-0.73,0.05,-0.4);
glColor3d (frenos_luz,0,0);       glVertex3f (-0.73,0.05,-0.3);
 /*luces de atras [lado-izquierdo-FRENTE]*/
glColor3d (frenos_luz,0,0);       glVertex3f (-0.725,0.15,-0.3);    
glColor3d (frenos_luz,0,0);       glVertex3f (-0.725,0.15,-0.4);
glColor3d (frenos_luz,0,0);       glVertex3f (-0.725,0.05,-0.4);
glColor3d (frenos_luz,0,0);       glVertex3f (-0.725,0.05,-0.3);  
 /*luces de atras [lado-izquierdo-tapa-derecho]*/
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.15,-0.3);    
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.15,-0.3);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.05,-0.3);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.05,-0.3);
 /*luces de atras [lado-izquierdo-tapa-izquierdo]*/
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.15,-0.4);    
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.15,-0.4);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.05,-0.4);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.05,-0.4);
 /*luces de atras [lado-izquierdo-tapa-arriba*/
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.15,-0.3);    
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.15,-0.3);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.15,-0.4);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.15,-0.4);         
 /*luces de atras [lado-izquierdo-tapa-abajo*/
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.05,-0.3);    
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.05,-0.3);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.05,-0.4);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.05,-0.4); 

  /*LADO DERECHO*/
 /*luces de atras [lado-derecho-ATRAS]*/
glColor3d (frenos_luz,0,0);       glVertex3f (-0.73,0.15,-0.2);    
glColor3d (frenos_luz,0,0);       glVertex3f (-0.73,0.15,-0.2);
glColor3d (frenos_luz,0,0);       glVertex3f (-0.73,0.05,-0.2);
glColor3d (frenos_luz,0,0);       glVertex3f (-0.73,0.05,-0.1);
 /*luces de atras [lado-derecho-FRENTE]*/
glColor3d (frenos_luz,0,0);       glVertex3f (-0.725,0.15,-0.2);    
glColor3d (frenos_luz,0,0);       glVertex3f (-0.725,0.15,-0.1);
glColor3d (frenos_luz,0,0);       glVertex3f (-0.725,0.05,-0.1);
glColor3d (frenos_luz,0,0);       glVertex3f (-0.725,0.05,-0.2);  
 /*luces de atras [lado-derecho-tapa-derecho]*/
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.15,-0.1);    
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.15,-0.1);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.05,-0.1);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.05,-0.1);
 /*luces de atras [lado-derecho-tapa-izquierdo]*/
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.15,-0.2);    
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.15,-0.2);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.05,-0.2);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.05,-0.2);
 /*luces de atras [lado-derecho-tapa-arriba*/
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.15,-0.1);    
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.15,-0.1);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.15,-0.2);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.15,-0.2);         
 /*luces de atras [lado-derecho-tapa-abajo*/
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.05,-0.1);    
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.05,-0.1);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.7,0.05,-0.2);
glColor3d (0.20,0.20,0.20);       glVertex3f (-0.725,0.05,-0.2);    

glEnd();
}

void RAPRuedas()
{
/RUEDAS/
/1ra RUEDA/
glPushMatrix();
glColor3d (0.20,0.20,0.20);
glOrtho(1,1,1,1,1,1);
glTranslated (-0.3,0,0);
glutSolidTorus(0.08,0.05,15,15);
glColor3d (0.80,0.80,0.80);
glTranslated (0,0,0.03);
glutSolidTorus(0.05,0.05,15,15);
glPopMatrix();

/*2da RUEDA*/
glPushMatrix();
glColor3d (0.20,0.20,0.20);
glOrtho(1,1,1,1,1,1);
glTranslated (0.4,0,0);
glutSolidTorus(0.08,0.05,15,15);
glColor3d (0.80,0.80,0.80);
glTranslated (0,0,0.03);    
glutSolidTorus(0.05,0.05,15,15);
glPopMatrix();

/*3ra RUEDA*/
glPushMatrix();
glColor3d (0.20,0.20,0.20);
glOrtho(1,1,1,1,1,1);
glTranslated (0.4,0,-0.5);
glutSolidTorus(0.08,0.05,15,15);
glColor3d (0.80,0.80,0.80);
glTranslated (0,0,-0.03);    
glutSolidTorus(0.05,0.05,15,15);
glPopMatrix();

/*4ta RUEDA*/
glPushMatrix();
glColor3d (0.20,0.20,0.20);
glOrtho(1,1,1,1,1,1);
glTranslated (-0.3,0,-0.5);
glutSolidTorus(0.08,0.05,15,15);
glColor3d (0.80,0.80,0.80);
glTranslated (0,0,-0.03);    
glutSolidTorus(0.05,0.05,15,15);
glPopMatrix();

}
void RAPMufler()
{
/Mufler/
/Inicio de mufler[hacia abajo]/
glBegin(GL_QUADS);
glColor3f (0.52,0.52,0.52); glVertex3f(-0.2,0,-0.1);
glColor3f (0.52,0.52,0.52); glVertex3f(-0.2,0,-0.2);
glColor3f (0.50,0.50,0.50); glVertex3f(-0.2,-0.06,-0.2);
glColor3f (0.50,0.50,0.50); glVertex3f(-0.2,-0.06,-0.1);
/Mufler[trompa]/
glColor3f (0.42,0.42,0.42); glVertex3f(-0.2,-0.06,-0.2);
glColor3f (0.42,0.42,0.42); glVertex3f(-0.75,-0.06,-0.2);
glColor3f (0.30,0.30,0.30); glVertex3f(-0.75,-0.06,-0.1);
glColor3f (0.30,0.30,0.30); glVertex3f(-0.2,-0.06,-0.1);
/Mufler[trompa-lado-derecho]/
glColor3f (0.32,0.32,0.32); glVertex3f(-0.2,-0.00,-0.2);
glColor3f (0.32,0.32,0.32); glVertex3f(-0.2,-0.06,-0.2);
glColor3f (0.40,0.40,0.40); glVertex3f(-0.75,-0.06,-0.2);
glColor3f (0.40,0.40,0.40); glVertex3f(-0.75,-0.00,-0.2);
/Mufler[trompa-lado-izquierdo]/
glColor3f (0.25,0.25,0.25); glVertex3f(-0.2,-0.00,-0.1);
glColor3f (0.25,0.25,0.25); glVertex3f(-0.2,-0.06,-0.1);
glColor3f (0.40,0.40,0.40); glVertex3f(-0.75,-0.06,-0.1);
glColor3f (0.40,0.40,0.40); glVertex3f(-0.75,-0.00,-0.1);
/Mufler[final de la trompa-arriba]/
glColor3f (0.32,0.32,0.32); glVertex3f(-0.2,-0.0,-0.2);
glColor3f (0.32,0.32,0.32); glVertex3f(-0.2,-0.0,-0.1);
glColor3f (0.50,0.50,0.50); glVertex3f(-0.75,-0.0,-0.1);
glColor3f (0.50,0.50,0.50); glVertex3f(-0.75,-0.0,-0.2);

 glEnd();

}
void RAPVentanas ()
{
/VENTANAS/
/1ra Ventana/
glBegin (GL_QUADS);
glColor3d (0,0,0);
glVertex3f (0.4,0.2,0.001);
glVertex3f (-0.0,0.2,0.001);
glVertex3f (-0.0,0.4,0.001);
glVertex3f (0.25,0.4,0.001);
/2da Ventana/
glVertex3f (-0.4,0.2,0.001);
glVertex3f (-0.05,0.2,0.001);
glVertex3f (-0.05,0.4,0.001);
glVertex3f (-0.25,0.4,0.001);
/3ra Ventana/
glVertex3f (0.4,0.2,-0.51);
glVertex3f (-0.0,0.2,-0.51);
glVertex3f (-0.0,0.4,-0.51);
glVertex3f (0.25,0.4,-0.51);
/4ta Ventana/
glVertex3f (-0.4,0.2,-0.51);
glVertex3f (-0.05,0.2,-0.51);
glVertex3f (-0.05,0.4,-0.51);
glVertex3f (-0.25,0.4,-0.51);
/5ta Ventana/
glVertex3f (0.35,0.4,-0.45);
glVertex3f (0.35,0.4,-0.051);
glVertex3f (0.5,0.22,-0.051);
glVertex3f (0.5,0.22,-0.45);
/6ta Ventana/
glVertex3f (-0.35,0.4,-0.45);
glVertex3f (-0.35,0.4,-0.051);
glVertex3f (-0.475,0.25,-0.051);
glVertex3f (-0.475,0.25,-0.45);

  glEnd();

}

void RAPManecillas()
{
/MANECILLAS/
/Manecilla de Acompañante/
glBegin(GL_QUADS);
glVertex3f (0,0.1,0.001);
glVertex3f (0.15,0.1,0.001);
glVertex3f (0.15,0.15,0.001);
glVertex3f (0,0.15,0.001);
/Manecilla de Acompañante [parte-abrir]/
glColor3f (0.25,0.25,0.25); glVertex3f (0,0.115,0.025);
glColor3f (0.25,0.25,0.25); glVertex3f (0.15,0.115,0.025);
glColor3f (0.50,0.50,0.50); glVertex3f (0.15,0.15,0.001);
glColor3f (0.50,0.50,0.50); glVertex3f (0,0.15,0.001);
/Manecilla de Acompañante/
glBegin(GL_QUADS);
glColor3d (0,0,0);
glVertex3f (0,0.1,-0.501);
glVertex3f (0.15,0.1,-0.501);
glVertex3f (0.15,0.15,-0.501);
glVertex3f (0,0.15,-0.501);
/Manecilla de Acompañante [parte-abrir]/
glColor3f (0.25,0.25,0.25); glVertex3f (0,0.115,-0.525);
glColor3f (0.25,0.25,0.25); glVertex3f (0.15,0.115,-0.525);
glColor3f (0.50,0.50,0.50); glVertex3f (0.15,0.15,-0.501);
glColor3f (0.50,0.50,0.50); glVertex3f (0,0.15,-0.501);

   glEnd();

}
static void shapesPrintf (int row, int col, const char *fmt, …)
{
static char buf[256];
int viewport[4];
void *font = GLUT_BITMAP_9_BY_15;
va_list args;

va_start(args, fmt);
(void) vsprintf (buf, fmt, args);
va_end(args);

glGetIntegerv(GL_VIEWPORT,viewport);

glPushMatrix();
glLoadIdentity();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

    glOrtho(0,viewport[2],0,viewport[3],-1,1);

    glRasterPos2i(
          glutBitmapWidth(font, ' ') * col,
        - glutBitmapHeight(font) * (row+2) + viewport[3]
    );
    glutBitmapString (font, (unsigned char *) buf);

glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

}

/* GLUT callback Handlers */

bool init()
{
glClearColor(0.93f, 0.93f, 0.93f, 0.0f);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glClearDepth(1.0f);

return true;

}

void display()
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

gluLookAt(
	0.0f, 0.0f, 3.0f,
	0.0f, 0.0f, 0.0f,
	0.0f, 1.0f, 0.0f);

glRotatef(xrot,0.5f,0.0f,0.0f);
glRotatef(yrot,0.0f,0.5f,0.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (offset)
{
	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1.0f, 1.0f);
}

glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_LIGHTING);
glPushMatrix();
glTranslated(0,0,0.5);
RAPCarrito();
RAPMufler();
RAPVentanas ();
RAPManecillas();
RAPRuedas();
glPopMatrix();
glDisable(GL_LIGHTING);
shapesPrintf (1, 3, "Se prende las luces de freno al f y se apagan a shift+f.");
shapesPrintf (2, 3, "Este programalo hice yo rapito...");
shapesPrintf (3, 3, "...Si, yo Robert", slices, stacks);
if (offset)
glDisable(GL_POLYGON_OFFSET_FILL);


glFlush();
glutSwapBuffers();

}

void resize(int w, int h)
{
const float ar = (float) w / (float) h;

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if( ar &gt; .5 )
    glFrustum( -ar, ar, -1.0, 1.0, 2.0, 100.0 );
else
    glFrustum( -1.0, 1.0, -1/ar, 1/ar, 2.0, 100.0 );
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;

}

void idle()
{
if (!mouseDown)
{

	yrot += 1.0f;
}

glutPostRedisplay();

}

void keyboard(unsigned char key, int x, int y)
{
switch(key)
{
case 27 :
exit (0); break;

case 'f' :
     if (frenos_luz = 0.5) frenos_luz = 1.0; break;
case 'F' :
     if (frenos_luz = 1.0) frenos_luz = 0.5; break;
 
 
}

}

void specialKeyboard(int key, int x, int y)
{

if (key == GLUT_KEY_F1)
{
	fullscreen = !fullscreen;

	if (fullscreen)
		glutFullScreen();
	else
	{
		glutReshapeWindow(500, 500);
		glutPositionWindow(50, 50);
  }
}

}

void mouseMotion(int x, int y)
{
if (mouseDown)
{
yrot = x - xdiff;
xrot = y + ydiff;

	glutPostRedisplay();
}

}

void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
mouseDown = true;

	xdiff = x - yrot;
	ydiff = -y + xrot;
}
else
	mouseDown = false;

}

const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 5.0f, -5.0f, 5.0f, 0.0f };

const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };

/* Program entry point */

int
main(int argc, char *argv[])
{
glutInitWindowSize(640,480);
glutInitWindowPosition(40,40);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

glutCreateWindow("OpenGLUT Shapes");

glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMotionFunc(mouseMotion);
glutSpecialFunc(specialKeyboard);
glutIdleFunc(idle);

glClearColor(1,1,1,1);

glCullFace(GL_BACK);

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);

glLightfv(GL_LIGHT0, GL_AMBIENT,  light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE,  light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glMaterialfv(GL_FRONT, GL_AMBIENT,   mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE,   mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR,  mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);



glutMainLoop();

return EXIT_SUCCESS;

}

Originally posted by Rapito:
i tried o use ur advice and this is what i get

Please, do not include such long source code directly in the post.

There are two problems. First your car has very low polygon count so specular highlights will not work well on it (try to increase number of parts from which wheels are constructed by using 50 instead of 15 in glutSolidTorus call to see the difference on the wheels).

Second you are not specifying vertex normal using glNormal3* call so last value from rendering of wheels will be used for rest of the mesh so lighting will not work correctly on the rest of the mesh.

but i dont know what is the normal3* for…

Originally posted by Rapito:
but i dont know what is the normal3* for…
By that group of functions you specify vertex normal which is direction perpendicular to object surface in that vertex. The lighting uses it to determine amount of lighting applied to the surface at vertex.
Basically if normal points directly towards the light, diffuse lighting will be at its maximal power while if normal is pointing from the light there will be no diffuse lighting at all. Power of specular lighting depends on direction of normal and position of camera. Exactly how ammount of lighting is calculated is written in Opengl specification in chapter 2.14.1

ok…
and for example how do i make the source of lighting be the /LUCES/?

and for example how do i make the source of lighting be the /LUCES/?
I do not uderstand your question.

You will probably not like the idea, but I think it’s the right way to start: create a 2-d shooter or platform game.
This way you need only:
-rendering simple quads in 2d
-use texturing
-use blending (for some speciall effects)
-depth test (optional)
And you don’t need:
-fog
-lighting
-normal vectors
-complex collision detection and physics
-no 3d models at all!
-only 2d vectors, and these are simple
-no matrix knowledge
-no dot product and cross product knowledge
-no trigonometry

So, making some kind of 2d shooter is a best way of mastering mechanisms like texturing and blending in very short time.

When making a 3d-game you need to strongly understand (and not just know how to compute) dot products, cross products, and most likely multiplying vector by matrix. And this is just the beginning.

When I started programming I was 12 years old, and I was very good at maths, too. However - my thinking was bad. I used to create models by writting instructions that draw them - just like you did. This may work at the beginning - but how would you detect collision between two such cars? You really need to start storing all vertex coordinates in an array.

I strongly recommend you to try 2d game first. Although it sounds less exciting it’s more reasonable. And still you can put some 3d elements in there. for example - platform game can have platforms made of 3-d boxes covered with brick texture. Or 2-d shhoter can have some boxes, barrels, walls etc. Only the characters would have to be 2d.
This way you do not need any modeller, and can make a game way faster.

Think of it.

Hi all…

This topic is very cute yet very very educational…

2D games is not as exciting as 3D games - it is plain and boring. But what k_szczech said is right, and i have to agree! Spend more time on the logic and the usage of OpenGL API. 3D model can be done with modeller such as GMax(Free 3D modeller www.autodesk.com/gmax)..)