Lionheart008
10-07-2024, 16:01
Hello Petr..
Perhaps you can Help for my example.
I only want to rotate a Font about 90.0 degrees.
Something is wrong or Missing in my Code example. Would be good If you can Check my NeHe 13 example. Thanks in advance.. regards Frank
'-- NeHe Lesson 13: Bitmap Fonts
' -- how to rotate a font in openGL ?
'
#COMPILE EXE
#DIM ALL
' // Include files
#INCLUDE ONCE "glu.inc"
$WindowCaption = "DDT OpenGL: NeHe Lesson 13"
GLOBAL pGL AS IDDTOpenGL
' =======================================================================================
' OpenGL class
' =======================================================================================
CLASS CDDTOpenGL
INSTANCE m_hdc AS DWORD ' // Device context
INSTANCE m_hrc AS DWORD ' // Rendering context
INSTANCE m_hDlg AS DWORD ' // Dialog handle
INSTANCE m_hFont, m_hOldFont, m_FontBase AS DWORD
INSTANCE m_cnt1, m_cnt2 AS SINGLE
INSTANCE m_szText AS ASCIIZ * 256
CLASS METHOD DESTROY
' // Release the device and rendering contexts
IF m_hdc THEN wglMakeCurrent m_hdc, 0
' // Delete the rendering context
IF m_hrc THEN wglDeleteContext m_hrc
' // Release the device context
IF m_hdc THEN ReleaseDC m_hDlg, m_hdc
' // Delete the lists
glDeleteLists m_FontBase, 96
END METHOD
' =====================================================================================
INTERFACE IDDTOpenGL : INHERIT IUNKNOWN
' =====================================================================================
' =====================================================================================
' Initializes OpenGL
' =====================================================================================
METHOD InitOpenGL (BYVAL hDlg AS DWORD) AS LONG
IF hDlg = 0 THEN EXIT METHOD
m_hDlg = hDlg
' // Get the device context
m_hdc = GetDC(m_hDlg)
IF m_hdc = 0 THEN EXIT METHOD
' // Bits per pixel
LOCAL nBitsPerPel AS LONG
nBitsPerPel = GetDeviceCaps(m_hdc, %BITSPIXEL)
' // Depth bits
LOCAL cDepthBits AS LONG
cDepthBits = nBitsPerPel - 8
IF cDepthBits < 16 THEN cDepthBits = 16
' // Pixel format
LOCAL pfd AS PIXELFORMATDESCRIPTOR
pfd.nSize = SIZEOF(PIXELFORMATDESCRIPTOR)
pfd.nVersion = 1
pfd.dwFlags = %PFD_DRAW_TO_WINDOW OR %PFD_SUPPORT_OPENGL OR %PFD_DOUBLEBUFFER
pfd.iPixelType = %PFD_TYPE_RGBA
pfd.cColorBits = nBitsPerPel
pfd.cDepthBits = cDepthBits
' // Find a matching pixel format
LOCAL pf AS LONG
pf = ChoosePixelFormat(m_hdc, pfd)
IF ISFALSE pf THEN
MessageBox(m_hDlg, "Can't find a suitable pixel format", FUNCNAME$, %MB_OK OR %MB_ICONINFORMATION)
EXIT METHOD
END IF
' // Set the pixel format
IF ISFALSE SetPixelFormat(m_hdc, pf, pfd) THEN
MessageBox(m_hDlg, "Can't set the pixel format", FUNCNAME$, %MB_OK OR %MB_ICONINFORMATION)
EXIT METHOD
END IF
' // Create a new OpenGL rendering context
m_hrc = wglCreateContext(m_hdc)
IF m_hrc = 0 THEN
MessageBox m_hDlg, "Can't create an OpenGL rendering context", FUNCNAME$, %MB_OK OR %MB_ICONEXCLAMATION
SendMessage m_hDlg, %WM_CLOSE, 0, 0
EXIT METHOD
END IF
' // Make it current
IF ISFALSE wglMakeCurrent(m_hdc, m_hrc) THEN
MessageBox m_hDlg, "Can't activate the OpenGL rendering context", FUNCNAME$, %MB_OK OR %MB_ICONEXCLAMATION
SendMessage m_hDlg, %WM_CLOSE, 0, 0
EXIT METHOD
END IF
' // Return success
METHOD = %TRUE
END METHOD
' =====================================================================================
' =====================================================================================
' All the setup goes here
' =====================================================================================
METHOD SetupScene
' Select smooth shading
glShadeModel %GL_SMOOTH
' Specify clear values for the color buffers
glClearColor 0.0!, 0.0!, 0.0!, 0.0!
' Specify the clear value for the depth buffer
glClearDepth 1.0!
' Enable depth comparisons and update the depth buffer
glEnable %GL_DEPTH_TEST
' Specify the value used for depth-buffer comparisons
glDepthFunc %GL_LEQUAL
' Really nice perspective calculations
glHint %GL_PERSPECTIVE_CORRECTION_HINT, %GL_NICEST
' Storage for 96 characters
m_FontBase = glGenLists(96)
' Build the font
m_hFont = CreateFont(-24, _ ' Height of the font
0, _ ' Width of the font
0, _ ' Angle of escapement
0, _ ' Orientation angle
%FW_BOLD, _ ' Font weight
0, _ ' Italic
0, _ ' Underline
0, _ ' Strikeout
%ANSI_CHARSET, _ ' Character set identifier
%OUT_TT_PRECIS, _ ' Output precision
%CLIP_DEFAULT_PRECIS, _ ' Clipping precision
%ANTIALIASED_QUALITY, _ ' Output quality
%FF_DONTCARE OR %DEFAULT_PITCH, _ ' Family and pitch
"Courier New") ' Font name
' Select our font
m_hOldFont = SelectObject(m_hdc, m_hFont)
' Builds 96 characters starting at character 32
wglUseFontBitmaps m_hdc, 32, 96, m_FontBase
' Select previous font
SelectObject m_hdc, m_hOldFont
' Delete the font
DeleteObject m_hFont
END METHOD
' =====================================================================================
' =====================================================================================
' Resize the scene
' =====================================================================================
METHOD ResizeScene (BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)
' // Prevent divide by zero making height equal one
IF nHeight = 0 THEN nHeight = 1
' // Reset the current viewport
glViewport 0, 0, nWidth, nHeight
' // Select the projection matrix
glMatrixMode %GL_PROJECTION
' // Reset the projection matrix
glLoadIdentity
' // Calculate the aspect ratio of the window
gluPerspective 45.0!, nWidth / nHeight, 0.1!, 100.0!
' // Select the model view matrix
glMatrixMode %GL_MODELVIEW
' // Reset the model view matrix
glLoadIdentity
END METHOD
' =====================================================================================
' =======================================================================================
' Render the scene
' =======================================================================================
METHOD RenderScene
DIM angle AS STATIC SINGLE
'angle=80.0
' Clear the screen buffer
glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
' Reset the view
glLoadIdentity
angle=80.0
' Move one unit into the screen
glpushmatrix()
glTranslatef 0.0!, 0.0!, -1.0!
glRotatef(angle,0.0!, 0.0!,1.0!)
' Pulsing colors based on text position
glColor3f 1.0! * COS(m_cnt1), 1.0! * SIN(m_cnt2), 1.0! - 0.5! * COS(m_cnt1 + m_cnt2)
' Position the text on the screen
glRasterPos2f -0.45! + 0.05! * COS(m_cnt1), 0.32! * SIN(m_cnt2)
' Print GL text to the screen
'm_szText = "Active OpenGL Text With NeHe - " & FORMAT$(m_cnt1, "#.00")
m_szText = "Active OpenGL Text With Powerbasic - " & FORMAT$(m_cnt1, "#.00") 'm_cnt1
glpopmatrix()
' Pushes the display list bits
glPushAttrib %GL_LIST_BIT
' Sets the base character to 0
glListBase m_FontBase - 32
' Draws the display list text
glCallLists LEN(m_szText), %GL_UNSIGNED_BYTE, m_szText
' Pops the display list bits
glPopAttrib
' Increase counters
'm_cnt1 '= m_cnt1 + 0.051!
'm_cnt2 '= m_cnt2 + 0.005!
' // Exchange the front and back buffers
SwapBuffers m_hdc
END METHOD
' =======================================================================================
' ====================================================================================
' Processes keystrokes
' ====================================================================================
METHOD ProcessKeys (BYVAL hDlg AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG)
SELECT CASE wMsg
CASE %WM_KEYDOWN
SELECT CASE LO(WORD, wParam)
CASE %VK_ESCAPE
' // Send a message to close the application
DIALOG SEND hDlg, %WM_CLOSE, 0, 0
END SELECT
END SELECT
END METHOD
' ====================================================================================
END INTERFACE
END CLASS
' =======================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG
' // Create the dialog
LOCAL hDlg AS DWORD
DIALOG NEW PIXELS, 0, $WindowCaption, , , 600, 400, %WS_OVERLAPPEDWINDOW TO hDlg
' // Create an instance of the DX9 class
pGL = CLASS "CDDTOpenGL"
IF ISNOTHING(pGL) THEN EXIT FUNCTION
' // Initialize OpenGL
IF ISFALSE pGL.InitOpenGL(hDlg) THEN EXIT FUNCTION
' // Display and activate the dialog
DIALOG SHOW MODELESS hDlg, CALL DlgProc
' // Set the timer
SetTimer(hDlg, 1, 0, %NULL)
' // Message loop
LOCAL uMsg AS tagMsg
WHILE GetMessage(uMsg, %NULL, 0, 0)
TranslateMessage uMsg
DispatchMessage uMsg
WEND
' // Kill the timer
KillTimer(hDlg, 1)
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main Dialog procedure
' ========================================================================================
CALLBACK FUNCTION DlgProc() AS LONG
SELECT CASE CB.MSG
CASE %WM_SYSCOMMAND
' // Disable the Windows screensaver
IF (CB.WPARAM AND &HFFF0) = %SC_SCREENSAVE THEN FUNCTION = 1
' // Close the window
IF (CB.WPARAM AND &HFFF0) = %SC_CLOSE THEN DIALOG SEND CB.HNDL, %WM_CLOSE, 0, 0
CASE %WM_INITDIALOG
' // Set up the scene
pGL.SetupScene
CASE %WM_TIMER
' // Render the scene
pGL.RenderScene
CASE %WM_SIZE
' // Resize the scene
pGL.ResizeScene LO(WORD, CB.LPARAM), HI(WORD, CB.LPARAM)
CASE %WM_KEYDOWN
' // Process keystrokes
pGL.ProcessKeys CB.HNDL, CB.MSG, CB.WPARAM, CB.LPARAM
CASE %WM_CLOSE
' // Post a message to end the application
DIALOG SEND CB.HNDL, %WM_DESTROY, 0, 0
CASE %WM_DESTROY
' // End the application
' // Use this method instead of DIALOG END with modeless dialogs
PostQuitMessage 0
END SELECT
END FUNCTION
' ========================================================================================
Perhaps you can Help for my example.
I only want to rotate a Font about 90.0 degrees.
Something is wrong or Missing in my Code example. Would be good If you can Check my NeHe 13 example. Thanks in advance.. regards Frank
'-- NeHe Lesson 13: Bitmap Fonts
' -- how to rotate a font in openGL ?
'
#COMPILE EXE
#DIM ALL
' // Include files
#INCLUDE ONCE "glu.inc"
$WindowCaption = "DDT OpenGL: NeHe Lesson 13"
GLOBAL pGL AS IDDTOpenGL
' =======================================================================================
' OpenGL class
' =======================================================================================
CLASS CDDTOpenGL
INSTANCE m_hdc AS DWORD ' // Device context
INSTANCE m_hrc AS DWORD ' // Rendering context
INSTANCE m_hDlg AS DWORD ' // Dialog handle
INSTANCE m_hFont, m_hOldFont, m_FontBase AS DWORD
INSTANCE m_cnt1, m_cnt2 AS SINGLE
INSTANCE m_szText AS ASCIIZ * 256
CLASS METHOD DESTROY
' // Release the device and rendering contexts
IF m_hdc THEN wglMakeCurrent m_hdc, 0
' // Delete the rendering context
IF m_hrc THEN wglDeleteContext m_hrc
' // Release the device context
IF m_hdc THEN ReleaseDC m_hDlg, m_hdc
' // Delete the lists
glDeleteLists m_FontBase, 96
END METHOD
' =====================================================================================
INTERFACE IDDTOpenGL : INHERIT IUNKNOWN
' =====================================================================================
' =====================================================================================
' Initializes OpenGL
' =====================================================================================
METHOD InitOpenGL (BYVAL hDlg AS DWORD) AS LONG
IF hDlg = 0 THEN EXIT METHOD
m_hDlg = hDlg
' // Get the device context
m_hdc = GetDC(m_hDlg)
IF m_hdc = 0 THEN EXIT METHOD
' // Bits per pixel
LOCAL nBitsPerPel AS LONG
nBitsPerPel = GetDeviceCaps(m_hdc, %BITSPIXEL)
' // Depth bits
LOCAL cDepthBits AS LONG
cDepthBits = nBitsPerPel - 8
IF cDepthBits < 16 THEN cDepthBits = 16
' // Pixel format
LOCAL pfd AS PIXELFORMATDESCRIPTOR
pfd.nSize = SIZEOF(PIXELFORMATDESCRIPTOR)
pfd.nVersion = 1
pfd.dwFlags = %PFD_DRAW_TO_WINDOW OR %PFD_SUPPORT_OPENGL OR %PFD_DOUBLEBUFFER
pfd.iPixelType = %PFD_TYPE_RGBA
pfd.cColorBits = nBitsPerPel
pfd.cDepthBits = cDepthBits
' // Find a matching pixel format
LOCAL pf AS LONG
pf = ChoosePixelFormat(m_hdc, pfd)
IF ISFALSE pf THEN
MessageBox(m_hDlg, "Can't find a suitable pixel format", FUNCNAME$, %MB_OK OR %MB_ICONINFORMATION)
EXIT METHOD
END IF
' // Set the pixel format
IF ISFALSE SetPixelFormat(m_hdc, pf, pfd) THEN
MessageBox(m_hDlg, "Can't set the pixel format", FUNCNAME$, %MB_OK OR %MB_ICONINFORMATION)
EXIT METHOD
END IF
' // Create a new OpenGL rendering context
m_hrc = wglCreateContext(m_hdc)
IF m_hrc = 0 THEN
MessageBox m_hDlg, "Can't create an OpenGL rendering context", FUNCNAME$, %MB_OK OR %MB_ICONEXCLAMATION
SendMessage m_hDlg, %WM_CLOSE, 0, 0
EXIT METHOD
END IF
' // Make it current
IF ISFALSE wglMakeCurrent(m_hdc, m_hrc) THEN
MessageBox m_hDlg, "Can't activate the OpenGL rendering context", FUNCNAME$, %MB_OK OR %MB_ICONEXCLAMATION
SendMessage m_hDlg, %WM_CLOSE, 0, 0
EXIT METHOD
END IF
' // Return success
METHOD = %TRUE
END METHOD
' =====================================================================================
' =====================================================================================
' All the setup goes here
' =====================================================================================
METHOD SetupScene
' Select smooth shading
glShadeModel %GL_SMOOTH
' Specify clear values for the color buffers
glClearColor 0.0!, 0.0!, 0.0!, 0.0!
' Specify the clear value for the depth buffer
glClearDepth 1.0!
' Enable depth comparisons and update the depth buffer
glEnable %GL_DEPTH_TEST
' Specify the value used for depth-buffer comparisons
glDepthFunc %GL_LEQUAL
' Really nice perspective calculations
glHint %GL_PERSPECTIVE_CORRECTION_HINT, %GL_NICEST
' Storage for 96 characters
m_FontBase = glGenLists(96)
' Build the font
m_hFont = CreateFont(-24, _ ' Height of the font
0, _ ' Width of the font
0, _ ' Angle of escapement
0, _ ' Orientation angle
%FW_BOLD, _ ' Font weight
0, _ ' Italic
0, _ ' Underline
0, _ ' Strikeout
%ANSI_CHARSET, _ ' Character set identifier
%OUT_TT_PRECIS, _ ' Output precision
%CLIP_DEFAULT_PRECIS, _ ' Clipping precision
%ANTIALIASED_QUALITY, _ ' Output quality
%FF_DONTCARE OR %DEFAULT_PITCH, _ ' Family and pitch
"Courier New") ' Font name
' Select our font
m_hOldFont = SelectObject(m_hdc, m_hFont)
' Builds 96 characters starting at character 32
wglUseFontBitmaps m_hdc, 32, 96, m_FontBase
' Select previous font
SelectObject m_hdc, m_hOldFont
' Delete the font
DeleteObject m_hFont
END METHOD
' =====================================================================================
' =====================================================================================
' Resize the scene
' =====================================================================================
METHOD ResizeScene (BYVAL nWidth AS LONG, BYVAL nHeight AS LONG)
' // Prevent divide by zero making height equal one
IF nHeight = 0 THEN nHeight = 1
' // Reset the current viewport
glViewport 0, 0, nWidth, nHeight
' // Select the projection matrix
glMatrixMode %GL_PROJECTION
' // Reset the projection matrix
glLoadIdentity
' // Calculate the aspect ratio of the window
gluPerspective 45.0!, nWidth / nHeight, 0.1!, 100.0!
' // Select the model view matrix
glMatrixMode %GL_MODELVIEW
' // Reset the model view matrix
glLoadIdentity
END METHOD
' =====================================================================================
' =======================================================================================
' Render the scene
' =======================================================================================
METHOD RenderScene
DIM angle AS STATIC SINGLE
'angle=80.0
' Clear the screen buffer
glClear %GL_COLOR_BUFFER_BIT OR %GL_DEPTH_BUFFER_BIT
' Reset the view
glLoadIdentity
angle=80.0
' Move one unit into the screen
glpushmatrix()
glTranslatef 0.0!, 0.0!, -1.0!
glRotatef(angle,0.0!, 0.0!,1.0!)
' Pulsing colors based on text position
glColor3f 1.0! * COS(m_cnt1), 1.0! * SIN(m_cnt2), 1.0! - 0.5! * COS(m_cnt1 + m_cnt2)
' Position the text on the screen
glRasterPos2f -0.45! + 0.05! * COS(m_cnt1), 0.32! * SIN(m_cnt2)
' Print GL text to the screen
'm_szText = "Active OpenGL Text With NeHe - " & FORMAT$(m_cnt1, "#.00")
m_szText = "Active OpenGL Text With Powerbasic - " & FORMAT$(m_cnt1, "#.00") 'm_cnt1
glpopmatrix()
' Pushes the display list bits
glPushAttrib %GL_LIST_BIT
' Sets the base character to 0
glListBase m_FontBase - 32
' Draws the display list text
glCallLists LEN(m_szText), %GL_UNSIGNED_BYTE, m_szText
' Pops the display list bits
glPopAttrib
' Increase counters
'm_cnt1 '= m_cnt1 + 0.051!
'm_cnt2 '= m_cnt2 + 0.005!
' // Exchange the front and back buffers
SwapBuffers m_hdc
END METHOD
' =======================================================================================
' ====================================================================================
' Processes keystrokes
' ====================================================================================
METHOD ProcessKeys (BYVAL hDlg AS DWORD, BYVAL wMsg AS DWORD, BYVAL wParam AS DWORD, BYVAL lParam AS LONG)
SELECT CASE wMsg
CASE %WM_KEYDOWN
SELECT CASE LO(WORD, wParam)
CASE %VK_ESCAPE
' // Send a message to close the application
DIALOG SEND hDlg, %WM_CLOSE, 0, 0
END SELECT
END SELECT
END METHOD
' ====================================================================================
END INTERFACE
END CLASS
' =======================================================================================
' ========================================================================================
' Main
' ========================================================================================
FUNCTION PBMAIN () AS LONG
' // Create the dialog
LOCAL hDlg AS DWORD
DIALOG NEW PIXELS, 0, $WindowCaption, , , 600, 400, %WS_OVERLAPPEDWINDOW TO hDlg
' // Create an instance of the DX9 class
pGL = CLASS "CDDTOpenGL"
IF ISNOTHING(pGL) THEN EXIT FUNCTION
' // Initialize OpenGL
IF ISFALSE pGL.InitOpenGL(hDlg) THEN EXIT FUNCTION
' // Display and activate the dialog
DIALOG SHOW MODELESS hDlg, CALL DlgProc
' // Set the timer
SetTimer(hDlg, 1, 0, %NULL)
' // Message loop
LOCAL uMsg AS tagMsg
WHILE GetMessage(uMsg, %NULL, 0, 0)
TranslateMessage uMsg
DispatchMessage uMsg
WEND
' // Kill the timer
KillTimer(hDlg, 1)
END FUNCTION
' ========================================================================================
' ========================================================================================
' Main Dialog procedure
' ========================================================================================
CALLBACK FUNCTION DlgProc() AS LONG
SELECT CASE CB.MSG
CASE %WM_SYSCOMMAND
' // Disable the Windows screensaver
IF (CB.WPARAM AND &HFFF0) = %SC_SCREENSAVE THEN FUNCTION = 1
' // Close the window
IF (CB.WPARAM AND &HFFF0) = %SC_CLOSE THEN DIALOG SEND CB.HNDL, %WM_CLOSE, 0, 0
CASE %WM_INITDIALOG
' // Set up the scene
pGL.SetupScene
CASE %WM_TIMER
' // Render the scene
pGL.RenderScene
CASE %WM_SIZE
' // Resize the scene
pGL.ResizeScene LO(WORD, CB.LPARAM), HI(WORD, CB.LPARAM)
CASE %WM_KEYDOWN
' // Process keystrokes
pGL.ProcessKeys CB.HNDL, CB.MSG, CB.WPARAM, CB.LPARAM
CASE %WM_CLOSE
' // Post a message to end the application
DIALOG SEND CB.HNDL, %WM_DESTROY, 0, 0
CASE %WM_DESTROY
' // End the application
' // Use this method instead of DIALOG END with modeless dialogs
PostQuitMessage 0
END SELECT
END FUNCTION
' ========================================================================================