TinyGL:
All checks were successful
Build system / Check kernel codestyle (pull_request) Successful in 24s
Build system / Build (pull_request) Successful in 7m5s

- fixed setting of 'GL_FRONT_AND_BACK' mode
- fixed setting of 'GL_SPOT_DIRECTION' angle
- optimization of drawing triangles and lines
- fixes in 'gluCylinder' and 'gluSphere' functions
- 'gluDisk' function added
- optimize function 'calc_buf'
- clean code

Flag: add lighting

info3ds, info3ds_u, test_glu0, test_glu1, test_glu2,
textures0, textures1, textures2:
- updated programs using 'gluCylinder' and 'gluSphere'
This commit is contained in:
2025-04-22 21:43:12 +03:00
committed by Max Logaev
parent cd1c2ce969
commit 062aa527fb
23 changed files with 1155 additions and 722 deletions

View File

@@ -1,3 +1,7 @@
; SPDX-License-Identifier: GPL-2.0-only
; Textures0 - example of texture mapping on a sphere and cube
; Copyright (C) 2015-2025 KolibriOS team
use32
org 0
db 'MENUET01'
@@ -8,24 +12,24 @@ include '../../../../../macros.inc'
include '../../../../../KOSfuncs.inc'
include '../../../../../load_img.inc'
include '../../../../../load_lib.mac'
include '../kosgl.inc'
include '../opengl_const.inc'
include '../zbuffer.inc'
include '../../../../../develop/info3ds/info_fun_float.inc'
@use_library mem.Alloc,mem.Free,mem.ReAlloc,dll.Load
3d_wnd_l equ 0 ;tinygl buffer left indent
3d_wnd_t equ 30 ;tinygl buffer top indent
3d_wnd_w equ 500
3d_wnd_h equ 400
;Макрос для параметров типа double (8 байт)
macro glpush GLDoubleVar {
push dword[GLDoubleVar+4]
push dword[GLDoubleVar]
}
@use_library mem.Alloc,mem.Free,mem.ReAlloc,dll.Load
IMAGE_TOOLBAR_ICON_SIZE equ 21*21*3
align 4
start:
load_libraries l_libs_start,l_libs_end
;проверка на сколько удачно загузились библиотеки
;checking how successfully the libraries were loaded
mov ebp,lib_0
.test_lib_open:
cmp dword [ebp+ll_struc_size-4],0
@@ -39,9 +43,9 @@ load_libraries l_libs_start,l_libs_end
mcall SF_STYLE_SETTINGS,SSF_GET_COLORS,sc,sizeof.system_colors
mcall SF_SET_EVENTS_MASK,0x27
stdcall [kosglMakeCurrent], 5,30,[buf_ogl.w],[buf_ogl.h],ctx1
stdcall [kosglMakeCurrent], 3d_wnd_l,3d_wnd_t,[buf_ogl.w],[buf_ogl.h],ctx1
stdcall [glEnable], GL_DEPTH_TEST
stdcall [glEnable], GL_NORMALIZE ;делам нормали одинаковой величины во избежание артефактов
stdcall [glEnable], GL_NORMALIZE ;normals of the same size to avoid artifacts
call [gluNewQuadric]
mov [qObj],eax
stdcall [gluQuadricTexture], eax,GL_TRUE
@@ -49,7 +53,7 @@ load_libraries l_libs_start,l_libs_end
stdcall [glClearColor], 0.25,0.25,0.25,0.0
stdcall [glShadeModel], GL_SMOOTH
mov eax,dword[ctx1] ;eax -> TinyGLContext.GLContext
mov eax,[ctx1.gl_context]
mov eax,[eax] ;eax -> ZBuffer
mov eax,[eax+ZBuffer.pbuf]
mov dword[buf_ogl],eax
@@ -63,6 +67,11 @@ load_libraries l_libs_start,l_libs_end
load_image_file 'toolb_1.png', image_data_toolbar
load_image_file 'text_1.png', texture, text_w,text_h ;открытие файла текстуры
fld dword[angle_y]
stdcall update_number, txt_angle_y.v
fld dword[angle_z]
stdcall update_number, txt_angle_z.v
;* Setup texturing *
stdcall [glTexEnvi], GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL
@@ -100,7 +109,15 @@ align 4
draw_window:
pushad
mcall SF_REDRAW,SSF_BEGIN_DRAW
mcall SF_CREATE_WINDOW,(50 shl 16)+420,(30 shl 16)+410,0x33ffffff,,caption
mcall SF_STYLE_SETTINGS,SSF_GET_SKIN_HEIGHT
mov ebx,[buf_ogl.w]
add ebx,(50 shl 16)+9
mov ecx,[buf_ogl.h]
add ecx,(30 shl 16)+4
add ecx,eax
add cx,[buf_ogl.t]
mcall SF_CREATE_WINDOW,,,0x33ffffff,,caption
mov esi,[sc.work_button]
mcall SF_DEFINE_BUTTON,(6 shl 16)+19,(6 shl 16)+19,3+0x40000000 ;сферы
@@ -144,11 +161,7 @@ key:
fld dword[angle_y]
fadd dword[delt_size]
fst dword[angle_y]
mov word[NumberSymbolsAD],2
fstp qword[Data_Double]
call DoubleFloat_to_String
mov byte[txt_angle_y.v],0
stdcall str_cat, txt_angle_y.v,Data_String
stdcall update_number, txt_angle_y.v
call draw_3d
call [kosglSwapBuffers]
@@:
@@ -158,11 +171,7 @@ key:
fld dword[angle_y]
fsub dword[delt_size]
fst dword[angle_y]
mov word[NumberSymbolsAD],2
fstp qword[Data_Double]
call DoubleFloat_to_String
mov byte[txt_angle_y.v],0
stdcall str_cat, txt_angle_y.v,Data_String
stdcall update_number, txt_angle_y.v
call draw_3d
call [kosglSwapBuffers]
@@:
@@ -172,11 +181,7 @@ key:
fld dword[angle_z]
fadd dword[delt_size]
fst dword[angle_z]
mov word[NumberSymbolsAD],2
fstp qword[Data_Double]
call DoubleFloat_to_String
mov byte[txt_angle_z.v],0
stdcall str_cat, txt_angle_z.v,Data_String
stdcall update_number, txt_angle_z.v
call draw_3d
call [kosglSwapBuffers]
@@:
@@ -186,11 +191,7 @@ key:
fld dword[angle_z]
fsub dword[delt_size]
fst dword[angle_z]
mov word[NumberSymbolsAD],2
fstp qword[Data_Double]
call DoubleFloat_to_String
mov byte[txt_angle_z.v],0
stdcall str_cat, txt_angle_z.v,Data_String
stdcall update_number, txt_angle_z.v
call draw_3d
call [kosglSwapBuffers]
@@:
@@ -227,6 +228,20 @@ button:
stdcall mem.Free,[image_data_toolbar]
mcall SF_TERMINATE_PROCESS
;input:
; st0 - number
; txt_addr - pointer to text buffer
align 4
proc update_number uses eax, txt_addr:dword
mov word[NumberSymbolsAD],2
fstp qword[Data_Double]
call DoubleFloat_to_String
mov eax,[txt_addr]
mov byte[eax],0
stdcall str_cat, eax,Data_String
ret
endp
align 4
but_dr_0:
mov dword[dr_figure],0
@@ -287,8 +302,6 @@ but_zoom_m:
call [kosglSwapBuffers]
ret
align 4
caption db 'Test textures, [Esc] - exit, [<-],[->],[Up],[Down] - rotate',0
align 4
draw_3d:
@@ -303,15 +316,24 @@ cmp dword[dr_figure],0
jne @f
; рисование сфер
stdcall [glColor3f], 1.0, 1.0, 0.0
stdcall [gluSphere], [qObj], 1.0, 32,32
push 32
push 32
glpush rad1
stdcall [gluSphere], [qObj]
stdcall [glColor3f], 1.0, 0.0, 0.0
stdcall [glTranslatef], -1.6,0.0,0.0
stdcall [gluSphere], [qObj], 0.55, 16,16
push 16
push 16
glpush rad2
stdcall [gluSphere], [qObj]
stdcall [glColor3f], 0.0, 0.0, 1.0
stdcall [glTranslatef], 3.2,0.0,0.0
stdcall [gluSphere], [qObj], 0.55, 16,16
push 16
push 16
glpush rad2
stdcall [gluSphere], [qObj]
@@:
cmp dword[dr_figure],1
jne @f
@@ -387,6 +409,13 @@ call [glPopMatrix]
stdcall [buf2d_draw_text], buf_ogl, buf_1,txt_angle_y,5,25,0xffff00
ret
align 4
caption db 'Test textures, [Esc] - exit, [<-],[->],[Up],[Down] - rotate',0
align 4
rad1 dq 1.0
rad2 dq 0.55
scale dd 0.4 ;начальный масштаб
sc_delt dd 0.05 ;изменение масштаба при нажатии
sc_min dd 0.1 ;минимальный масштаб
@@ -409,13 +438,17 @@ import_tinygl:
macro E_LIB n
{
if defined sz_#n
n dd sz_#n
end if
}
include '../export.inc'
dd 0,0
macro E_LIB n
{
if used n
sz_#n db `n,0
end if
}
include '../export.inc'
@@ -533,28 +566,23 @@ lib_name_2 db 'libimg.obj',0
txt_scale:
db 'Scale: '
.v:
db 0
rb 10
.v: rb 11
txt_angle_z:
db 'Rotate z: '
.v:
db 0
rb 10
.v: rb 11
txt_angle_y:
db 'Rotate y: '
.v:
db 0
rb 10
.v: rb 11
align 4
buf_ogl:
dd 0 ;указатель на буфер изображения
dw 10,10 ;+4 left,top
.w: dd 400
.h: dd 350
dw 3d_wnd_l ;+4 left
.t: dw 3d_wnd_t ;+6 top
.w: dd 3d_wnd_w
.h: dd 3d_wnd_h
dd 0,24 ;+16 color,bit in pixel
align 4
@@ -573,7 +601,7 @@ l_libs_end:
align 4
i_end:
ctx1 rb 28 ;sizeof.TinyGLContext = 28
ctx1 TinyGLContext
image_data_toolbar dd 0
dr_figure dd 0
qObj dd 0