View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# [FIXED] Isometric View + Texturing? (OpenGL)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1Jungletoe  Members

Posted 27 November 2011 - 06:18 PM

FIXED, THANKS!
(SOURCE INCLUDED @ LAST POST)

INTRODUCTION

I've begun work on a 3D OpenGL isometric game engine. Lately I've attempted two things:
1) Texturing a Cube with a .BMP
2) Setting up an Isometric View

PROBLEM

I found the code for the isometric view on GameDev.net and the code for the texturing here. When using the two snippets separately, they work. When using them together, they don't and look like like this:

As you can see, it is textured properly, yet it's not isometric. I think this is due to the isometric code messing up the view.

Here is the isometric code that I put in my init() function:

void init()
{
glClearColor(0.0, 0.0, 0.0, 1.0); //RGB + Alpha
glMatrixMode(GL_PROJECTION);
gluPerspective(45, 640 / 480, 1.0, 500.0); //sets camera params
glMatrixMode(GL_MODELVIEW);
SDL_WM_SetCaption( "OpenGL Game", NULL );
glEnable(GL_DEPTH_TEST);

// ISOMETRIC VIEW CODE
glMatrixMode(GL_PROJECTION);
glOrtho(-100.0f, 100.0f, -100.0f, 100.0f, -500.0f, 500.0f);
glMatrixMode(GL_MODELVIEW);
glRotatef(35.264f, 1.0f, 0.0f, 0.0f);
glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);
glScalef(1.0f, 1.0f, -1.0f);

delete image;
}


When I take out the isometric code part it works perfectly, but isn't isometric (this is just some extra coloring stuff I did too, it won't affect the texturing):

CONCLUSION

I need to figure out how to make my objects show up isometrically while also allowing me to use textures. Do any of you know any isometric code that would work to set up an isometric camera? I've tried a couple of codes from different people without success.

### #2Kyall  Members

Posted 27 November 2011 - 07:52 PM

You shouldn't be transforming your geometry like that to achieve an isometric effect. To achieve an isometric effect you only need to set your camera in the correct position and use an isometric projection.

// Set projection transform
glMatrixMode(GL_PROJECTION);
void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);

// Set view transform
glMatrixMode(GL_MODELVIEW);
gluLookAt(GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ);

// When drawing an object or a set of objects
glMatrixMode(GL_MODELVIEW);
glPushMatrix();

-- Use transforms here to set an object or set of objects in the correct position in world space
-- Draw geometry for such here

glPopMatrix();

I say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!

### #3Jungletoe  Members

Posted 28 November 2011 - 10:53 PM

What are the values inside glLookAt(); ?

When I use your code with the supposed inputs:

	// Set projection transform
glMatrixMode(GL_PROJECTION);
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);

// Set view transform
glMatrixMode(GL_MODELVIEW);
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0, 0.0);

It gives me this:

EDIT:
Hell, I'll just post all my source code...

TEXTURED ATTEMPT: (gives me a blank screen)

//*******************************************************************************************************************//
//*******************************************************************************************************************//

#include "SDL.h"
#include "SDL_opengl.h"
#include "GL/glut.h"
#include <iostream>
#include <stdio.h>

const int triangle = 1;
float angle = 0.0;
GLuint _textureId; //The id of the texture

//Makes the image into a texture, and returns the id of the texture
GLuint textureId;
glGenTextures(1, &textureId); //Make room for our texture
glBindTexture(GL_TEXTURE_2D, textureId); //Tell OpenGL which texture to edit
//Map the image to the texture
glTexImage2D(GL_TEXTURE_2D,                //Always GL_TEXTURE_2D
0,                            //0 for now
GL_RGB,                   	//Format OpenGL uses for image
image->width, image->height,  //Width and height
0,                            //The border of the image
GL_RGB, //GL_RGB, because pixels are stored in RGB format
GL_UNSIGNED_BYTE, //GL_UNSIGNED_BYTE, because pixels are stored
//as unsigned numbers
image->pixels);           	//The actual pixel data
return textureId; //Returns the id of the texture
}

