Jump to content
  • Advertisement
Sign in to follow this  

texturing bricks

This topic is 2950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I amj working on a breakout game using opengl and C. I have used google to find information on texture mapping but I am still confused.I want to apply a texture to each brick in my game.Here is the code I have so far.

GLuint LoadTextureRAW([/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]const[/font][/font][/font][font="Consolas"][font="Consolas"] [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]char[/font][/font][/font][font="Consolas"][font="Consolas"] * filename, [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][font="Consolas"] wrap)


GLuint texture;

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]int[/font][/font][/font][font="Consolas"][font="Consolas"] width,height;

BYTE * data;

FILE * file;


[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"](file==NULL) [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]return[/font][/font][/font][font="Consolas"][font="Consolas"] 0;

width = 256;

height = 256;

[/font][/font][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"]// data = malloc(width * height * 3);







Share this post

Link to post
Share on other sites
With that function, you'll load a texture and save it's id in some GLuint variable - this will be your texture. But in your case, you can only load ".RAW" textures. If you want something else like bmp, jpg, gif etc. you'll have to do it differently.

Anyway, after you load your texture, you simply bind that texture before drawing your quad, like this:

GLuint myTexture = LoadTextureRad("test.raw", TRUE);[/font]

glBindTexture(GL_TEXTURE_2D, myTexture);
glBegin( GL_QUADS );
glTexCoord2d(0, 0, 0, 0); glVertex2d(0, 0, 0, 0);
[/font][font="verdana"]glTexCoord2d(1, 0, 0, 0); glVertex2d(1, 0, 0, 0);
[/font][font="verdana"]glTexCoord2d(1, 0, 1, 0); glVertex2d(1, 0, 1, 0);
[/font][font="verdana"]glTexCoord2d(0, 0, 1, 0); glVertex2d(0, 0, 1, 0);

Share this post

Link to post
Share on other sites
well for some reason this line of code does not work
[font="Consolas"][font="Consolas"]GLuint myTexture = LoadTextureRad([/font][/font][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"][font="Consolas"][color="#a31515"]"test.raw"[/font][/font][/font][font="Consolas"][font="Consolas"],[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]true[/font][/font][/font][font="Consolas"][font="Consolas"]);

see sbove code for reference


Share this post

Link to post
Share on other sites
Why would it work? You're never actually returning the GLuint from the function.

You need to add:

return texture;

Just before the the closing curly brace. You also need to add that malloc() line back in - with an appropriate free() after you're done with the data.

Also - you will have to call the glTexParameteri() family of functions before the texture is considered by OpenGL to be complete. And also pass the actual data to OpenGL using glTexImage2D. Where did you get this code from? This shows a distinct lack of understanding and/or research.

And please, whatever you do - don't call that function every frame. Call it once at startup and then store the variable and use it each frame.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!