Introduction to OpenGL: A 3D Text Rendering Tutorial

Introduction to Open GL

Links:

With the availability of tools like DirectX and OpenGL, writing a desktop application that renders 3D elements is not very difficult nowadays. However, like many technologies, there are sometimes obstacles making it difficult for developers trying to enter into this niche. Over time, the race between DirectX and OpenGL has caused these technologies to become more accessible to developers, along with better documentation and an easier process of becoming a skilled DirectX or OpenGL developer.

DirectX, introduced and maintained by Microsoft, is a technology specific to the Windows platform. On the other hand, OpenGL is a cross-platform API for the 3D graphics arena whose specification is maintained by the Khronos Group.

In this introduction to OpenGL, you will write a very simple application to render 3D text models. We will be using Qt/Qt Creator to implement the UI, making it easy to compile and run this application on multiple platforms. The source code of the prototype built for this article is available on GitHub.

The goal of this simple application is to generate 3D models, save them to a file with a simple format, and to open and render them on screen. The 3D model in the rendered scene will be rotatable and zoomable, to give a better sense of depth and dimension.

Get Hostname from IP Address

While doing system troubleshooting I will sometimes come across an IP address which is causing some issue and is getting reported on an error log.  It could be a server, or a network user, and it would be helpful to know the Hostname in order to dig in further.

CMD

The easiest method that I have come across is to use the windows command prompt.

  • Start > Run > CMD
  • ping -a [IP ADDRESS}

There are other methods such as using power shell, java, C#, etc, but if you are not trying to integrate this hostname into some other commands then CMD should be all you need.

Performance of Like vs Left/Right for Indexed and Non Indexed Columns

I have have heard and read many times over the years that Left or Right should always be used, where possible, instead of Like.  On the surface, this does sound logical since the Like command is often used for pattern searching and one could assume that the Like command is causing some extra work to be performed by the SQL server engine even though the predicate expressions are essentially equivalent. I personally have always assumed that they operated equivalently, however, I had never performed a performance analysis to infer the true answer.  Also, was curious to find if there was a difference in performance when applied specifically to an indexed column vs non-indexed column.

The names and data structures in this example have been changed to protect the innocent. For this test, assume [SOME_TABLE] has 530 million records and contains two columns: [INDEXED_COLUMN], and [NONINDEXED_COLUMN].  Indexed_Column has a clustered index and Nonindexed_Column does not have an index.  We will run a test using like and left against each column using a basic count(*) command.

Test 1 – Non Indexed Column

Output for queries 1 and 2 = 63 million.

  • Query 1 used like and  averaged 102 seconds over 5 measurements.
  • Query 2 used left and averaged 103 seconds over 5 measurements.

Execution plans for queries 3 and 4:like vs left no index

Test 2 – Indexed Column

Output for queries 1 and 2 = 87 million.

  • Query 1 used like and averaged 3 seconds over 5 measurements.
  • Query 2 used left and averaged 14 seconds over 5 measurements.

Execution plans for queries 1 and 2:like vs left index

Conclusion

You can see from the results that Like is actually considerably faster than Left when applied to an indexed column.  This is because Like is treated as a computed column, which can utilize indexes, while Left is a function which can not utilize indexes.  If an index is not involved then Like and Left perform the same.

There might be additional factors that impact performance differences which I am not considering such as other index types, and other data types.  I came across another blog (http://cc.davelozinski.com/sql/like-vs-substring-vs-leftright-vs-charindex) where a similar test was done.  Surprisingly, their results showed that Chardindex is the most efficient out of Like, Substring, Left/Right, and Charindex, and their results between Like and Left/Right are quite different than mine.  At some point I’d like to go through their code and identify exactly what is different.

Edit: The author reached out to me and mentioned that the main difference between our results is likely due to my analysis being ran on SQL Server 2008 R2 vs theirs being done on SQL Server 2014 and there have been changes to the query engine between versions.  I encourage anyone seeing this to check out Dave’s blog.

More about Indexes on Computed Columns: https://msdn.microsoft.com/en-us/library/ms189292.aspx

Check SQL Server Version Using T-SQL

If you are building some code that would be different depending on the version of SQL Server then it may be useful to check the SQL server version using T-SQL instead of going through the object explorer in SSMS.  For example, I have some code that checks for SSIS package execution status across multiple servers and the database design is slightly different between server versions so I need to check the version and then execute the proper block of code.

 

Helpful SQL Server Links

icrosoft White Papers:
https://msdn.microsoft.com/en-us/library/ee410014(v=sql.105).aspx

Microsoft Books Online:
https://technet.microsoft.com/en-us/library/ms130214(v=sql.105).aspx

Pragmatic Works Training Resources:
http://pragmaticworks.com/Training/Resources

SQL Server Database Engine Permission Posters:
http://social.technet.microsoft.com/wiki/contents/articles/11842.sql-server-database-engine-permission-posters.aspx

TechFunda SQL Server Tutorials:
http://techfunda.com/howto/sql-server

Microsoft SQL Server Tutorials:
https://msdn.microsoft.com/en-us/library/ms167593

Microsoft SQL Server Community Projects & Samples:
http://sqlserversamples.codeplex.com/

SQL Pass DBA Fundamentals – Web Presentation Archives
http://fundamentals.sqlpass.org/MeetingArchive.aspx

Blogs and Other Great Resources:
https://blogs.msdn.microsoft.com/sql_server_team/ – MSSQL Tiger Team
https://www.mssqltips.com/
http://blog.sqlauthority.com/
http://www.brentozar.com/
http://www.edwinmsarmiento.com/
http://kevinsgoff.net/
https://www.sqlskills.com/
http://blog.datainspirations.com/
 – BI blog by Stacia

A better list put together by New Horizons:
http://nhlearningsolutions.com/Blog/TabId/145/ArtMID/16483/ArticleID/1186/Free-Resources-for-SQL-Server.aspx

SQL Injections:
http://www.unixwiz.net/techtips/sql-injection.html

Show SP_Who and Rollback Status for All SPIDS Rolling Back

We had a session we had to kill and roll back and wanted some more information about the status of the roll back.  If you only have one SPID to check then you can run the kill commend with an option:

I wanted to expand this by dynamically looking for all sessions in rollback status and then provide some information about the session as well as the kill status.  This way, I do not need to first manually review sessions and look for records in rollback status, then check each kill status.

In my test there was only one SPID in rollback status but it will work if there are more than one.

List SQL Servers On Network

A list of servers can be obtained using windows command prompt (cmd) or powershell (ps).  CMD and PS both provide Server Name and Instance Name, however, powershell provides two additional fields: IsClustered, and SQL Server Version.  One challenge I have noticed is that running these commands from my local machine only returns a short list with names that look like computer names and not server names.  I had to run the commands from a production server, a QA server, and a development server to obtain the server lists from those environments.  There must be some network separation between them, which I am still investigating.

CMD: OSQL -L or SQLCMD -L

PS: [System.Data.Sql.SqlDataSourceEnumerator]::Instance.GetDataSources()

Check if SQL Server is Clustered

For more information on SERVERPROPERTY(): https://msdn.microsoft.com/en-us/library/ms174396.aspx

Search for Column Name in All Tables in All Databases

Use a text wild card to search for a column name in all tables in each database.  Stored procedure sp_msforeachdb is used to cycle through each database.  The sys tables are used to obtain table and column information.  The output will include Database Name, Schema Name, Table Name, Column Name, and code to easily select the top 10 from a table returned in the result.