void drawCube(float size)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glColor3f(1.0f, 1.0f, 1.0f);

//front face
glColor3f(1.0, 1.0, 1.0);
glVertex3f(size/2, size/2, size/2);		//glTexCoord2f(0.0f, 0.0f);
glVertex3f(-size/2, size/2, size/2);	//glTexCoord2f(1.0f, 0.0f);
glVertex3f(-size/2, -size/2, size/2);	//glTexCoord2f(1.0f, 1.0f);
glVertex3f(size/2, -size/2, size/2);	//glTexCoord2f(0.0f, 1.0f);

//left face
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-size/2, size/2, size/2);
glVertex3f(-size/2, size/2, -size/2);
glVertex3f(-size/2, -size/2, -size/2);
glVertex3f(-size/2, -size/2, size/2);

//back face
glColor3f(1.0, 0.0, 1.0);
glVertex3f(size/2, size/2, -size/2);
glVertex3f(-size/2, size/2, -size/2);
glVertex3f(-size/2, -size/2, -size/2);
glVertex3f(size/2, -size/2, -size/2);

//right face
glColor3f(0.5, 0.5, 0.5);
glVertex3f(size/2, size/2, -size/2);
glVertex3f(size/2, size/2, size/2);
glVertex3f(size/2, -size/2, size/2);
glVertex3f(size/2, -size/2, -size/2);

//top face
glColor3f(1.0, 0.5, 1.0);
glVertex3f(size/2, size/2, size/2);
glVertex3f(-size/2, size/2, size/2);
glVertex3f(-size/2, size/2, -size/2);
glVertex3f(size/2, size/2, -size/2);

//bottom face
glColor3f(1.0, 1.0, 1.0);
glVertex3f(size/2, -size/2, size/2);
glVertex3f(-size/2, -size/2, size/2);
glVertex3f(-size/2, -size/2, -size/2);
glVertex3f(size/2, -size/2, -size/2);
glEnd();
}

void init()
{
// Set projection transform
glMatrixMode(GL_PROJECTION);
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);

// Set view transform
glMatrixMode(GL_MODELVIEW);
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0, 0.0);

delete image;
}

void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

//glTranslatef(0.0, 0.0, -5.0);
//glRotatef(angle, 1.0, 1.0, 1.0);
drawCube(10.0);
}

int main( int agrc, char* args[] )
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen=SDL_SetVideoMode(600,400,32, SDL_SWSURFACE|SDL_OPENGL );
bool running = true;
Uint32 start;
SDL_Event event;
init();

while(running)
{
start=SDL_GetTicks();
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running = false;
break;
}
}
display();
SDL_GL_SwapBuffers();
angle+=0.1;
if(angle > 360)
angle -= 360;
if(1000/30>(SDL_GetTicks()-start))
SDL_Delay(1000/30>(SDL_GetTicks()-start));
}

SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}

NON-TEXTURED ATTEMPT: (gives me picture above)

/* ************************************************************************************************ */
/* ******************************            INCLUDES       	*********************************** */
/* ************************************************************************************************ */

#include "SDL.h"
#include "SDL_opengl.h"
#include "stdio.h"
#include <string>
#include "CubeTypes.h"

const int triangle = 1;
float currentX = 0.0;
float currentY = 0.0;
float currentZ = 0.0;

/* ************************************************************************************************ */
/* *********************                      INIT              *********************************** */
/* ************************************************************************************************ */
void init()
{
/*
glClearColor(0.0, 0.0, 0.0, 1.0); //RGB + Alpha
glMatrixMode(GL_PROJECTION);
gluPerspective(45, 640 / 480, 1.0, 500.0); //sets camera params
glMatrixMode(GL_MODELVIEW);
SDL_WM_SetCaption( "OpenGL Game", NULL );
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5);
*/

// Set projection transform
glMatrixMode(GL_PROJECTION);
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);

