PDA

View Full Version : سوال: تصویر پس زمینه برای پنجره opengl



mahdi_gl
دوشنبه 29 دی 1393, 18:38 عصر
کد زیر را جهت ترسیم یک میز و قوری نوشتم جهت اضافه کردن یک عکس برای پس زمینه راهنمایی کنید لطفاً
#include<GL/glut.h>

void tableLeg(double thick,double len) // payehaye miz
{
glPushMatrix();
glTranslated(0,len/6.4,0);
glScaled(thick,len,thick);
glutSolidCube(1.8);
glPopMatrix();

}
void table(double topWid, double topThick,double legThick,double legLen) // siniye miz
{
glPushMatrix();
glTranslated(0,legLen,0);
glScaled(topWid, topThick,topWid);
glutSolidCube(1.9);
glPopMatrix();
double dist =0.95* topWid/2.0 - legThick/2.0;
glPushMatrix();
glTranslated(dist,0,dist);
tableLeg(legThick,legLen);
glTranslated(0.0,0.0,-2*dist);
tableLeg(legThick,legLen);
glTranslated(-2*dist,0,2*dist);
tableLeg(legThick,legLen);
glTranslated(0,0,-2*dist);
tableLeg(legThick,legLen);
glPopMatrix();
}

void displaySolid(void)
{

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.33,1.33, -1,1,0.1,100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(2.3,1.3,2.0,0.0,0.25,0.0,0.0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslated(0.4,0,0.4);
table(0.6,0.02,0.02,0.3);
glPopMatrix();
glPushMatrix();
glTranslated(0.2,0.38,0.8);
glRotated(12,0,1,0);
glutSolidTeapot(0.1);


glPopMatrix();


glPushMatrix();
glRotated(90.0,0.0,0.0,1.0);

glPopMatrix();
glPushMatrix();
glRotated(-90.0,1.0,0.0,0.0);

glPopMatrix();



glFlush();
}
int main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB|GLUT_DEPT H);
glutInitWindowSize(1000,700);
glutInitWindowPosition(100,100);
glutCreateWindow("simple shaded scene consisting of a tea pot on a table ");
glutDisplayFunc(displaySolid);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glShadeModel(GL_SMOOTH);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glClearColor(0.1,0.1,0.1,0.0);
glViewport(0,0,640,480);

texture= LoadTexture( "bg.jpg" );

glutMainLoop();
return 0;
}