nikel1992 Posted June 3, 2012 Report Posted June 3, 2012 Am de facut reprezentarea unei curti in opengl, am proiectat cladirile prin intermediul matricilor, dar nu stiu sa le texturez tot cu matrici. Exemplu de proiectie.static GLfloat a2[]={ -5.6,0,8.4, -1.4,0,8.4, -1.4,0,19, -5.6,0,19, -5.6,6,8.4, -1.4,6,8.4, -1.4,6,19, -5.6,6,19, }; static GLubyte indices9[]={ 0,1,2,3, 4,5,6,7, 0,1,5,4, 2,3,7,6, 0,4,7,3, 1,2,6,5, };glVertexPointer(3,GL_FLOAT,0,a2); glColor3f(0.8,0,0); glDrawElements(GL_POLYGON,4,GL_UNSIGNED_BYTE,indices9); glDrawElements(GL_POLYGON,4,GL_UNSIGNED_BYTE,&indices9[4]); glDrawElements(GL_POLYGON,4,GL_UNSIGNED_BYTE,&indices9[8]); glDrawElements(GL_POLYGON,4,GL_UNSIGNED_BYTE,&indices9[12]); glDrawElements(GL_POLYGON,4,GL_UNSIGNED_BYTE,&indices9[16]); glDrawElements(GL_POLYGON,4,GL_UNSIGNED_BYTE,&indices9[20]);Daca stie cineva sa lucreze foarte bine si poate sa mai ma ajute, da`ti`mi un pm cu un id de mess.. va rog Quote
noVaLue Posted June 3, 2012 Report Posted June 3, 2012 Cum mi-e lene sa explic, ai aici tot ce-ti trebuie, doar ca trebuia sa cauti mai mult NeHe Productions: Lessons 06 - 10 Quote
nikel1992 Posted June 3, 2012 Author Report Posted June 3, 2012 Nu reusesc sa pun imaginea, am lucrat la ceva, dar totusi nu inteleg codul.Daca stii, te rog da`mi o mana de ajutor.. Quote
noVaLue Posted June 3, 2012 Report Posted June 3, 2012 (edited) Ca sa poti folosi texturi, trebuie sa le 'mapezi'. In ce sens? Pentru fiecare vertex vei mai avea 2 coordonate u si v spre exemplu, care sunt coordonatele texturei. In ce sens? 1 reprezinta intregul, 0.5 inseamna jumate dindistanta intre acele coordonate pentru vertex 1 si coordonatele penru vertex 2 (u, v). De asemenea scalar, poti alege 2, ceea ce va intinde textura de 2 ori.Acum ce intelegi prin mapping. Cand te apuci sa desenezi fetele la palyndromuri, trebuie sa-ti alegi o directie specifica (sensul acelor de ceas, ori opusul). Din moment ce ai acea directie atunci poti incepe sa desenezi textura pe fata care te intereseaza. Sa vad daca mai am vre-un exemplu de asa ceva. Revin cu un edit.Le:// (Am gasit proiectul, cum nu am mai avut timp sa-l termin de acum 2 ani, a ramas undeva la 10% din micul joculet care am incercat sa-l fac, si inca ma amuzam pe atunci sa fac ceva din ceea ce intelegeam).Le:2// Uitandu-ma la exemplul furnizat, folosesti desenatul antiorar, cred ca folosesti si gl_cull_facec++ - Using glDrawElements does not draw my .obj file - Stack Overflowc++ - How to call glDrawElements with static TexCoords and Dynamic Vertices - Stack OverflowSi cateva exemple, din proiect ( Nu zic ca e cel mai bun, e doar o idee ).TextureBMPLoaderint num_texture = -1;int LoadBMP(char *p_filename, size_t deepthSz=4) { int i, j=0; FILE *l_file; unsigned char *l_texture; num_texture++; BITMAPFILEHEADER fileheader; BITMAPINFOHEADER infoheader; RGBTRIPLE rgb; if (p_filename[0] == '\0') return(-1); if((l_file = fopen(p_filename, "rb")) == NULL) return (-1); // Citeste din header bloc fread(&fileheader, sizeof(fileheader), 1, l_file); // Sarim in fisier acolo unde header tag ul se termina fseek(l_file, sizeof(fileheader), SEEK_SET); // Citeste informatiile din header fread(&infoheader, sizeof(infoheader), 1, l_file); // Alocam memorie pentru imagine (width * height * color deep) l_texture = (byte*) malloc(infoheader.biWidth * infoheader.biHeight * deepthSz); // Umplem cu \0 memset(l_texture, 0, infoheader.biWidth * infoheader.biHeight * deepthSz); for (i=0; i < infoheader.biWidth*infoheader.biHeight; i++) { // Citim valorile RGB al fiecarui pixel din fisier fread(&rgb, sizeof(rgb), 1, l_file); l_texture[j+0] = rgb.rgbtRed; // Red l_texture[j+1] = rgb.rgbtGreen; // Green l_texture[j+2] = rgb.rgbtBlue; // Blue // Alpha ( e calculata in modul cel mai simplu al intensitatii luminii. Pentru ceva mai complex ai putea utiliza. L = 0.2126·R + 0.7152·G + 0.0722·B ) // l_texture[j+3] = rgb.rgbtRed*0.2126 + rgb.rgbtGreen*0.7152 + rgb.rgbtBlue*0.0722; // De asemenea se poate implementa pentru fiecare textura, un cod alpha diferit (Be creative) l_texture[j+3] = (rgb.rgbtRed + rgb.rgbtGreen + rgb.rgbtBlue)/3; // Next Pixel j += 4; } // Dupa ce am terminat cu cititul fisierului, inchidem stream fclose(l_file); // Corelam textura si numarul ei glBindTexture(GL_TEXTURE_2D, num_texture); // Setam parametrii la texturi. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // If the u,v coordinates overflow the range 0,1 the image is repeated( that means scalar measures ) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // The magnification function ("linear" produce rezultate mai ingaduitoare) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); // Definim textura (pentru a fi recunoscuta glTexImage2D(GL_TEXTURE_2D, 0, 4, infoheader.biWidth, infoheader.biHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, l_texture); // Cream mipmaps pentru glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); gluBuild2DMipmaps(GL_TEXTURE_2D, 4, infoheader.biWidth, infoheader.biHeight, GL_RGBA, GL_UNSIGNED_BYTE, l_texture); // Eliberam memoria folosita pentru citirea texturii(si va ramane in memorie doar cache texture) free(l_texture); return num_texture;}void setTexture(int texId) { glBindTexture(GL_TEXTURE_2D, texId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);}[COLOR="#DAA520"]static const GLfloat squareTexCoord[] = { 0, 1, 1, 1, 0, 0, 1, 0, };[/COLOR]void tObject::DrawWorld() { for(int i=0; i < Build.noWObjs; i++) { if(Build.World[i].Param.Visible) { glPushMatrix(); for(int j=0; j< Build.World[i].noPolygons; j++) { // Set Texture and Colour glEnable(GL_TEXTURE_2D); setTexture(Build.World[i].Polygon[j].TextureId); glColor3f(Build.World[i].Polygon[j].Colour.x, Build.World[i].Polygon[j].Colour.y, Build.World[i].Polygon[j].Colour.z); [COLOR="#FFD700"]Aici vei introduce texturarea[/COLOR] [COLOR="#00FF00"]glVertexPointer(3,GL_FLOAT,0,a2);[/COLOR] [COLOR="#DAA520"]glEnableClientState(GL_VERTEX_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, squareTexCoord); glEnableClientState(GL_TEXTURE_COORD_ARRAY);[/COLOR] // Draw Polygon [COLOR="#FF0000"]glBegin(GL_POLYGON);[/COLOR] for(int k=0; k<Build.World[i].Polygon[j].noPoints; k++) { [COLOR="#FF0000"]glTexCoord2f(Build.World[i].Polygon[j].Point[k].u, Build.World[i].Polygon[j].Point[k].v); glVertex3f(Build.World[i].Location.x + Build.World[i].Polygon[j].Point[k].x, Build.World[i].Location.y + Build.World[i].Polygon[j].Point[k].y, Build.World[i].Location.z + Build.World[i].Polygon[j].Point[k].z);[/COLOR] [COLOR="#00FF00"]glDrawElements(GL_POLYGON,4,GL_UNSIGNED_BYTE,&indi ces9[4*k]);[/COLOR] } [COLOR="#FF0000"]glEnd();[/COLOR] [COLOR="#FFD700"]Aici vei opri texturarea[/COLOR] // Reset colour to default glColor3f(1.0, 1.0, 1.0); glDisable(GL_TEXTURE_2D); } glPopMatrix(); } }}La sfarsitul documentului vei gasi un exemplu exact, de cum poti face asa ceva. Source code samples: glTexCoordPointer example c/c++PS:// Nu am incercat niciodata aces mod de a textura. Edited June 3, 2012 by noVaLue Quote