dev.gamez.lv Forum Index dev.gamez.lv
Latvian Game Developers Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 

Tekstuuras

 
dev.gamez.lv Forum Index -> OpenGL
View previous topic :: View next topic  

Kuras tekstuuras ir labaakaas
TGA
28%
 28%  [ 2 ]
JPG
14%
 14%  [ 1 ]
BMP
14%
 14%  [ 1 ]
Cita [ierakstiit forumaa]
42%
 42%  [ 3 ]
Total Votes : 7

Author Message
Angel



Joined: 02 Jan 2005
Posts: 113
Location: Latvija

PostPosted: Thu Jun 02, 2005 7:05 pm    Post subject: Tekstuuras

Man ir viena probleema (jau atkal Very Happy ), kuru nekaadi vienc nevaru atrisinaat.

Eku buus kods:
Code:

/**********************************/
/*   Texture.hpp               */
/**********************************/
#include "../main.h"
#define TGA 1
#define BMP 2


class CTexture{
private:
public:
   CTexture();
   ~CTexture();

   bool Load(char* filename, int type);
   void Delete();

   unsigned int ID;
   int width, height;
   unsigned char *image;
   int type;
};

/********************************/
/*   Texture.cpp               */
/********************************/
bool CTexture::Load(char* filename, int type){

   FILE *fp;
   
   switch(type){

      case BMP:
         {
            BITMAPFILEHEADER fileHeader;
            BITMAPINFOHEADER infoHeader;
            if((fp = fopen(filename,"rb")) == NULL )
               return false;

            fread(&fileHeader,sizeof(fileHeader),1,fp);
            
            fseek(fp,sizeof(fileHeader),SEEK_SET);
            fread(&infoHeader, sizeof(infoHeader),1,fp);

            width = infoHeader.biWidth;
            height = infoHeader.biHeight;
            
            image = (byte *) malloc(width*height*3);
            ZeroMemory(&image,width*height*3);
            
            RGBTRIPLE rgb;
            int j = 0;
            for(int i = 0; i<width*height*3; i++){
               fread(&rgb, sizeof(rgb),1,fp);

               image[j] = rgb.rgbtRed;
               image[j+1]=rgb.rgbtGreen;
               image[j+2]=rgb.rgbtBlue;
               j+=3;

            }

            fclose(fp);

            glGenTextures(1,&ID);
            glBindTexture(GL_TEXTURE_2D, ID);

            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

            glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

            glTexImage2D(GL_TEXTURE_2D, 0,4,width, height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
            gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, image);

            free(image);
         }
         break;
   }
   return true;
}


void CTexture::Delete(){
   if(image){
      delete[] image;
      image = 0;
   }
}

/******************************/
/*   Main.cpp            */
/******************************/

#include "main.h"
//#include "Camera/Camera.h"
//#include "Frustum/Frustum.h"
#include "textures/textures.hpp"

CTexture texture;

void Initialize(){
   // Aditional init stuff
   //camera.Position(0,1,0,      0,0,0,   0,1,0);
   texture.Load("test.bmp",2);
    glEnable(GL_TEXTURE_2D);
}

void DrawGrid(){
   for(float  x=-25;x<25;x++){
      for(float z=-25;z<25;z++){
         glBegin(GL_LINES);
            glVertex3f(x,0,0);
            glVertex3f(x,0,z);

            glVertex3f(0,0,z);
            glVertex3f(x,0,z);
         glEnd();
      }
   }
}

void DrawScene(){
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();

   //camera.Look();
   gluLookAt(0,2,-10,0,0,0,0,1,0);

   DrawGrid();
   glBindTexture(GL_TEXTURE_2D, texture.ID);
   glBegin(GL_QUADS);
      glTexCoord2f(0,0);   glVertex3f(-1,1,0);
      glTexCoord2f(0,1);   glVertex3f(-1,-1,0);
      glTexCoord2f(1,1);   glVertex3f(1,-1,0);
      glTexCoord2f(1,0);   glVertex3f(1,1,0);

   glEnd();

}



Ehh, sorry ka posts ir tik garsh, bet luudzu nedusmojaties, probleema ir patieshaam interesanta
_________________


Last edited by Angel on Fri Jun 03, 2005 12:28 am; edited 1 time in total
Back to top
View user's profile Send e-mail
Vecais_Dumais_Laacis
Guru
Guru


Joined: 29 Jan 2004
Posts: 800

PostPosted: Thu Jun 02, 2005 7:53 pm    Post subject:

probleema nr 1) avatars konkreeti izmeeros nerullee
2) ar opengl neesmu straadaajis bet cik no ogres noprotu ir taksh devil libraarijs http://openil.sourceforge.net/ kursh bilzhu formaatu probleemas atrisina

par tekstuuru labumu - domaaju ka bmp viennoziimigi nee
dds/tga/jpeg taadaa arii seciibaa (hvz par opengl un dds)
_________________
...un ja bites buutu laachi...


Last edited by Vecais_Dumais_Laacis on Thu Jun 02, 2005 7:56 pm; edited 1 time in total
Back to top
View user's profile
s1
Guest





PostPosted: Thu Jun 02, 2005 7:53 pm    Post subject:

Kā izpaužas dzīvē šī problēma?
Back to top
Angel



Joined: 02 Jan 2005
Posts: 113
Location: Latvija

PostPosted: Thu Jun 02, 2005 8:30 pm    Post subject:

Crying or Very sad textuuras vnk NAV!!! Crying or Very sad Dari ko gribi, bet nav iespeejams ieraudzzit textuuru
_________________


