Basecode Jump For Beginners

I’ve noticed that it’s more then a strain to start off as a beginner wannabe OpenGL programmer , i think tons off people would like to try OpenGL or make a profession or hobby out of it.

I think that the people that make this site would do tremendously good if they would add some basecode’s on this site.Why?, because I myself spend a fortune on OpenGL books, and
really i don’t care about the money it’s just
that i can’t start off , since i am a Borland 5.0 C++ enterprise user , i am totally left out in the dark, imagine you know nothing about OpenGL, and imagine nobody in the advanced coding forum knows how to start up the first most basic 1.0 example in the Red Book displayed.

the book says , all you have to do is

add , glut.h , windows.h and glu.h and voila

oh + this chunck piece of code will result in you seeing a black screen with a white square in it.

glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glEnd();
glFlush();

But in Borland 5.0 C++ enterprise edition i only get a grey screen. O/W it’s only half the story here what they are telling me in the red book, Now were is that little bridge of compatibility between OpenGL and Borland 5.0 C++ edition Users? , as a matter of fact were are all the BASECODES? for different C++ OpenGL programmers on different systems?

I think OpenGL.org should display on their site these basecodes for the different programs that support OpenGL like Borland C++ 5.0 , i need a basecode in order to make a start. I am sorry if i sound so demanding, but it would be such a help if anyone would display and paste the code that comes along to display the first example 1.0 of the Red Book. Benefits would be especially for those who are interested in OpenGL but don’t know were to start, or for the People who in general prefer a different development enviroment pure out of choise, so they don’t necessarly have to stick to the microsoft enviroment and can find the basecodes on OpenGL.ORG without being redirected to countless sites which end up in zero results, and a lott of hassle to make a nice smooth start with OpenGL?

From a Desperate wannebe Borland 5.0 C++ OpenGL programmer.

BCB comes with example OpenGl application.

but this one is better: http://nehe.gamedev.net/tutorials/borland/lesson01.zip

Thank you for replying, however the NEHE basecode isn’t working. As i stated in my reply someone needs to PASTE the code direct and ready along with additional code in here to be fastly used in Borland C++ 5.0 ,

You have this piece of code below here which creates a white rectangle within a black screen. Put the additional code to it to make it display this in a screen in Borland 5.0 C++ builder, at any rate make it display.

glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glBegin(GL_POLYGON);
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
glEnd();
glFlush();

There is error in your code (glOrtho).
Insert this to Nehe application:

void __fastcall TForm1::RenderGLScene()
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
  glMatrixMode(GL_MODELVIEW);

  glClearColor(0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
  glColor3f(1.0, 1.0, 1.0);
  glBegin(GL_POLYGON);
  glVertex3f(0.25, 0.25, 0.0);
  glVertex3f(0.75, 0.25, 0.0);
  glVertex3f(0.75, 0.75, 0.0);
  glVertex3f(0.25, 0.75, 0.0);
  glEnd();
}

some advices:

  1. wglMakeCurrent() is needed only in FormCreate and FormDestroy, you can remove it from other methods.
  2. you can move all FormCreate stuff to begin of constructor
  3. it is cool to use TPanel instead of TForm as rendering window

I almost had to get a tissue wiping of my tears of happiness, My thanks extends for the decennia to come. I have no idea how i slipped and passed by the borland tutorials on NEHE, but thanks again JEFF Molofee for helping me out on this.

For Any Aspiring OpenGL Code Wannabe Beginner here’s the cpp.code

[cppcode]
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include <gl/gl.h>
#include <gl/glu.h>
#include <float.h>

