Post by axeblade346 on Oct 9, 2010 21:22:20 GMT -5
I am Basicly Using Nehe's 6th and 7th tutorials code and would like to know how I can make it to display different images on each side of the Cube. Where do I State it must use the Next image? and How?
It has been more than 4 years since I last touched C++ OpenGL....
I want to be able later to read the images from one large .PNG file and place it on the Cube according to the values assigned to each image block in the .Png (there is currently a MAX 256 Image Blocks in it , some are still blank) Each Image Block is 16X16 pixels (small)
--I do not need lighting or anything else expect movement of the cube ATM. might need Transparency on Glass and white spots in a Door Later (.PNG file has Transparrency)
So if i say (dont know the correct code yet)
Image(0)=PNG.Start(0,0), PNG,end(16,16)
Image(1)=PNG.Start(0,16), PNG,end(16,32)
.....
Texture(0)=Image(VFront)
Texture(1)=Image(VBack)
The V values will Come From User Input or A text file
it would draw the Cube According to this.
My Code to Date Looks like this -- Multi Images are ' out due to it not working... it takes random images from the folder.
dim xrot# ' x Rotation
dim yrot# ' Y Rotation
dim xspeed# ' X Rotation Speed
dim yspeed# ' Y Rotation Speed
dim z# ' Depth Into The Screen
z# = -10 'sets depth to 5 units in
dim a$ 'for input reading
dim texture (6), handles (1) 'makes 6 Textures
'' Load texture Front face
'texture(0) = LoadTexture ("Data/FF.bmp")
' if texture(0) = 0 then print "Failed to load texture": end: endif
'' Load texture Back face
'texture(1) = LoadTexture ("Data/BF.bmp")
' if texture(1) = 0 then print "Failed to load texture": end: endif
'' Load texture Left face
' texture(2) = LoadTexture ("Data/LF.bmp")
' if texture(2) = 0 then print "Failed to load texture": end: endif
'' Load texture Right face
' texture(3) = LoadTexture ("Data/RF.bmp")
' if texture(3) = 0 then print "Failed to load texture": end: endif
'' Load texture Top face
'texture(4) = LoadTexture ("Data/TF.bmp")
' if texture(4) = 0 then print "Failed to load texture": end: endif
'' Load texture Bottem face
'texture(5) = LoadTexture ("Data/BOF.bmp")
'if texture(5) = 0 then print "Failed to load texture": end: endif
'Load texture Front face
texture(0) = LoadMipmapTexture ("data\nehe.bmp")
if texture(0) = 0 then print "Failed to load texture0": end: endif
' Load texture Back face
texture(1) = LoadMipmapTexture ("data\Crate.bmp")
if texture(1)= 0 then print "Failed to load texture1": end: endif
' Load texture Left face
texture(2) = LoadMipmapTexture ("data\font.bmp")
if texture(2) = 0 then print "Failed to load texture2": end: endif
' Load texture Right face
texture(3) = LoadMipmapTexture ("data\nehe.bmp")
if texture(3) = 0 then print "Failed to load texture3": end: endif
' Load texture Top face
texture(4) = LoadMipmapTexture ("data\nehe.bmp")
if texture(4) = 0 then print "Failed to load texture4":end: endif
' Load texture Bottem face
texture(5) = LoadMipmapTexture ("data\nehe.bmp")
if texture(5) = 0 then print "Failed to load texture5": end: endif
glEnable (GL_TEXTURE_2D)
glEnable (GL_CULL_FACE)
while true
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) ' Clear screen and depth buffer
glLoadIdentity() ' Reset the current modelview matrix
glTranslatef (0.0,0.0,z#) 'set depth
glRotatef(xrot#,1.0,0.0,0.0) 'Sets X for rotation
glRotatef(yrot#,0.0,1.0,0.0) 'Sets Y for rotation
glBegin(GL_QUADS)
' Front face
glBindTexture(GL_TEXTURE_2D, texture(0)) ' Select our Front face texture
glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, 1.0) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, 1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f( 1.0, 1.0, 1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f(-1.0, 1.0, 1.0) ' Top left of the texture and quad
' Back face
glBindTexture(GL_TEXTURE_2D, texture(1))
glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, -1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, 1.0, -1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, 1.0, -1.0) ' Top left of the texture and quad
glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, -1.0) ' Bottom left of the texture and quad
' Top face
glBindTexture(GL_TEXTURE_2D, texture(4))
glTexCoord2f(0.0, 1.0): glVertex3f(-1.0, 1.0, -1.0) ' Top left of the texture and quad
glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, 1.0, 1.0) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, 1.0, 1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f( 1.0, 1.0, -1.0) ' Top right of the texture and quad
' Bottom face
glBindTexture(GL_TEXTURE_2D, texture(5))
glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, -1.0, -1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, -1.0, -1.0) ' Top left of the texture and quad
glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, 1.0) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, 1.0) ' Bottom right of the texture and quad
' Right face
glBindTexture(GL_TEXTURE_2D, texture(3))
glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, -1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f( 1.0, 1.0, -1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, 1.0, 1.0) ' Top left of the texture and quad
glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, 1.0) ' Bottom left of the texture and quad
' Left face
glBindTexture(GL_TEXTURE_2D, texture(2))
glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, -1.0) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, 1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, 1.0, 1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f(-1.0, 1.0, -1.0) ' Top left of the texture and quad
glEnd()
xrot# = xrot# + xspeed#
yrot# = yrot# + yspeed#
SwapBuffers ()
a$ = inkey$()
if a$ = "R" or a$ = "r" then 'resets whole display
xrot#=0
yrot#=0
z# = -10
if a$ = "P" or a$ = "p" then 'resets rotation only
xspeed#=0
yspeed#=0
endif
endif
if ScanKeyDown (VK_PRIOR) then z# = z# - 0.2 endif
if ScanKeyDown (VK_NEXT) then z# = z# + 0.2 endif
if ScanKeyDown (VK_UP) then xspeed# = xspeed# - 0.01 endif
if ScanKeyDown (VK_DOWN) then xspeed# = xspeed# + 0.01 endif
if ScanKeyDown (VK_RIGHT) then yspeed# = yspeed# + 0.01 endif
if ScanKeyDown (VK_LEFT) then yspeed# = yspeed# - 0.01 endif
wend
And to those wondering what I am Gonna use it for.
I want to make a previewer to check out how a certain block looks whith premaid "textures" for Minecraft's terrain.png files (users can edit this files and use it in game , the problem is there is currently no way out of game to see how they look.)
Some else has already a Very nice Image Editor Going and I want to Integrate a Previewer into it. (can it link into a Java app as a small preview window later?) But it uses the games's Skin previewer directly from the website's file.
Standard Terrain.Png Image looks Like.
In game it looks like
And how we are currently thinking of Cheating in using the Game's Skin previewer to view the terrain file (each image is mannauly copy and pasted ATM.)
It Actually looks more like.
The Priewer might help out in a few other OPENGL games too due to it being just cubes at the end of the day.
It has been more than 4 years since I last touched C++ OpenGL....
I want to be able later to read the images from one large .PNG file and place it on the Cube according to the values assigned to each image block in the .Png (there is currently a MAX 256 Image Blocks in it , some are still blank) Each Image Block is 16X16 pixels (small)
--I do not need lighting or anything else expect movement of the cube ATM. might need Transparency on Glass and white spots in a Door Later (.PNG file has Transparrency)
So if i say (dont know the correct code yet)
Image(0)=PNG.Start(0,0), PNG,end(16,16)
Image(1)=PNG.Start(0,16), PNG,end(16,32)
.....
Texture(0)=Image(VFront)
Texture(1)=Image(VBack)
The V values will Come From User Input or A text file
it would draw the Cube According to this.
My Code to Date Looks like this -- Multi Images are ' out due to it not working... it takes random images from the folder.
dim xrot# ' x Rotation
dim yrot# ' Y Rotation
dim xspeed# ' X Rotation Speed
dim yspeed# ' Y Rotation Speed
dim z# ' Depth Into The Screen
z# = -10 'sets depth to 5 units in
dim a$ 'for input reading
dim texture (6), handles (1) 'makes 6 Textures
'' Load texture Front face
'texture(0) = LoadTexture ("Data/FF.bmp")
' if texture(0) = 0 then print "Failed to load texture": end: endif
'' Load texture Back face
'texture(1) = LoadTexture ("Data/BF.bmp")
' if texture(1) = 0 then print "Failed to load texture": end: endif
'' Load texture Left face
' texture(2) = LoadTexture ("Data/LF.bmp")
' if texture(2) = 0 then print "Failed to load texture": end: endif
'' Load texture Right face
' texture(3) = LoadTexture ("Data/RF.bmp")
' if texture(3) = 0 then print "Failed to load texture": end: endif
'' Load texture Top face
'texture(4) = LoadTexture ("Data/TF.bmp")
' if texture(4) = 0 then print "Failed to load texture": end: endif
'' Load texture Bottem face
'texture(5) = LoadTexture ("Data/BOF.bmp")
'if texture(5) = 0 then print "Failed to load texture": end: endif
'Load texture Front face
texture(0) = LoadMipmapTexture ("data\nehe.bmp")
if texture(0) = 0 then print "Failed to load texture0": end: endif
' Load texture Back face
texture(1) = LoadMipmapTexture ("data\Crate.bmp")
if texture(1)= 0 then print "Failed to load texture1": end: endif
' Load texture Left face
texture(2) = LoadMipmapTexture ("data\font.bmp")
if texture(2) = 0 then print "Failed to load texture2": end: endif
' Load texture Right face
texture(3) = LoadMipmapTexture ("data\nehe.bmp")
if texture(3) = 0 then print "Failed to load texture3": end: endif
' Load texture Top face
texture(4) = LoadMipmapTexture ("data\nehe.bmp")
if texture(4) = 0 then print "Failed to load texture4":end: endif
' Load texture Bottem face
texture(5) = LoadMipmapTexture ("data\nehe.bmp")
if texture(5) = 0 then print "Failed to load texture5": end: endif
glEnable (GL_TEXTURE_2D)
glEnable (GL_CULL_FACE)
while true
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) ' Clear screen and depth buffer
glLoadIdentity() ' Reset the current modelview matrix
glTranslatef (0.0,0.0,z#) 'set depth
glRotatef(xrot#,1.0,0.0,0.0) 'Sets X for rotation
glRotatef(yrot#,0.0,1.0,0.0) 'Sets Y for rotation
glBegin(GL_QUADS)
' Front face
glBindTexture(GL_TEXTURE_2D, texture(0)) ' Select our Front face texture
glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, 1.0) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, 1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f( 1.0, 1.0, 1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f(-1.0, 1.0, 1.0) ' Top left of the texture and quad
' Back face
glBindTexture(GL_TEXTURE_2D, texture(1))
glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, -1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, 1.0, -1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, 1.0, -1.0) ' Top left of the texture and quad
glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, -1.0) ' Bottom left of the texture and quad
' Top face
glBindTexture(GL_TEXTURE_2D, texture(4))
glTexCoord2f(0.0, 1.0): glVertex3f(-1.0, 1.0, -1.0) ' Top left of the texture and quad
glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, 1.0, 1.0) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, 1.0, 1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f( 1.0, 1.0, -1.0) ' Top right of the texture and quad
' Bottom face
glBindTexture(GL_TEXTURE_2D, texture(5))
glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, -1.0, -1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, -1.0, -1.0) ' Top left of the texture and quad
glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, 1.0) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, 1.0) ' Bottom right of the texture and quad
' Right face
glBindTexture(GL_TEXTURE_2D, texture(3))
glTexCoord2f(1.0, 0.0): glVertex3f( 1.0, -1.0, -1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f( 1.0, 1.0, -1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f( 1.0, 1.0, 1.0) ' Top left of the texture and quad
glTexCoord2f(0.0, 0.0): glVertex3f( 1.0, -1.0, 1.0) ' Bottom left of the texture and quad
' Left face
glBindTexture(GL_TEXTURE_2D, texture(2))
glTexCoord2f(0.0, 0.0): glVertex3f(-1.0, -1.0, -1.0) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3f(-1.0, -1.0, 1.0) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3f(-1.0, 1.0, 1.0) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3f(-1.0, 1.0, -1.0) ' Top left of the texture and quad
glEnd()
xrot# = xrot# + xspeed#
yrot# = yrot# + yspeed#
SwapBuffers ()
a$ = inkey$()
if a$ = "R" or a$ = "r" then 'resets whole display
xrot#=0
yrot#=0
z# = -10
if a$ = "P" or a$ = "p" then 'resets rotation only
xspeed#=0
yspeed#=0
endif
endif
if ScanKeyDown (VK_PRIOR) then z# = z# - 0.2 endif
if ScanKeyDown (VK_NEXT) then z# = z# + 0.2 endif
if ScanKeyDown (VK_UP) then xspeed# = xspeed# - 0.01 endif
if ScanKeyDown (VK_DOWN) then xspeed# = xspeed# + 0.01 endif
if ScanKeyDown (VK_RIGHT) then yspeed# = yspeed# + 0.01 endif
if ScanKeyDown (VK_LEFT) then yspeed# = yspeed# - 0.01 endif
wend
And to those wondering what I am Gonna use it for.
I want to make a previewer to check out how a certain block looks whith premaid "textures" for Minecraft's terrain.png files (users can edit this files and use it in game , the problem is there is currently no way out of game to see how they look.)
Some else has already a Very nice Image Editor Going and I want to Integrate a Previewer into it. (can it link into a Java app as a small preview window later?) But it uses the games's Skin previewer directly from the website's file.
Standard Terrain.Png Image looks Like.
In game it looks like
And how we are currently thinking of Cheating in using the Game's Skin previewer to view the terrain file (each image is mannauly copy and pasted ATM.)
It Actually looks more like.
The Priewer might help out in a few other OPENGL games too due to it being just cubes at the end of the day.