Last edited by Angel on Fri Jun 03, 2005 12:28 am; edited 1 time in total
Back to top
View user's profile Send e-mail
anggelus



Joined: 23 Feb 2005
Posts: 383
Location: Rīga (LV)

PostPosted: Thu Jun 02, 2005 9:33 pm    Post subject:

formāti: labākais DDS, tad tga un pēc tam pārējie.

Pamēģini pirms glBindTexture(GL_TEXTURE_2D, texture.ID);
pielikt glEnable(GL_TEXTURE_2D);, ja tas nedarbojas, tad ar BMP ielādi kaut kas nav kārtībā, ar BMP neesmu darbojies tāpēc par to neko nevaru pateikt.
_________________
No comprendo lo que dice.
Back to top
View user's profile Send e-mail
anggelus



Joined: 23 Feb 2005
Posts: 383
Location: Rīga (LV)

PostPosted: Thu Jun 02, 2005 10:21 pm    Post subject:

Es domāju, ka šis neder:
Code:

            glTexImage2D(GL_TEXTURE_2D, 0,4,width, height,0,GL_RGB,GL_UNSIGNED_BYTE,image);
            gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, image);


Lieto vai nu vienu vai otru, un kāpēc tev gluBuild2DMipmaps otrais parametrs ir 3?

nodzēs to glTexImage2D rindiņu un atstāj tikai gluBuild2DMipmaps:
Code:

gluBuild2DMipmaps (GL_TEXTURE_2D, GL_RGB8, width,
            height, GL_RGB, GL_UNSIGNED_BYTE,
            pixels);

_________________
No comprendo lo que dice.
Back to top
View user's profile Send e-mail
Angel



Joined: 02 Jan 2005
Posts: 113
Location: Latvija

PostPosted: Thu Jun 02, 2005 11:58 pm    Post subject:

Khm, khm....
Tagad mans koods izstaas peec kkaadas modernaas gleznas, kur izmantotas zaljaa, zilaa un melnaa kraasa... Embarassed
Es tekstuuru ielaadi tieshaa veidaa aizstaaju ar glaux bmp ielaadi no nehe 6 tutoriaala
Quote:
http://nehe.gamedev.net/data/lessons/vc/lesson06.zip


Bet taa pat nekaa, liekas, ka tekstuuras man vispaar nespiid............ Sad
aaa un veel es meeginaaju targa bildes (tga) un sanaaca tieshi tas pac.... nekas Wink
_________________
Back to top
View user's profile Send e-mail
GiGa
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 25 Sep 2003
Posts: 887

PostPosted: Fri Jun 03, 2005 11:59 am    Post subject:

Es kaut kaa nesaprotu sho dalju:
Code:

void DrawGrid(){
   for(float  x=-25;x<25;x++){
      for(float z=-25;z<25;z++){
         glBegin(GL_LINES);
            glVertex3f(x,0,0);
            glVertex3f(x,0,z);

            glVertex3f(0,0,z);
            glVertex3f(x,0,z);
         glEnd();
      }
   }
}

void DrawScene(){
   glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();

   //camera.Look();
   gluLookAt(0,2,-10,0,0,0,0,1,0);

   DrawGrid();
   glBindTexture(GL_TEXTURE_2D, texture.ID);
   glBegin(GL_QUADS);
      glTexCoord2f(0,0);   glVertex3f(-1,1,0);
      glTexCoord2f(0,1);   glVertex3f(-1,-1,0);
      glTexCoord2f(1,1);   glVertex3f(1,-1,0);
      glTexCoord2f(1,0);   glVertex3f(1,1,0);
   glEnd();
}

kad tiek ziimeets DrawGrid textuuras ir izsleegtas? Un peec tam taas netiek iesleegtas? Pameegjini glEnable(GL_TEXTURE_2D); pirms glBegin(GL_QUADS); un glDisable(GL_TEXTURE_2D); pirms DrawGrid();
_________________
Back to top
View user's profile Send e-mail
Angel



Joined: 02 Jan 2005
Posts: 113
Location: Latvija

PostPosted: Fri Jun 03, 2005 1:01 pm    Post subject:

pie initialize jau bija glEnable(GL_TEXTURE_2D);
Code:

void Initialize(){
   // Aditional init stuff
   //camera.Position(0,1,0,      0,0,0,   0,1,0);
   texture.Load("test.bmp",2);
    glEnable(GL_TEXTURE_2D);
}


Bet izmantojot arii tavu variantu nekas nemainaas...
_________________
Back to top
View user's profile Send e-mail
GiGa
Indago Uzvarētājs
Indago Uzvarētājs


Joined: 25 Sep 2003
Posts: 887

PostPosted: Fri Jun 03, 2005 4:15 pm    Post subject:

Ja tieshaam tik ljoti vajag atrast to kljuudu, atmet pilnu kodu uz: giga86@tvnet.lv pameegjinaashu atrast, te tagad gruuti kaut ko ieraudziit.
_________________
Back to top
View user's profile Send e-mail
Angel



Joined: 02 Jan 2005
Posts: 113
Location: Latvija

PostPosted: Fri Jun 03, 2005 11:51 pm    Post subject:

GIGA: Domaaju, ka pac veel pamekleesu vai arii paarrakstiishu visu, ja tomeer nekas nesanaaks, tad izmantoshu tavu piedaavaajumu Wink
_________________
Back to top
View user's profile Send e-mail
Display posts from previous:   
dev.gamez.lv Forum Index -> OpenGL All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group