#include “MainForm.h”
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource ".dfm"
TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent
Owner)
: TForm(Owner)
{
Application->OnIdle = IdleLoop;
_control87(MCW_EM, MCW_EM);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::IdleLoop(TObject
, bool& done)
{
done = false;
wglMakeCurrent(m_hDC, m_hRC);
RenderGLScene();
SwapBuffers(m_hDC);
wglMakeCurrent(m_hDC, NULL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
SetWindowStats(640, 480, 16);

m_hDC = GetDC(Handle);
SetPixelFormatDescriptor();
m_hRC = wglCreateContext(m_hDC);
wglMakeCurrent(m_hDC, m_hRC);

// Necessary to set up before InitGL
FormResize(NULL);

InitGL();

}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
if(BorderStyle == bsNone)
ChangeDisplaySettings(NULL,0);

ReleaseDC(Handle, m_hDC);
wglMakeCurrent(m_hDC, NULL);
wglDeleteContext(m_hRC);

}
//---------------------------------------------------------------------------
void __fastcall TForm1::SetPixelFormatDescriptor()
{
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24, // Color buffer
0,0,0,0,0,0,
0,0,
0,0,0,0,0,
32, // Depth buffer
0, // Stencil buffer
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
m_iPixelFormat = ChoosePixelFormat(m_hDC, &pfd);
SetPixelFormat(m_hDC, m_iPixelFormat, &pfd);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormResize(TObject *Sender)
{
wglMakeCurrent(m_hDC, m_hRC);

glViewport(0, 0, ClientWidth, ClientHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

 // Calculate The Aspect Ratio Of The Window
 gluPerspective(45.0, static_cast&lt;double&gt;(ClientWidth) /
                    static_cast&lt;double&gt;(ClientHeight),
              0.1,100.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

wglMakeCurrent(m_hDC, NULL);
}
//---------------------------------------------------------------------------
bool fastcall TForm1::SetWindowStats(int iWidth, int iHeight, int iColor_)
{
ClientWidth = iWidth_;
ClientHeight = iHeight_;

// Check for full screen
if(Application-&gt;MessageBox("Would You Like To Run In Fullscreen Mode?",
                           "Start FullScreen?",
                           MB_YESNO|MB_ICONQUESTION)==IDYES)
{
  // Switch screen resolution to the same as the form
  DEVMODE dmScreenSettings;								// Device Mode
	  memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
	  dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
	  dmScreenSettings.dmPelsWidth	= iWidth_;			    // Selected Screen Width
	  dmScreenSettings.dmPelsHeight	= iHeight_;				  // Selected Screen Height
	  dmScreenSettings.dmBitsPerPel	= iColor_;  	   	  // Selected Bits Per Pixel
	  dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

	// Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
  	if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
	  {
    return false;
	  }
  else
  {
    BorderStyle = bsNone;
    Left = 0;
    Top = 0;
  }
}

return true;

}
//---------------------------------------------------------------------------

bool __fastcall TForm1::InitGL()
{
wglMakeCurrent(m_hDC, m_hRC);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
wglMakeCurrent(m_hDC, NULL);
return TRUE; // Initialization Went OK
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RenderGLScene()
{
glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); glMatrixMode(GL_MODELVIEW); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glBegin(GL_POLYGON); glVertex3f(0.25, 0.25, 0.0); glVertex3f(0.75, 0.25, 0.0); glVertex3f(0.75, 0.75, 0.0); glVertex3f(0.25, 0.75, 0.0); glEnd(); // Done Drawing The Quad
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormKeyPress(TObject *Sender, char &Key)
{
if(Key == VK_ESCAPE)
Close();
}
//---------------------------------------------------------------------------
[/cppcode]

And for those who are still doubting here is the header file along with it.

HEADER FILE

[cppcode]
#ifndef MainFormH
#define MainFormH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
void __fastcall FormCreate(TObject *Sender);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall FormKeyPress(TObject *Sender, char &Key);
private: // User declarations
HDC m_hDC;
HGLRC m_hRC;
int m_iPixelFormat;

bool __fastcall InitGL();
bool __fastcall SetWindowStats(int iWidth_, int iHeight_, int iColor);

public: // User declarations
__fastcall TForm1(TComponent* Owner);
void __fastcall IdleLoop(TObject*, bool&);
void __fastcall RenderGLScene();
void __fastcall SetPixelFormatDescriptor();
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
[/cppcode]

It actually works!!!

So you have basically asked for help with your compiler on the suggestions forum for opengl.

I should try it sometimes.

V-man

ho no no no no no , i made a suggestion and accidently got a compiler reply!!!

yeah im sorry, but thing is, was that it isn’t funny anymore, i have been sleeping in the mud for 5 months, spend over 500$ dollars on OpenGL books, and only now i am able to make a fancy white triangle display on a black background. Finally…

I responded because I sympathetize with any other Borland C++ Builder user in this tough, unfriendly world, dominated by VC

Originally posted by MZ:
I sympathetize with any other Borland C++ Builder user in this tough, unfriendly world, dominated by VC

Amen. If we only had a bcb forum…

/Niko

I Second That.

Laterz