// Set view transform
glMatrixMode(GL_MODELVIEW);
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0, 0.0);
}

/* ************************************************************************************************ */
/* *********************                 	DISPLAY            *********************************** */
/* ************************************************************************************************ */

void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

//glTranslatef(0.0, 0.0, -5.0);
//glRotatef( 0.0 , 1.0, 1.0, 1.0);

glMatrixMode(GL_PROJECTION);
glOrtho(-100.0f, 100.0f, -100.0f, 100.0f, -500.0f, 500.0f);
glMatrixMode(GL_MODELVIEW);
glRotatef(35.264f, 1.0f, 0.0f, 0.0f);
glRotatef(-45.0f, 0.0f, 1.0f, 0.0f);
glScalef(1.0f, 1.0f, -1.0f);

//current cube position
//drawSand(currentX, currentY, currentZ);

//drawDirt(1.0, 0.0, 0.0);
drawSand(0.0, 0.0, 0.0);
//drawSand(1.0, 0.0, 1.0);
//drawSand(1.0, 1.0, 1.0);
//drawDirt(2.0, 0.0, 1.0);
//drawDirt(2.0, 0.0, 0.0);

}

/* ************************************************************************************************ */
/* *********************                    MAIN                *********************************** */
/* ************************************************************************************************ */

int main( int agrc, char* args[] )
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen=SDL_SetVideoMode(600,400,32, SDL_SWSURFACE|SDL_OPENGL );
bool running = true;
Uint32 start;
SDL_Event event;
init();

while(running)
{
start=SDL_GetTicks();
if (SDL_PollEvent(&event))
{
if (event.type == SDL_QUIT){
running = false;
}

if (event.type == SDL_KEYDOWN){
SDLKey keyPressed = event.key.keysym.sym;

switch (keyPressed)
{
case SDLK_ESCAPE:
running = false;
break;
}
}
}
display();
SDL_GL_SwapBuffers();
if(1000/30>(SDL_GetTicks()-start))
SDL_Delay(1000/30>(SDL_GetTicks()-start));
}

SDL_Quit();
return 0;
}

### #4Kyall  Members

Posted 28 November 2011 - 11:33 PM

From the looks of things, you're using glLookAt properly, the first 3 values are the world space position of the camera eye, the next three values are the world space position of where the eye is looking, and the last 3 values are an up vector to determine the roll of the camera.
You need to give openGL texture coordinates for each of the vertices as well as position.

http://www.opengl.or.../glTexCoord.xml

I noticed that you had glTexCoord2f commented out. Your texture binding looks fine, also:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri
(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

You can move that code to the loadTexture function if you want, you don't have to set it before drawing if it's already set for the texture you're binding.
I say Code! You say Build! Code! Build! Code! Build! Can I get a woop-woop? Woop! Woop!

### #5Jungletoe  Members

Posted 30 November 2011 - 11:11 PM

I changed the code and got the same result as the "Textured-Attempt" picture above. Here's the code again:



//*******************************************************************************************************************//
//*******************************************************************************************************************//

#include "SDL.h"
#include "SDL_opengl.h"
#include "GL/glut.h"
#include <iostream>
#include <stdio.h>

const int triangle = 1;
float angle = 0.0;
GLuint _textureId; //The id of the texture

//Makes the image into a texture, and returns the id of the texture
GLuint textureId;
glGenTextures(1, &textureId); //Make room for our texture
glBindTexture(GL_TEXTURE_2D, textureId); //Tell OpenGL which texture to edit
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//Map the image to the texture
glTexImage2D(GL_TEXTURE_2D,                //Always GL_TEXTURE_2D
0,                            //0 for now
GL_RGB,                       //Format OpenGL uses for image
image->width, image->height,  //Width and height
0,                            //The border of the image
GL_RGB, //GL_RGB, because pixels are stored in RGB format
GL_UNSIGNED_BYTE, //GL_UNSIGNED_BYTE, because pixels are stored
//as unsigned numbers
image->pixels);               //The actual pixel data
return textureId; //Returns the id of the texture
}

