简体   繁体   中英

How to add an image file in opengl using Texture?

#include <stdio.h>
#include <glut.h>

void display() {


  glClear(GL_COLOR_BUFFER_BIT);


  int initlist=glGenLists(1);
  glNewList(initlist,GL_COMPILE);


  glEnable(GL_TEXTURE_2D);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  //GLuint texture = loa // load an image file directly as a new OpenGL texture 


  glBindTexture(GL_TEXTURE_2D,texture); 
  glPushMatrix();
  glTranslatef(0,0,0);
  glBegin(GL_POLYGON);




  glEnd();
  glPopMatrix();

  glEndList();

  glFlush();
}

I Don't know how to generate a code of an image location for texture . I want to use an image of a road and intend to use that image as a High Way.But i can't get the image location. How can i get that location and use it to glBindTexture() Function ??

You must pass the image raw data using glTextImage2D , you may load the image using an external library. There are a lot of libraries. I personally like SFML .

Edit: You must use glGenTexture to create a texture and get a "texture location".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM