texturing question

I’m very new to programming, but I learn from example best. I recently downloaded Euphoria and GLFW and using examples from that I’ve been experimenting and reading their tuts/user guides to learn, but they dont cover all topics completely. right now I’ve been working on a cube that rotates with mouse movements, my first challenge was learning to load 2 textures one onto a separate face of, what for now is only 2 sides of a cube. my question is why would one texture overlap the other when it is obviously in front of the overlapping one? so as i rotate it, side number 2 is always on top of side number 1, even though side 2 is further away from the camera.

throw some hints out, or lemme know if you need more info about how I’m coding this or anything else.


Most likely depth testing is off.
In OpenGL speak (I don’t use those tools you mentioned):
Add glEnable(GL_DEPTH_TEST) to your OpenGL initialization routine and make sure you issue
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) each time before you render your scene.
Search the web for the OpenGL Programming Guide redbook.pdf and read that.

hrm, the glEnable(GL_DEPTH_TEST) was missing, but had no effect. I have seen the redbook before, and i read up on it a little more, but i’m unable to find anything in there that resembles my situation. I’ll keep reading it, but I have to go to work for now.

Could still be depth buffer problems.
Check the number of depth bits and the ratio of the zFar to zNear ratio in the projection matrix initialization.
If your zFar/zNear ratio is too big, the depth precision is affected.
Make that ratio as small as possible by shifting zNear out and pull zFar in so that you just don’t clip your model’s coordinates.

Did you allowed the window to do depth testing ? GLFW must provide something like that in the window initialization routine.

if the problem is depth buffering, then I need to learn more. the camera is -10(z) units away from 0,0,0, zmin is at 0, zfar is at 20, the parts of the cube are placed at 0,0,0 I tried doing a negative zmin but it just prevented anything from being displayed. So now i guess i need to learn how to place the parts of the cube at -5(z) and rotate it there, but when i do that it rotates it around the 0,0,0 axis so, i cant get a proper angled view before the cube leaves the screen. so looks like i still have lots to learn. still any tips would help, thx for the info so far though.

If I may make a friendly suggestion, I would recommend using GLUT while learning OpenGL. It’s a very thin API that handles basic window creation and input, and it’s darn near impossible to botch it up. Whereas with more complex APIs you may be wasting time battling the the details of the API rather than learning OpenGL.

On top of its simplicity, there are literally thousands of ready-to-build demos written using GLUT (including a textured cube :wink: ). I’d start off with the stuff that works.


theophage post your entire code please.

sorry it took so long to get back

here it is

include msgbox.e
include C:\EUPHORIA\GLFW\Euphoria\gl\gl.e
include C:\EUPHORIA\GLFW\Euphoria\gl\glu.e
include C:\EUPHORIA\GLFW\Euphoria\gl\glfw.e

atom t1, t0, fps, texidone, texidtwo --, texidthree, texidfour, texidfive, texidsix
integer running, frames, width, height, x, y
sequence titlestr, pos, lptex
frames = 0
t0 = glfwGetTime()
lptex = ({0, 0})

---------- setup window

procedure setupwindow()
	running = glfwInit()
	if not(glfwOpenWindow(1280, 1024, 0,0,0,0, 0,0, GLFW_FULLSCREEN)) then
		running = message_box("unable to open an opengl window.", "Error", MB_ICONERROR)
	end if
end procedure

---------- setup textures

procedure setuptexture()
	lptex[1] = allocate(4)
	lptex[2] = allocate(4)
	glGenTextures(1, lptex[1])
	texidone = peek4u(lptex[1])
	glBindTexture(GL_TEXTURE_2D, texidone)
	if not(glfwLoadTexture2D("imgs\\one.tga", GLFW_ORIGIN_UL_BIT)) then
		running = message_box("Unable to Open imgs\\one.tga.", "Error", MB_ICONERROR)
	end if
	glGenTextures(1, lptex[2])
	texidtwo = peek4u(lptex[2])
	glBindTexture(GL_TEXTURE_2D, texidtwo)
	if not(glfwLoadTexture2D("imgs\	wo.tga", GLFW_ORIGIN_UL_BIT)) then
		running = message_box("Unable to Open imgs\	wo.tga.", "Error", MB_ICONERROR)
	end if
end procedure

---------- call setups


---------- main loop

while running do

	----- determine fps

	t1 = glfwGetTime()
	if (t1-t0) > 1.0 then
		fps = frames / (t1 - t0)
		frames = 0
		t0 = t1
		titlestr = sprintf("FPS: %.1f", {fps})
	end if

	----- get mouse position

	pos = glfwGetMousePos()
	x = pos[1]
	y = pos[2]

	----- determine actual screen size

	pos = glfwGetWindowSize()
	width = pos[1]
	height = pos[2]
	if height <= 0 then
		height = 1
	end if
	glViewport(0, 0, width, height)

	----- clear buffer

	glClearColor(0, 0, 0, 0)

	----- setup viewing angles

	gluPerspective(65, width / height, 0.0, 10.0)
	gluLookAt({0.0,  0.0, -10.0},	-- Eye-position
			  {0.0, 0.0, 0.0},	-- View-point
			  {0.0,  1.0,   0.0})	-- Up-vector

	----- Draw a textured quad
	glTranslatef(({0, 0, 5}))
	glRotatef(0.05 * x, {0.0, 1.0, 0.0})
	glRotatef(0.05 * y, {1.0, 0.0, 0.0})

	glBindTexture(GL_TEXTURE_2D, texidtwo)

		glTexCoord2f({1, 0})
		glVertex3f({1, 1, 0})

		glTexCoord2f({0, 0})
		glVertex3f({1, 1, 2})

		glTexCoord2f({0, 1})
		glVertex3f({1, -1, 2})

		glTexCoord2f({1, 1})
		glVertex3f({1, -1, 0})


	glBindTexture(GL_TEXTURE_2D, texidone)

		glTexCoord2f({1, 0})
		glVertex3f({-1, 1, 0})

		glTexCoord2f({0, 0})
		glVertex3f({1, 1, 0})

		glTexCoord2f({0, 1})
		glVertex3f({1, -1, 0})

		glTexCoord2f({1, 1})
		glVertex3f({-1, -1, 0})

	----- swap buffer and add frame

	frames += 1

	----- check for key presses and continue

	running = not(glfwGetKey(GLFW_KEY_ESC)) and glfwGetWindowParam(GLFW_OPENED)
end while


Originally posted by theophage:

if not(glfwOpenWindow(1280, 1024, 0,0,0,0,  --> 0 <--  , 0, GLFW_FULLSCREEN))

Zero depth bits means you don’t want a depth buffer. Put 24 or something there so the window manager knows you want a depth buffer. Without depth buffer, depth testing doesn’t work.

And by the way, what language is that?

thx for pointing that out

euphoria, its a free compiler i came across, allows you to make stand alone .exe files you can freely distribute

and it has everything i ever wanted, free free free :wink: just so long i can learn to use gl… just wish qbasic was still the happenin thing :stuck_out_tongue:

yay, it works now

i also had to change glPerspective to:

gluPerspective(65, width / height, 1, 20.0)

or else it still did the same thing just with more flickering, but now its solid.