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

  • SEARCH
  • Home
  • 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 7435881
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:08:57+00:00 2026-05-29T10:08:57+00:00

So I’ve been running through a tutorial on texture mapping in OpenGL and I’m

  • 0

So I’ve been running through a tutorial on texture mapping in OpenGL and I’m using the function from the tutorial to attempt to map a texture in my own program.

I think I must be missing some necessary calls to something or going horribly wrong somewhere, but at the moment, I’m managing to achieve the black screen effect as per usual.

I’ve ran through this code and to my knowledge I see no reason why i should be getting a blank screen and was hoping anybody around here could spot where I’m going wrong

I’m using SDL just to clarify which I think might have some relevance to the problem maybe:

#include <iostream>
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <GL/glu.h>

void Draw()

{

glTranslatef(320,240,0);
glBegin(GL_QUADS);
glColor3f(1,0,0);

    glTexCoord2f(0,0); glVertex2f(0,0);
    glTexCoord2f(100,0); glVertex2f(100,0);
    glTexCoord2f(100,100); glVertex2f(100,100);
    glTexCoord2f(0,100); glVertex2f(0,100);

glEnd();

glLoadIdentity();

}

void Init(void)

{

SDL_Init(SDL_INIT_EVERYTHING);
SDL_SetVideoMode(640,480,32,SDL_OPENGL);
SDL_WM_SetCaption("Texture Test", NULL);

}

void Set_States(void)

{

glClearColor(0,0,0,0);
glViewport(0, 0, 640, 480);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 0, 480, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

GLuint LoadTextureRAW( const char * filename, int wrap )

{
GLuint texture;
int width, height;
BYTE * data;
FILE * file;

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

// allocate buffer
width = 256;
height = 256;
data = (BYTE*)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 mipmap
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                 GL_LINEAR_MIPMAP_NEAREST );
// when texture area is large, bilinear filter the first mipmap
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 mipmaps
gluBuild2DMipmaps( GL_TEXTURE_2D, 3, width, height,
                   GL_RGB, GL_UNSIGNED_BYTE, data );

// free buffer
free( data );

return texture;

}

int main (int argc, char ** argv)

{

GLuint texture;
SDL_Event event;
Init();
Set_States();
bool running = true;
glEnable( GL_TEXTURE_2D );
texture = LoadTextureRAW("texture.raw", 1);
glBindTexture( GL_TEXTURE_2D, texture );

while (running == true)

{

    while (SDL_PollEvent(&event))

    {

        switch (event.type)

        {

            case SDL_QUIT: running = false; break;

        }

        glClear(GL_COLOR_BUFFER_BIT);
        Draw();
        SDL_GL_SwapBuffers();

    }

}

SDL_Quit();
glDeleteTextures( 1, &texture );
return 0;

}
  • 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-05-29T10:08:59+00:00Added an answer on May 29, 2026 at 10:08 am

    Well one problem is that you’re not resetting your model-view matrix each time, so your quad gets quickly translated out of view (assuming it was in view to start with, which I haven’t checked).

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am currently running into a problem where an element is coming back from
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

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.