Advertisement

2 objects in a scene ... impossible !

Started by October 30, 2000 11:00 AM
6 comments, last by Al-hhu 24 years ago
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
if you could post your section of the draw code, that would help in debugging the stuff.

NeoGL
Advertisement
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();

}



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
--Ched--chris@ched45.com
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
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
Advertisement
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.
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

This topic is closed to new replies.

Advertisement