void drawCube(float size)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _textureId);
glColor3f(1.0f, 1.0f, 1.0f);

// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5f, -.5f,  .5f);  // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( .5f, -.5f,  .5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( .5f,  .5f,  .5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5f,  .5f,  .5f);  // Top Left Of The Texture and Quad

// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-.5f, -.5f, -.5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-.5f,  .5f, -.5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( .5f,  .5f, -.5f);  // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( .5f, -.5f, -.5f);  // Bottom Left Of The Texture and Quad

// Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5f,  .5f, -.5f);  // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5f,  .5f,  .5f);  // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( .5f,  .5f,  .5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( .5f,  .5f, -.5f);  // Top Right Of The Texture and Quad

// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f(-.5f, -.5f, -.5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( .5f, -.5f, -.5f);  // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( .5f, -.5f,  .5f);  // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-.5f, -.5f,  .5f);  // Bottom Right Of The Texture and Quad

// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f( .5f, -.5f, -.5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( .5f,  .5f, -.5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( .5f,  .5f,  .5f);  // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( .5f, -.5f,  .5f);  // Bottom Left Of The Texture and Quad

// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5f, -.5f, -.5f);  // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-.5f, -.5f,  .5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-.5f,  .5f,  .5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5f,  .5f, -.5f);  // Top Left Of The Texture and Quad
glEnd();
}

void init()
{
// Set projection transform
glMatrixMode(GL_PROJECTION);
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);

// Set view transform
glMatrixMode(GL_MODELVIEW);
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0., 1.0, 0.0);

delete image;
}

void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

//glTranslatef(0.0, 0.0, -5.0);
//glRotatef(angle, 1.0, 1.0, 1.0);
drawCube(10.0);
}

int main( int agrc, char* args[] )
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen=SDL_SetVideoMode(600,400,32, SDL_SWSURFACE|SDL_OPENGL );
bool running = true;
Uint32 start;
SDL_Event event;
init();

while(running)
{
start=SDL_GetTicks();
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running = false;
break;
}
}
display();
SDL_GL_SwapBuffers();
angle+=0.1;
if(angle > 360)
angle -= 360;
if(1000/30>(SDL_GetTicks()-start))
SDL_Delay(1000/30>(SDL_GetTicks()-start));
}

SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}


And here is the pic of what it does:

I've literally followed every single tutorial for isometric views on the internet and all give the exact same code you gave, so I'm very curious as to why this wont work. I've also tried commenting out various chunks/line of the code to see if it would work but to no success.

Any more ideas? You've been great so far!

### #6Syranide  Members

Posted 01 December 2011 - 04:16 AM

Aren't you setting the modelview matrix to identity every time you render a new frame? It sure seems so to me.

### #7Jungletoe  Members

Posted 01 December 2011 - 08:04 PM

Aren't you setting the modelview matrix to identity every time you render a new frame? It sure seems so to me.

THANK YOU SO MUCH!

I commented out glLoadIdentity and it now gives me this:

I'm still kind of curious as to why it only prints that pyramid-looking shape though... My code hasn't changed from my above post besides commenting out glLoadIdentity.

### #8Jungletoe  Members

Posted 01 December 2011 - 08:51 PM

FIXED

For the sake of helping the community, here is all my source code along with the product. Thanks so much!


//*******************************************************************************************************************//
//*******************************************************************************************************************//

#include "SDL.h"
#include "SDL_opengl.h"
#include "GL/glut.h"
#include <iostream>
#include <stdio.h>

const int triangle = 1;
float angle = 0.0;
GLuint _textureId; //The id of the texture

