What upgrade do you think will fix this?

Started by JBR, September 23, 2019, 21:29:36

Previous topic - Next topic

JBR

Hi,

Using BMax and miniB3D.

I've been using Krischans code as a reference and all was working well.

I create a round cube and texture the 6 faces. Problem is when I use BLUE it comes out more like CYAN. Red/Green work fine.

Graduated BLUE is a mess!

This was all on my Dell laptop which I intentionally keep off the internet. When I try on my code on my Desktop everything works as expected!

So my guess is that I need to do some software upgrades (Graphics drivers/ OpenGL) for my laptop. (My laptop is maybe 3 years old i7 cpu)

Any advice would be much appreciated, Jim.

Kippykip

If you disable the lights, does the effect still happen?

JBR

Hi, not using any lights.

Here is the code : North Full Blue : South Graduated Blue


SuperStrict

Import "minib3d.bmx"

Graphics3D 1920/1.5, 1080/1.5, 32, 2

ClearTextureFilters()


Global G_Camera:TCamera = CreateCamera()
Global z# = -40


Global G_Planet_Type_A_Mesh:TMesh[6] ' Planet Type A needs 6 surfaces
Global G_Planet_Type_A_Surf:TSurface[6]

Global G_Planet_Top_Texture:TTexture = CreateTexture( 256,  256, 1+8+ 16 + 32 ) ' colour + mipmapped + clamp u,v
Global G_Planet_Mid_Texture:TTexture = CreateTexture( 1024, 256, 1+8+ 16 + 32 ) ' colour + mipmapped + clamp u,v
Global G_Planet_Bot_Texture:TTexture = CreateTexture( 256,  256, 1+8+ 16 + 32 ) ' colour + mipmapped + clamp u,v

TextureBlend G_Planet_Top_Texture:TTexture, 0
TextureBlend G_Planet_Mid_Texture:TTexture, 0
TextureBlend G_Planet_Bot_Texture:TTexture, 0

Global G_Planet_Top_Pixmap:TPixmap = CreatePixmap( 256,  256, PF_RGBA8888)
Global G_Planet_Mid_Pixmap:TPixmap = CreatePixmap( 1024, 256, PF_RGBA8888)
Global G_Planet_Bot_Pixmap:TPixmap = CreatePixmap( 256,  256, PF_RGBA8888)


For Local i% = 0 To 6-1
G_Planet_Type_A_Mesh:TMesh[i%] = CreateMesh()
G_Planet_Type_A_Surf:TSurface[i%] = CreateSurface(G_Planet_Type_A_Mesh:TMesh[i%])
Next


EntityTexture G_Planet_Type_A_Mesh[0], G_Planet_Mid_Texture:TTexture ' middles
EntityTexture G_Planet_Type_A_Mesh[1], G_Planet_Mid_Texture:TTexture
EntityTexture G_Planet_Type_A_Mesh[2], G_Planet_Mid_Texture:TTexture
EntityTexture G_Planet_Type_A_Mesh[3], G_Planet_Mid_Texture:TTexture
EntityTexture G_Planet_Type_A_Mesh[4], G_Planet_Top_Texture:TTexture ' top
EntityTexture G_Planet_Type_A_Mesh[5], G_Planet_Bot_Texture:TTexture ' bot

'-------------------------------------------------------------------------------------------------------------------------------------
' now fill the planets
'-------------------------------------------------------------------------------------------------------------------------------------
'-------------------------------------------------------------------------------------------------------------------------------------
' Type A
'-------------------------------------------------------------------------------------------------------------------------------------
Global G_Side_Size:Int = 16

For Local face% = 0 To 5

For Local y# = 1 To -1  Step -0.125
For Local x# = -1 To 1 Step 0.125

Local z# = -1

'we have x#,y#,z#
'----------------

Local x2# = x# * x#
Local y2# = y# * y#
Local z2# = z# * z#

Local sx# = x# * Sqr( 1 - y2#/2.0 - z2#/2.0 + y2#*z2#/3.0 ) ' these are the normals
Local sy# = y# * Sqr( 1 - x2#/2.0 - z2#/2.0 + x2#*z2#/3.0 )
Local sz# = z# * Sqr( 1 - x2#/2.0 - y2#/2.0 + x2#*y2#/3.0 )

