|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| OpenGL Texture Mapping: An Introduction |
|
![]() 0311 Member since: 2/15/2005 From: USA |
||||
|
|
||||
| i'm using .net 2002 and running the texture.c sample. the console comes up and so does the window, but the quad is white (not textured)... i have made this work on what i believe to be a .net 2003 machine... does this sound familiar to anyone?? |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| I am having the same same problem. Can some one please answer this one - it will be very helpful. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| I've found this quick tutorial very useful, but on both the machines I have tried this on, the texture coords are mislabled in the diagram. correctly: 0,0 1,0 +--------+ | | | | | | +--------+ 0,1 1,1 this is typical for graphics systems and GUIs, so I think the article is just wrong. great job otherwise. -luke |
||||
|
||||
![]() Morpheus011 Member since: 6/17/2005 From: Raleigh, NC, United States |
||||
|
|
||||
| No, the texcoords in that article are exactly correct. The problem you guys might be experiencing is probably due to something else. I'm thinking either bad winding order, maybe something with your lighting, or maybe your texturing is getting turned off somewhere else in your program. But those are the correct texture coordinates for sure, I've used them a thousand times in a thousand programs. Just think about it, if the first value is your X value, and the second value stands for your Y value, then it totally makes sense if you put the quads bottom left corner at the origin. The bottom left corner would have coordinates (0,0) because it's at origin, the top left would be (0,1), and so on. EDIT: The article should make it clearer that you need to enable texturing with glEnable(GL_TEXTURE_2D); most every other important call is in bold, this one should be too because without it texturing will never happen no matter what your settings are. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| Greetings, I attempted to use this code on Linux (Fedora Core 5) and found several problems. Most of these are things like #include when it should be #include which happens to work on MS because it is not case sensitive. I tried to e-mail the author vandals1@home.com but the e-mail address is bad. Could someone please modify the code in the art or contact the author? I will post it inline below for lack of a better solution. Hope this helps, William William.Deans@gmail.com (Please e-mail me if there are any developments as I will not know to come back to these postings). PS: If anyone else is using Linux they will want to use linker options like -L/usr/X11R6/lib -lGL -lglut -lGLU or they will not be able to produce an executable. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| /* OpenGL Tutor : Texture Copyright 1999 by Nate 'm|d' Miller For non-commercial use only! File -- texture.c Date -- 6/22/99 Author -- Nate 'm|d' Miller Contact -- vandals1@home.com Web -- http://members.home.com/vandals1 This is about as simple of a texture mapping tutorial that you will get. The program loads "texture.tga" and displays it onto a quad. If you want to compile this make sure that you link too the following libraries: opegl32.lib glu32.lib glut32.lib */ #define APP_NAME "OpenGL Tutor : Texture" #include "tga.h" #include #include #include int winW = 640; /* window width */ int winH = 480; /* window height */ /* ============= drawFace ============= Draws a textured face. Take note that the texture vertex must come BEFORE the vertex that it will be assigned too. Texture Coordinate Orrientation (0,1)-------------(1,1) | | | Image | | | | | (0,0)-------------(1,0) */ void drawFace (void) { glEnable (GL_TEXTURE_2D); /* enable texture mapping */ glBindTexture (GL_TEXTURE_2D, 13); /* bind to our texture, has id of 13 */ glBegin (GL_QUADS); glTexCoord2f (0.0f,0.0f); /* lower left corner of image */ glVertex3f (-10.0f, -10.0f, 0.0f); glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */ glVertex3f (10.0f, -10.0f, 0.0f); glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */ glVertex3f (10.0f, 10.0f, 0.0f); glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */ glVertex3f (-10.0f, 10.0f, 0.0f); glEnd (); glDisable (GL_TEXTURE_2D); /* disable texture mapping */ } /* ============= glutDisplay ============= Our display function */ void glutDisplay (void) { if (!winH) return; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity (); glTranslatef (0, 0, -20); /* eye position */ drawFace (); glutSwapBuffers(); } /* ============= glutResize ============= Resize function. Called when our window is created and resized. */ void glutResize (int w, int h) { winW = w; winH = h; glViewport (0, 0, winW, winH); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluPerspective (90, winW / winH, 1, 9999); glutPostRedisplay (); } /* ============= glutKeyboard ============= Keyboard handler. */ void glutKeyboard (unsigned char key, int x, int y) { switch (key) { /* exit the program */ case 27: case 'q': case 'Q': exit (1); break; } } /* ============= glInit ============= Sets up some OpenGL states and loads image. */ void glInit (void) { glEnable (GL_DEPTH_TEST); glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); if (!loadTGA ("texture.tga", 13)) printf ("texture.tga not found!\n"); } int main (int argc, char ** argv) { glutInit( &argc, argv ); glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize (winW,winH); glutCreateWindow (APP_NAME); glutKeyboardFunc (glutKeyboard); glutDisplayFunc (glutDisplay); glutReshapeFunc (glutResize); glInit (); glutMainLoop(); // we never return... } |
||||
|
||||
![]() DursoFranco Member since: 9/28/2008 From: Verbania |
||||
|
|
||||
| Hello. i am new and i have a question yet. How a can bind a a specific level of a dds texture to my mesh in opengl. I have found a lot of example that load a dds,but they bind always the first level. Thanks |
||||
|
||||
![]() mgrenier Member since: 3/6/2009 From: North Bay, Canada |
||||
|
|
||||
| This example worked great for me, but I tried to map a picture of my own (it is a .tga file and 256 x 256 like the sample file) however it will not show up and I am not sure why. Any suggestions? (The only code I change was the file name, and no error is display in the console) |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|