//Makes the image into a texture, and returns the id of the texture
GLuint textureId;
glGenTextures(1, &textureId); //Make room for our texture
glBindTexture(GL_TEXTURE_2D, textureId); //Tell OpenGL which texture to edit
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//Map the image to the texture
glTexImage2D(GL_TEXTURE_2D,                //Always GL_TEXTURE_2D
0,                            //0 for now
GL_RGB,                   	//Format OpenGL uses for image
image->width, image->height,  //Width and height
0,                            //The border of the image
GL_RGB, //GL_RGB, because pixels are stored in RGB format
GL_UNSIGNED_BYTE, //GL_UNSIGNED_BYTE, because pixels are stored
//as unsigned numbers
image->pixels);           	//The actual pixel data
return textureId; //Returns the id of the texture
}

void drawCube(float size)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, _textureId);
glColor3f(1.0f, 1.0f, 1.0f);

// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5f, -.5f,  .5f);  // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( .5f, -.5f,  .5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( .5f,  .5f,  .5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5f,  .5f,  .5f);  // Top Left Of The Texture and Quad

// Back Face
glTexCoord2f(1.0f, 0.0f); glVertex3f(-.5f, -.5f, -.5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-.5f,  .5f, -.5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( .5f,  .5f, -.5f);  // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( .5f, -.5f, -.5f);  // Bottom Left Of The Texture and Quad

// Top Face
glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5f,  .5f, -.5f);  // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5f,  .5f,  .5f);  // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( .5f,  .5f,  .5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( .5f,  .5f, -.5f);  // Top Right Of The Texture and Quad

// Bottom Face
glTexCoord2f(1.0f, 1.0f); glVertex3f(-.5f, -.5f, -.5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( .5f, -.5f, -.5f);  // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( .5f, -.5f,  .5f);  // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-.5f, -.5f,  .5f);  // Bottom Right Of The Texture and Quad

// Right face
glTexCoord2f(1.0f, 0.0f); glVertex3f( .5f, -.5f, -.5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( .5f,  .5f, -.5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f( .5f,  .5f,  .5f);  // Top Left Of The Texture and Quad
glTexCoord2f(0.0f, 0.0f); glVertex3f( .5f, -.5f,  .5f);  // Bottom Left Of The Texture and Quad

// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-.5f, -.5f, -.5f);  // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f(-.5f, -.5f,  .5f);  // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f(-.5f,  .5f,  .5f);  // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(-.5f,  .5f, -.5f);  // Top Left Of The Texture and Quad
glEnd();
}

void init()
{
// Set projection transform
glMatrixMode(GL_PROJECTION);
//glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
glOrtho(-10.0f, 10.0f, -10.0f, 10.0f, -10.0f, 10.0f);

// Set view transform
glMatrixMode(GL_MODELVIEW);
gluLookAt(1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

delete image;
}

void display(){
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

//glTranslatef(0.0, 0.0, -5.0);
//glRotatef(angle, 1.0, 1.0, 1.0);
drawCube(10.0);
}

int main( int agrc, char* args[] )
{
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Surface* screen=SDL_SetVideoMode(600,400,32, SDL_SWSURFACE|SDL_OPENGL );
bool running = true;
Uint32 start;
SDL_Event event;
init();

while(running)
{
start=SDL_GetTicks();
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
running = false;
break;
}
}
display();
SDL_GL_SwapBuffers();
angle+=0.1;
if(angle > 360)
angle -= 360;
if(1000/30>(SDL_GetTicks()-start))
SDL_Delay(1000/30>(SDL_GetTicks()-start));
}

SDL_FreeSurface(screen);
SDL_Quit();
return 0;}

RESULT:

WARNING: You need the required "vtr.bmp" to make this code work. You can use any size as long as it's a power of two.

What I did wrong:
I changed glOrtho and I got it work now. The values I used previously were wrong.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.