Texture mapping - Opengl

Hi,

I have started to explore Opengl and I’m facing a problem with texture mapping. I have created a simple program just to see how texture mapping is working(and then I will hopefully create a solar system with texture on planets) and then having the lines of code below I getting the folowing errors

GLubyte rgb = {255, 255, 255, 0, 0, 0, 0, 0, 0, 255, 255,255};

glTexImage2D(GL_TEXTURE_2D, 0, 3, teximageWidth,teximageHeight,0, GL_RGB, GL_UNSIGNED_BYTE, rgb);

Error 1 too many initializers
Error 2’glTexImage2D’ : cannot convert parameter 9 from ‘GLubyte’ to ‘const GLvoid *’

The error 1 is for the rgb and error 2 for the glTexImage2D. I don’t know if you want any other code or all the code if you want just tell me…

Thanks

Make rgb an array. Second error even says it’s not an array, but of GLubyte type.

I have make it an array…but I think I have bigger errors now which I don’t understand them :slight_smile:

Error 1 error LNK2019: unresolved external symbol “unsigned char * __cdecl TextureLoadBitmap(char *,int *,int *)” (?TextureLoadBitmap@@YAPAEPADPAH1@Z) referenced in function “void __cdecl myinit(void)” (?myinit@@YAXXZ)

Error 2 fatal error LNK1120: 1 unresolved externals

Looks like you only included the header file for TextureLoadBitmap in your project. Try including the source file and/or linking with a library that implements it.

N.

I’m sorry but I don’t understand you well. Can you explain me in more details please.

Thanks

If you receive an error code that you don’t understand, the best way to solve it is by doing a google search for the error code or check the msdn documentation.

An unresolved symbol means that you have provided a function ( most likely in a header file like texture.h) but you didn’t provide a definition/implementation for it (this should be in your texture.cpp or texture.c file).

Make sure that you included the source file for compilation in the project or that you linked to a dll file that implements the
TextureLoadBitmap function.

N.

I understand, you mean to have all the classes (glut.h…) in the include folder of the visual studio. I have them…Ok this is my code…I may have some unnecessary things is ok…

#include <GL/glut.h>
#include <stdio.h>
#include <windows.h>

int y=500;
int x=500;

GLubyte rgb[12] = {255, 255, 255, 0, 0, 0, 0, 0, 0, 255, 255, 255};
GLubyte* TextureLoadBitmap(char* filename, int *w, int *h);
int teximageWidth = 2, teximageHeight = 2;
GLubyte *teximage;

void display(void){

glEnable(GL_TEXTURE_2D);
glTexImage2D(GL_TEXTURE_2D, 0, 3, teximageWidth,teximageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, rgb);
glBegin(GL_POLYGON);
	glTexCoord2f(0.0, 0.0); glVertex2f(0,0);
	glTexCoord2f(1.0, 0.0); glVertex2f(1,0);
	glTexCoord2f(1.0, 1.0); glVertex2f(0,1);
	glTexCoord2f(0.0, 1.0); glVertex2f(1,1);
glEnd();
glDisable(GL_TEXTURE_2D);

glEnable(GL_TEXTURE);
	glTexImage2D(GL_TEXTURE_2D, 0, 3,teximageWidth, teximageHeight, 0,GL_RGB, GL_UNSIGNED_BYTE, teximage);
glDisable(GL_TEXTURE);

}

void myinit()
{
teximage = TextureLoadBitmap(“test.bmp”,&teximageWidth, &teximageHeight);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);

}

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(y,x);
glutCreateWindow(“TEXTURE”);
glEnableClientState(GL_VERTEX_ARRAY);
myinit();
glutDisplayFunc(display);
glEnable(GL_DEPTH_TEST);
glutMainLoop();
}

There’s just too much wrong with this code:

glutInitWindowSize(y,x); -> why not (x,y) unless you have some weird coordinate system?

glEnableClientState(GL_VERTEX_ARRAY); -> why?

glEnable(GL_DEPTH_TEST); -> you never clear it…

GLubyte* TextureLoadBitmap(char* filename, int *w, int *h); -> you didn’t implement it, you can’t expect the application to magically produce an image object just because you wrote this line of code.

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); -> GL_TEXTURE_WRAP_T not repeating?

void display(void) -> you never generated an opengl texture, nor did you bind it to the GL_TEXTURE_2D state. Also, you should load a texture only once, not everytime something needs to be drawn on screen.

It’s best to start with some basic OpenGL examples such as these. Good luck! :wink:

N.

I’m very Sorry NiCo :)…

I’m a beginner I just copy paste codes just to see how they work and try to understand them

Thanks

No need to be sorry… I hope you get the hang of it soon.
Happy coding :slight_smile:

N.