|
Новичок |
Зарегистрирован: 22 янв 2013 00:03 Сообщения: 1
|
Вот я нарисовал доску, загрузил изображения. Помогите расставить их на доску ,я вообще без понятия, единственное, что мне приходит в голову это рисовать по отдельности квадратики то есть 64 штуки без цикла и на них по отдельности налаживать текстуры. Покажите как это можно сделать по легче ,если можно кодом. Код: #include <stdlib.h> #include <glut.h> #include <glaux.h> #include <windows.h>
const int N=8; bool board[N][N]; unsigned int textures[31];
void LoadTextures() { AUX_RGBImageRec *texture1=auxDIBImageLoadA("фигуры\btura.bmp"), *texture2=auxDIBImageLoadA("фигуры\btura.bmp"), *texture3=auxDIBImageLoadA("фигуры\bkon.bmp"), *texture4=auxDIBImageLoadA("фигуры\bkon.bmp"), *texture5=auxDIBImageLoadA("фигуры\blad.bmp"), *texture6=auxDIBImageLoadA("фигуры\blad.bmp"), *texture7=auxDIBImageLoadA("фигуры\bkor.bmp"), *texture8=auxDIBImageLoadA("фигуры\bkorol.bmp"), *texture9=auxDIBImageLoadA("фигуры\blackpeshka.bmp"), *texture10=auxDIBImageLoadA("фигуры\blackpeshka.bmp"), *texture11=auxDIBImageLoadA("фигуры\blackpeshka.bmp"), *texture12=auxDIBImageLoadA("фигуры\blackpeshka.bmp"), *texture13=auxDIBImageLoadA("фигуры\blackpeshka.bmp"), *texture14=auxDIBImageLoadA("фигуры\blackpeshka.bmp"), *texture15=auxDIBImageLoadA("фигуры\blackpeshka.bmp"), *texture16=auxDIBImageLoadA("фигуры\blackpeshka.bmp"), *texture17=auxDIBImageLoadA("фигуры\wtura.bmp"), *texture18=auxDIBImageLoadA("фигуры\wtura.bmp"), *texture19=auxDIBImageLoadA("фигуры\wkon.bmp"), *texture20=auxDIBImageLoadA("фигуры\wkon.bmp"), *texture21=auxDIBImageLoadA("фигуры\wlad.bmp"), *texture22=auxDIBImageLoadA("фигуры\wlad.bmp"), *texture23=auxDIBImageLoadA("фигуры\wkor.bmp"), *texture24=auxDIBImageLoadA("фигуры\wkorol.bmp"), *texture25=auxDIBImageLoadA("фигуры\belpeshka.bmp"), *texture26=auxDIBImageLoadA("фигуры\belpeshka.bmp"), *texture27=auxDIBImageLoadA("фигуры\belpeshka.bmp"), *texture28=auxDIBImageLoadA("фигуры\belpeshka.bmp"), *texture29=auxDIBImageLoadA("фигуры\belpeshka.bmp"), *texture30=auxDIBImageLoadA("фигуры\belpeshka.bmp"), *texture31=auxDIBImageLoadA("фигуры\belpeshka.bmp"), *texture32=auxDIBImageLoadA("фигуры\belpeshka.bmp"); glGenTextures(32,&textures[0]); glBindTexture(GL_TEXTURE_2D,textures[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture1->sizeX,texture1->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture1->data); glBindTexture(GL_TEXTURE_2D,textures[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture2->sizeX,texture2->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture2->data); glBindTexture(GL_TEXTURE_2D,textures[2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture3->sizeX,texture3->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture3->data); glBindTexture(GL_TEXTURE_2D,textures[3]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture4->sizeX,texture4->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture4->data); glBindTexture(GL_TEXTURE_2D,textures[4]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture5->sizeX,texture5->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture5->data); glBindTexture(GL_TEXTURE_2D,textures[5]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture6->sizeX,texture6->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture6->data); glBindTexture(GL_TEXTURE_2D,textures[6]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture7->sizeX,texture7->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture7->data); glBindTexture(GL_TEXTURE_2D,textures[7]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture8->sizeX,texture8->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture8->data); glBindTexture(GL_TEXTURE_2D,textures[8]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture9->sizeX,texture9->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture9->data); glBindTexture(GL_TEXTURE_2D,textures[9]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture10->sizeX,texture10->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture10->data); glBindTexture(GL_TEXTURE_2D,textures[10]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture11->sizeX,texture11->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture11->data); glBindTexture(GL_TEXTURE_2D,textures[11]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture12->sizeX,texture12->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture12->data); glBindTexture(GL_TEXTURE_2D,textures[12]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture13->sizeX,texture13->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture13->data); glBindTexture(GL_TEXTURE_2D,textures[13]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture14->sizeX,texture14->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture14->data); glBindTexture(GL_TEXTURE_2D,textures[14]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture15->sizeX,texture15->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture5->data); glBindTexture(GL_TEXTURE_2D,textures[15]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture16->sizeX,texture16->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture16->data); glBindTexture(GL_TEXTURE_2D,textures[16]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture17->sizeX,texture17->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture17->data); glBindTexture(GL_TEXTURE_2D,textures[17]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture18->sizeX,texture18->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture18->data); glBindTexture(GL_TEXTURE_2D,textures[19]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture20->sizeX,texture20->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture20->data); glBindTexture(GL_TEXTURE_2D,textures[20]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture21->sizeX,texture21->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture21->data); glBindTexture(GL_TEXTURE_2D,textures[21]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture22->sizeX,texture22->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture22->data); glBindTexture(GL_TEXTURE_2D,textures[22]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture23->sizeX,texture23->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture23->data); glBindTexture(GL_TEXTURE_2D,textures[23]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture24->sizeX,texture24->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture24->data); glBindTexture(GL_TEXTURE_2D,textures[24]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture25->sizeX,texture25->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture25->data); glBindTexture(GL_TEXTURE_2D,textures[25]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture26->sizeX,texture26->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture26->data); glBindTexture(GL_TEXTURE_2D,textures[26]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture27->sizeX,texture27->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture27->data); glBindTexture(GL_TEXTURE_2D,textures[27]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture28->sizeX,texture28->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture28->data); glBindTexture(GL_TEXTURE_2D,textures[28]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture29->sizeX,texture29->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture29->data); glBindTexture(GL_TEXTURE_2D,textures[29]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture30->sizeX,texture30->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture30->data); glBindTexture(GL_TEXTURE_2D,textures[30]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture31->sizeX,texture31->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture31->data); glBindTexture(GL_TEXTURE_2D,textures[31]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D,0,3,texture32->sizeX,texture32->sizeY,0, GL_RGB,GL_UNSIGNED_BYTE,texture32->data); } void display() { glClear(GL_COLOR_BUFFER_BIT); const int step=480/N; glBegin(GL_QUADS); for(int i=0;i<N;i++) for(int j=0;j<N;j++){ if((i+j)%2) glColor3f(0.5,0.5,0.5); else glColor3f(0,0,0); const int x=i*step; const int y=j*step; glVertex2f(x,y); glVertex2f(x+step,y); glVertex2f(x+step,y+step); glVertex2f(x,y+step); } glEnd(); glutSwapBuffers(); } void Keyboard(unsigned char key,int x,int y) { if(key=='f') glutReshapeWindow(480,480); } int main(int argc, char **argv) { PlaySound (TEXT ("1.wav"), NULL,SND_ASYNC | SND_LOOP); glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(480,480); glutInitWindowPosition(100,200); glutCreateWindow("Chess"); glClearColor(0,0,0,1.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,480,480,0,-1,1); glutKeyboardFunc(Keyboard); glutDisplayFunc(display); glutFullScreen(); glutMainLoop(); }
|
|