Archived

This topic is now archived and is closed to further replies.

Al-hhu

2 objects in a scene ... impossible !

Recommended Posts

Al-hhu    122
hi, i can''t create more than 1 object in my application , why ? i introduced 2 function to draw 2 different objects, i call these function in my DrawGL function but when i run the programm i see just 1 object , what can i do ? i want ,too , to create a lens flare effect , is there anyone who explain me how to creat it ? ciao al

Share this post


Link to post
Share on other sites
Al-hhu    122
my source is not very pretty :

void sphere(void)
{
glBindTexture(GL_TEXTURE_2D, texture[1]);
glColor3f(0.0f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 0.4f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glutSolidSphere(2,20,20);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);


}
void cube(void)
{
glBegin(GL_QUADS);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glPolygonMode (8,GL_POLYGON_OFFSET_POINT);
glTexCoord2i(0,0);glVertex3i(+1,+1,+1);
glTexCoord2i(1,0);glVertex3i(-1,+1,+1);
glTexCoord2i(1,1);glVertex3i(-1,-1,+1);
glTexCoord2i(0,1);glVertex3i(+1,-1,+1);

glTexCoord2i(0,0);glVertex3i(-1,-1,+1);
glTexCoord2i(1,0);glVertex3i(+1,-1,+1);
glTexCoord2i(1,1);glVertex3i(+1,+1,+1);
glTexCoord2i(0,1);glVertex3i(-1,+1,+1);

glTexCoord2i(0,0);glVertex3i(+1,-1,-1);
glTexCoord2i(1,0);glVertex3i(+1,-1,+1);
glTexCoord2i(1,1);glVertex3i(+1,+1,+1);
glTexCoord2i(0,1);glVertex3i(+1,+1,-1);

glTexCoord2i(0,0);glVertex3i(-1,-1,-1);
glTexCoord2i(1,0);glVertex3i(-1,-1,+1);
glTexCoord2i(1,1);glVertex3i(-1,+1,+1);
glTexCoord2i(0,1);glVertex3i(-1,+1,-1);

glTexCoord2i(0,0);glVertex3i(-1,+1,-1);
glTexCoord2i(1,0);glVertex3i(+1,+1,-1);
glTexCoord2i(1,1);glVertex3i(+1,+1,+1);
glTexCoord2i(0,1);glVertex3i(-1,+1,+1);

glTexCoord2i(0,0);glVertex3i(-1,-1,+1);
glTexCoord2i(1,0);glVertex3i(+1,-1,+1);
glTexCoord2i(1,1);glVertex3i(+1,-1,-1);
glTexCoord2i(0,1);glVertex3i(-1,-1,-1);

glEnd();
}

// sorry for the next , it is not very "seenable" :

void Draw()
{
int key;
int x1;
int y1;
int z1;

a+= key ;
b+= key ;

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );


glLoadIdentity();
glTranslated(0,0,-z);
glRotated(-2*a,0,1,0);
glRotated(-3*b,1,0,0);

glLightiv(GL_LIGHT0,GL_POSITION,LightPos);


glRotated(a,x1,y1,z1);
glTranslatef(0.0,0.0,-5.0);
sphere();
glTranslatef(0.5,-1.0,-2.0);
cube();

glDisable(GL_LIGHTING);
glBegin(GL_POINTS);
glVertex3iv(LightPos);
glEnd();
glEnable(GL_LIGHTING);
glutSwapBuffers();

}



Share this post


Link to post
Share on other sites
Ched45    122
I don''t know if this is right or not, cos I''m just a newbie, but I always but a :

glPushMatrix()
cube()
glPopMatrix()

glPushMatrix()
sphere()
glPopMatrix()

I could be completely wrong, as I said I''m just a newbie



--Ched--
chris@ched45.com

Share this post


Link to post
Share on other sites
zedzeek    529
ched45 is right u need to prolly want to use the matrix stack also try these changes

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glLightiv(GL_LIGHT0,GL_POSITION,LightPos);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90, (w>h) ? w/h : h/w , 1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(50,50,0, 0,0.1,0, 0,0,1);

//glTranslated(0,0,-z);
//glRotated(-2*a,0,1,0);
//glRotated(-3*b,1,0,0);

glTranslatef(0.0,0.0,-5.0);
sphere();
glTranslatef(0.5,-1.0,-2.0); // withoput pushing + poping this
// translation is added to the above one prolly not what u want
cube();






http://members.xoom.com/myBollux

Share this post


Link to post
Share on other sites
Al-hhu    122
hi,
i''ve introduced the code , but when i start the programm , it bugs ,
i have mixed this code with the 16 th tuts of nehe , i don''t understand why it doesn''t work
ciao
al

Share this post


Link to post
Share on other sites
Phantom Lord    122
void sphere(void)
{
<-------------???
glBindTexture(GL_TEXTURE_2D, texture[1]);
glColor3f(0.0f, 1.0f, 1.0f);
glColor4f(1.0f, 1.0f, 1.0f, 0.4f);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glutSolidSphere(2,20,20); <------------???
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
<--------------???
}
/////////////////////////////////////////////////////////////////

if i am not mistaken then you have a cube on your screne and you are missing the sphere.

I don''t know anything about glut because i simply don''t use it, but if you want to make some polygons in OpenGL shouldn''t you use "glBegin(GL_whatever);" and "glEnd()"?? with OGL statements between them.

If i am not mistaken then this is your problem, but it could be something else because i don''t know if glutSolidSphere does a glBegin/glEnd.

Share this post


Link to post
Share on other sites
Al-hhu    122
euh.. it doesn''t work with popmatrix or a glupespective and gltranslate. i don''t understand
my cube is creat with GL_BEGIN(GL_QUAD) and GL_END but with glutSphere
i don''t think i have to put a GL_BEGIN....
but thanks for your post
ciao

Share this post


Link to post
Share on other sites