Local size% = 1'20 ' this is the radius

Local u#,v#

If face% <= 3 Then
u# = (0.25 * face%) + ((x#+1)/2.0) * 0.25
Else
u# = ((x#+1)/2.0)
EndIf

v# = ((y#-1)/-2.0)

AddVertex( G_Planet_Type_A_Surf:TSurface[face%], sx#*size%, sy#*size%, sz#*size%, u#, v# )

Next
Next

Local mult% = G_Side_Size+1

For Local y% = 0 To G_Side_Size-1
For Local x% = 0 To G_Side_Size-1

AddTriangle( G_Planet_Type_A_Surf:TSurface[face%], y%*mult% + x%, y%*mult% + x%+1, (y%+1)*mult% + x%+1 )
AddTriangle( G_Planet_Type_A_Surf:TSurface[face%], y%*mult% + x%, (y%+1)*mult% + x%+1, (y%+1)*mult% + x% )

Next
Next

Select face%

Case 0 rotatemesh G_Planet_Type_A_Mesh:TMesh[face%], 0,0,0 ' middle
Case 1 rotatemesh G_Planet_Type_A_Mesh:TMesh[face%], 0,90,0
Case 2 rotatemesh G_Planet_Type_A_Mesh:TMesh[face%], 0,180,0
Case 3 rotatemesh G_Planet_Type_A_Mesh:TMesh[face%], 0,270,0

Case 4 rotatemesh G_Planet_Type_A_Mesh:TMesh[face%], 90, 0,0 ' NORTH
Case 5 rotatemesh G_Planet_Type_A_Mesh:TMesh[face%], 270,0,0 ' SOUTH

EndSelect
Next
'-------------------------------------------------------------------------------------------------------------------------------------------------------







'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' BLUE looks like CYAN
'----------------------


Local pixels_top:Int Ptr = Int((G_Planet_Top_Pixmap).pixels) ' fill top pixmap

For Local start%=0 To 127

For Local y%=start To 256-1-start
For Local x% = start To 256-1-start
pixels_top[ x% + y%*256] = $4f000000 | (Int((31) + 224.0 * Float(start%) / 127.0)) Shl 16 ' GRADUATED BLUE (TOTAL MESS)
Next
Next

Next

PixmapToTexture(G_Planet_Top_Pixmap:TPixmap, G_Planet_Top_Texture:TTexture)

Local pixels_bot:Int Ptr = Int((G_Planet_Bot_Pixmap).pixels) ' fill bot pixmap

For Local start%=0 To 127

For Local y%=start To 256-1-start
For Local x% = start To 256-1-start
pixels_bot[ x% + y%*256] = $ffff0000 '| (Int((31) + 224.0 * Float(start%) / 127.0)) Shl 8 ' DARKEST BLUE looks like CYAN - GREEN or RED work perfectly
Next
Next

Next

PixmapToTexture(G_Planet_Bot_Pixmap:TPixmap, G_Planet_Bot_Texture:TTexture)









Global Ground_Height_Array#[ 1024 * 256 ]

init_ground_height_array()

Local pixels_mid:Int Ptr = Int((G_Planet_Mid_Pixmap).pixels)

For Local y% = 0 To 256-1 ' fill the middle pixmap
For Local x% = 0 To 1024-1

Local height# = Ground_Height_Array#[ y% * 1024 + x% ] ' heights

If height# < 0 Then pixels_mid[ x% + y%*1024 ] = $ff7f0000 ' This BLUE seems ok

If height# >= 0 Then

Local green# = 64 + 128 * (height#/5.0)

pixels_mid[ x% + y%*1024] = $ff000000 | (green# Shl 8)
EndIf

Next
Next



Global G_Time% = MilliSecs()

'--------------------------------------------------------------------------------------------
While Not AppTerminate() Or Not Confirm( "Terminate? " )

G_Time% = MilliSecs()



PixmapToTexture(G_Planet_Top_Pixmap:TPixmap, G_Planet_Top_Texture:TTexture)

PixmapToTexture(G_Planet_Mid_Pixmap:TPixmap, G_Planet_Mid_Texture:TTexture)

PixmapToTexture(G_Planet_Bot_Pixmap:TPixmap, G_Planet_Bot_Texture:TTexture)


For Local i% = 0 To 6-1
scaleentity G_Planet_Type_A_Mesh[i%], 20,20,20
turnentity G_Planet_Type_A_Mesh[i%], .5, -.3, .2
Next


PositionEntity G_Camera, 0, 0, z#

If KeyDown(KEY_UP) Then z# :+1
If KeyDown(KEY_DOWN) Then z# :-1


updateworld()
renderworld()

Begin2D()

DrawText "THE TIME IS",100,80
DrawText String(MilliSecs()-G_Time%),100,100

End2D()

Flip True
G_Time% = MilliSecs()-G_Time%
Wend



FlushKeys()
End









'-------------------------------------------------------------------------------------------------------------------------
Function init_ground_height_array()
For Local y%=0 To 256-1
For Local x%=0 To 1024-1
Ground_Height_Array#[ y%*1024 + x% ] = -0.1 ' the lowest level
Next
Next

For Local i% = 1 To 200
Local spread% = Rand( 8, 64 )
Local height# = Rnd( 0.5, 5 )
Local cx# = Rnd( 0, 1024 )
Local cy# = Rnd( 0, 256 )
ground_node( cx#, cy#, spread%, height# )
Next


For Local cir%= 1 To 32
Local ox# = Rnd( 0, 1024 )
Local oy# = Rnd( 0, 256 )

Local rad# = Rnd( 4, 16 )

Local spread% = Rand( 16, 32 )
Local height# = Rnd( 2, 5 )

For Local t%=0 To 360-10 Step 10
Local cx# = rad# * Cos(t) + ox#
Local cy# = rad# * Sin(t) + oy#
ground_node( cx#, cy#, spread%, height# )
Next
Next

End Function
'-------------------------------------------------------------------------------------------------------------------------


'-------------------------------------------------------------------------------------------------------------------------
' ground_node - does a cosine node on the ground height
'-------------------------------------------------------------------------------------------------------------------------
Function ground_node( base_x#, base_y#, spread%, amp# )

Local fx# = base_x# - Floor(base_x#)
Local fy# = base_y# - Floor(base_y#)

For Local y% = -spread% To spread%
For Local x% = -spread% To spread%

Local d# = Sqr( (x-fx#)*(x-fx#) + (y-fy#)*(y-fy#) )

If d# < Float(spread%) Then

Local h# = amp# * Cos( (d#/Float(spread%))*180 ) ' prefer 180 To 90

Local xx% = ( Floor(base_x#-fx#) + x% ) & 1023
Local yy% = ( Floor(base_y#-fy#) + y% ) & 255

Local hh# = Ground_Height_Array#[ yy%*1024 + xx% ]
If h# > hh# Then Ground_Height_Array#[ yy%*1024 + xx% ] = h#
'Ground_Height_Array#[ yy%*1024 + xx% ] = 5.0'h#
EndIf
Next
Next
End Function
'-------------------------------------------------------------------------------------------------------------------------





'--------------------------------
' creates a texture from a pixmap
'--------------------------------
Function PixmapToTexture(pixmap:TPixmap, tex:TTexture)

        If PixmapFormat(pixmap) <> PF_RGBA8888 Then pixmap = ConvertPixmap(pixmap, PF_RGBA8888)

        ' OpenB3D only function to copy pixmap to texture
        'BufferToTex tex, PixmapPixelPtr(pixmap, 0, 0)

        ' MiniB3D workaround to copy pixmap to texture
        glBindTexture (GL_TEXTURE_2D, tex.gltex[0])
        gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, pixmap.width, pixmap.Height, GL_RGBA, GL_UNSIGNED_BYTE, PixmapPixelPtr(pixmap, 0, 0))


End Function

' --------------------------------------------------------------------------------
' Fixed BeginMax2D()
' --------------------------------------------------------------------------------
Function Begin2D()

        Local x:Int, y:Int, w:Int, h:Int
        GetViewport(x, y, w, h)

        'glPopClientAttrib()
        'glPopAttrib()
        glMatrixMode(GL_MODELVIEW)
        glPopMatrix()
        glMatrixMode(GL_PROJECTION)
        glPopMatrix()
        glMatrixMode(GL_TEXTURE)
        glPopMatrix()
        glMatrixMode(GL_COLOR)
        glPopMatrix()
       
        glDisable(GL_LIGHTING)
        glDisable(GL_DEPTH_TEST)
        glDisable(GL_SCISSOR_TEST)
        glDisable(GL_FOG)
        glDisable(GL_CULL_FACE)

        glMatrixMode GL_TEXTURE
        glLoadIdentity

        glMatrixMode GL_PROJECTION
        glLoadIdentity
        glOrtho 0, GraphicsWidth(), GraphicsHeight(), 0, -1, 1

        glMatrixMode GL_MODELVIEW
        glLoadIdentity

        SetViewport x, y, w, h

        Local MaxTex:Int
        glGetIntegerv(GL_MAX_TEXTURE_UNITS, Varptr(MaxTex))

        For Local Layer:Int = 0 Until MaxTex

                glActiveTexture(GL_TEXTURE0+Layer)

                glDisable(GL_TEXTURE_CUBE_MAP)
                glDisable(GL_TEXTURE_GEN_S)
                glDisable(GL_TEXTURE_GEN_T)
                glDisable(GL_TEXTURE_GEN_R)

                glDisable(GL_TEXTURE_2D)

        Next

        glActiveTexture(GL_TEXTURE0)

        glViewport(0, 0, GraphicsWidth(), GraphicsHeight())
        glScissor(0, 0, GraphicsWidth(), GraphicsHeight())

        glEnable GL_BLEND
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glEnable(GL_TEXTURE_2D)

End Function

' --------------------------------------------------------------------------------
' Fixed EndMax2D()
' --------------------------------------------------------------------------------
Function End2D()

        ' save the Max2D settings for later
        'glPushAttrib(GL_ALL_ATTRIB_BITS)
        'glPushClientAttrib(GL_CLIENT_ALL_ATTRIB_BITS)
        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glMatrixMode(GL_PROJECTION)
        glPushMatrix()
        glMatrixMode(GL_TEXTURE)
        glPushMatrix()
        glMatrixMode(GL_COLOR)
        glPushMatrix()
               
        glDisable(GL_TEXTURE_CUBE_MAP)
        glDisable(GL_TEXTURE_GEN_S)
        glDisable(GL_TEXTURE_GEN_T)
        glDisable(GL_TEXTURE_GEN_R)

        glDisable(GL_TEXTURE_2D)
        glDisable(GL_BLEND)

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''TGlobal.EnableStates()
        'glDisable(GL_TEXTURE_2D)

        ' ' only needed for OpenB3D
        'TGlobal.alpha_enable[0] = 0    ' alpha blending was disabled by Max2d (GL_BLEND)
        'TGlobal.blend_mode[0] = 1      ' force alpha blending
        'TGlobal.fx1[0] = 0                     ' full bright/surface normals was enabled by EnableStates (GL_NORMAL_ARRAY)
        'TGlobal.fx2[0] = 1                     ' vertex colors was enabled by EnableStates (GL_COLOR_ARRAY)

        glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR)
        glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,GL_TRUE)

        glClearDepth(1.0)
        glDepthFunc(GL_LEQUAL)
        glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)

        glAlphaFunc(GL_GEQUAL, 0.5)

        ' ' only needed for OpenB3D
        'For Local cam:TCamera=EachIn TCamera.cam_list
               
                 ' active camera - was if cam.hide[0]=0
                 'If cam = TGlobal.camera_in_use
               
                        ' fog with Max2d fix
                '       cam.UpdateFog()
                '       Exit
                       
                'EndIf
               
        'Next

End Function

RemiD

#3
in blitz3d, there are different texture blend modes, which can make a texel using the exact same color, rendered in a different way.
also check the material / brush blendmode, and maybe some vertex colors were set to be different than 255,255,255 (default color)

Amanda Dearheart

JBR,

I'm puzzled.
The Graphics3D command setups a graphics mode.
In your instructions you use it like 1920/1.5 1080/1.5, 32, 0 which tells me to setup a graphics mode of 1920 and divide it by 1.5 which results in 1280, and the same for the 1080 option.
If that is the case, what is the purpose or advantage of setting up a graphics mode this way instead of using Graphics3D 1280, 560.
Prepare to be assimilated !  Resistance is futile!

JBR

I was just using Krischans code. No difference really. Jim.

JBR

Problem Solved. After a looooooong process my pc is now fully up to date with windows 10 and the code is working correctly.

Cheers, Jim.