Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:20:13+00:00 2026-06-01T23:20:13+00:00

Im trying to create a polygon with texture in opengl using this Nehe Loadraw

  • 0

Im trying to create a polygon with texture in opengl using this Nehe Loadraw

GLuint LoadTextureRAW( const char * filename, int wrap )
{
GLuint texture;
int width, height;
Byte * data;
FILE * file;

// open texture data
file = fopen( "Data/raw.raw", "rb" );
if ( file == NULL ) return 0;

// allocate buffer
width = 256;
height = 256;
data = malloc( width * height * 3 );

// read texture data
fread( data, width * height * 3, 1, file );
fclose( file );

// allocate a texture name
glGenTextures( 1, &texture );

// select our current texture
glBindTexture( GL_TEXTURE_2D, texture );

// select modulate to mix texture with color for shading
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

// when texture area is small, bilinear filter the closest MIP map
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                GL_LINEAR_MIPMAP_NEAREST );
// when texture area is large, bilinear filter the first MIP map
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

// if wrap is true, the texture wraps over at the edges (repeat)
//       ... false, the texture ends at the edges (clamp)
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
                wrap ? GL_REPEAT : GL_CLAMP );
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
                wrap ? GL_REPEAT : GL_CLAMP );

// build our texture MIP maps
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width,
                  height, GL_RGB, GL_UNSIGNED_BYTE, data );

// free buffer
free( data );

return texture;

}

and then create the polygons
texture = LoadTextureRAW( “texture.raw”, TRUE );

glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, texture );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glBegin( GL_POLYGON );
glVertex3f( -42.0f, -42.0f, 0.0f );
glTexCoord2f( 0.0f, 0.0f );
glVertex3f(  42.0f, -42.0f, 0.0f );
glTexCoord2f( 1.0f, 0.0f );
glVertex3f(  42.0f,  42.0f, 0.0f );
glTexCoord2f( 1.0f, 1.0f );
glVertex3f( -42.0f,  42.0f, 0.0f );
glTexCoord2f( 0.0f, 1.0f );
glEnd();

how can i change it to load any size of image not only power of 2 and to create the polygons using the side of the texture instead the coordinates

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:20:14+00:00Added an answer on June 1, 2026 at 11:20 pm

    You’ve asked several different questions.

    • How to load images?

    RAW is not really an “image format” so much as a binary dump of image data. RAW images don’t contain information about how big they are (or what format they are, for that matter). You’re expected to know, via other means, how big it is.

    What you need to do is use a proper image loading library to load a real image format. Some of those are just generic image loaders, but others are designed for integration with OpenGL and can automatically create textures for you.

    • How to load images of arbitrary sizes?

    A proper image loader have APIs to tell you how big the image is (as well as format information).

    Note that OpenGL 2.0 and above supports non-power-of-two images. gluBuild2DMipmaps does not! At least, not correctly. gluBuild2DMipmaps will attempt to scale any non-power-of-two image into a power-of-two one. So you need to use the actual OpenGL calls (GLU is not really part of OpenGL. It sits on top of GL) like glTexImage2D.

    • How to render image with pixel accuracy?

    This answer provides all the information you need for this process.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create a polygon using points in xaml and as per
I am trying to create a colored polygon using GDAL library. I am currently
I am trying to create a polygon in VB6 using the polygon function. I
I'm trying to create a fast 2D point inside polygon algorithm, for use in
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
I'm trying to create imagemaps on an image in wpf using codebehind. See the
im trying to create a overlay view using a ui view and need to
hi I'm trying create chat using node.js I see example in http://chat.nodejs.org/ I have
I'm trying to create an SVG polygon from with Javascript. When I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.