Sign in to follow this  

Noob at Texture Mapping(Please Help)

Recommended Posts

I was wondering how do you texture map I have read a lot of tutorials about it but how do you actually load the bmp file into the program. The NeHe one had this line if (!load_rgb_image("swirl_256x256.raw", 256, 256, &img)) return false; Now this had the program check to see if the texture called actually existed but what if i want to simplely texture map without checking to see if file exist how to i "tell" the program that i am setting a particular file as texture[0...].

Share this post

Link to post
Share on other sites
You will have to write a loader of your own (or get a library) I think NeHe used GLaux or something which now appears to be defunct.



Sorry I see that isnt useful :p

You have to write a loader to each specific datatype, if you are using raw, it should be a simple case of putting the colour data into memory

Share this post

Link to post
Share on other sites
No its not a problem because this helps in a way, but what i was wondering is after you get the library how do you call the texture

I have the a library for .bmp but i am kind of confused on how to call the texture while using the library is there an exact call such as LoadTexture or CreateTexture or something like that.

Share this post

Link to post
Share on other sites
How do i go about texturing the planet around the Sun
completely ignore i have no texCoordinates or a whole bunch of other things
just PLEASE tell me how i would load a .bmp file and map it around the planet
(i know the coordinates and the other things i just need to know how to load the file into the program) PLEASE PLEASE HELP THANKS IN ADVANCE

GLuint texture_index[1];
float idleSun=0.0;
float idleJupitar=0.0;

void init(void){
GLfloat mat_specular[]= {1.0, 1.0, 1.0, 1.0};
GLfloat mat_shininess[]= {3.0};

GLfloat light_position0[]= {0.0, 0.0, 0.0, 1.0};

GLfloat model_ambient[]= {1.0, 0.42, 0.42, 0.42, 1.0};

GLfloat white_light[]= {1.0, 1.0, 1.0, 1.0};
GLfloat red_light[]= {1.0, 0.0, 0.0, 1.0};
GLfloat orange_light[]={1.0,0.5, 0.0, 1.0};
GLfloat yellow_light[]={1.0, 1.0, 0.0, 1.0};
GLfloat green_light[]= {0.0, 1.0, 0.0, 1.0};
GLfloat blue_light[]= {0.0, 0.0, 1.0, 0.0};
GLfloat violet_light[]={0.5, 0.0, 1.0, 1.0};
GLfloat cyan_light[]={0.0, 1.0, 1.0};
GLfloat magenta_light[]={1.0, 0.0, 1.0};

glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);

glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, orange_light);
glLightfv(GL_LIGHT0, GL_SPECULAR, orange_light);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, texture_index);
glClearColor(0.0, 0.0, 0.0, 1.0);
gluOrtho2D(0.0, 500, 0.0, 500);

void display(void){
double r;
int lats;
int longs;
int i, j;

glRotatef(idleSun, 0.0, 1.0, 0.0);
glutSolidSphere(1.5, 1000, 1000);

glColor3f(1.0, 0.0, 0.0);
glTranslatef (1.6, 0.0, 0.0);
glRotatef(idleJupitar, 0.0, 1.0, 0.0);

for(i = 0; i <= 100; i++) {
double lat0 = M_PI * (-0.5 + (double) (i - 1) / 100);
double z0 = sin(lat0);
double zr0 = cos(lat0);
double lat1 = M_PI * (-0.5 + (double) i / lats);
double z1 = sin(lat1);
double zr1 = cos(lat1);

for(j = 0; j <= 100; j++) {
double lng = 2 * M_PI * (double) (j - 1) / 100;
double x = cos(lng);
double y = sin(lng);

glNormal3f(x * zr0, y * zr0, z0);
glVertex3f((0.11292*x * zr0), (0.11292*y * zr0), (0.11292*z0));
glNormal3f(x * zr1, y * zr1, z1);
glVertex3f((0.11292*x * zr1), (0.11292*y * zr1), (0.11292*z1));

void reshape(int w, int h)
glViewport(0, 0, w, h);
glLoadIdentity ();
gluPerspective(45.0, (GLfloat)w/(GLfloat)h, 0.1, 100.0);
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);

void keyboard (unsigned char key, int x, int y){
switch (key) {
case 27:
exit (0);

int main (int argc, char** argv)
glutInit( &argc, argv );
glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE );
glutCreateWindow ( "3D Programming 2" );
glutFullScreen ();

glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutMainLoop ();

Share this post

Link to post
Share on other sites

#include <stdio.h>
#include <stdlib.h>

void readbmp( const char *spath, int &w, int &h, unsigned char *&dat )
unsigned char bmi[54];
FILE *f0 = fopen( spath, "rb" );
fread( bmi, 1, 54, f0 );
w = *((int*) &bmi[18]);
h = *((int*) &bmi[22]);
dat = (unsigned char*) malloc( (w*3+3)/4*4 * h );
fread( dat, (w*3+3)/4*4, h, f0 );

void main()
int w, h;
unsigned char *dat;
readbmp( "aaa.bmp", w, h, dat );

BMP contains more than a dozen different image formats. The above program can only read one of them with no error checks. And, you must give it a uncompressed 24 bits bmp file and it must be ran on PC. Is it simply enough?

PS: the data is arranged in BGR format with 4-byte row alignment.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this