LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-23-2011, 09:37 AM   #1
samdman
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Rep: Reputation: Disabled
opengl and g++ prob


I have got g++ running on ubuntu 9.04(jaunty) but am having trouble with the following code on ie opengl headers , I use -I/dir..to include the opengl directories, but they still give errors,
#include<time.h>

#include<math.h>

#include<dos.h>

#include <windows.h> // Header File For Windows

#include<stdio.h>

//#include<mmsystem.h>

#include <gl.h> // Header File For The OpenGL32 Library;

#include <glu.h> // Header File For The GLu32 Library

#include <glaux.h> // Header File For The Glaux Library

GLfloat x=-0.1,y=-0.5,z;

GLsizei n ;

int start=0,help=0,exiT=0,tim=0;

float theta=0,pwr=0;

int hit=0,p1=0,p2=0,p1t=1,p2t=0,count=0,p1d=3,p2d=3;

GLuint* ids;

GLuint base;

HDC hDC=NULL; // Private GDI Device Context

HGLRC hRC=NULL; // Permanent Rendering Context

HWND hWnd=NULL; // Holds Our Window Handle

HINSTANCE hInstance; // Holds The Instance Of The Application

int lflag=0;

bool keys[256]; // Array Used For The Keyboard Routine

bool active=TRUE; // Window Active Flag Set To TRUE By Default

bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default

float INI=-0.2;

GLfloat rtri; // Angle For The Triangle ( NEW )

GLfloat rquad=0; // Angle For The Quad ( NEW )



GLvoid BuildFont(GLvoid) // Build Our Bitmap Font

{

HFONT font;

--rest excluded..
anybody have any suggestions..I have installed freeglut and mesa dev
 
Old 07-23-2011, 10:32 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
It would help if you gave the error messages and line that the compiler complains about. windows.h and dos.h aren't standard C or C++ headers, so presumably the compiler is complaining about those (if there aren't any other errors). What functionality are you wanting to use that's provided on Windows?

Edit: Also, if you're writing a C++ program, you want to drop the ".h" on the standard C headers and prefix them with a "c" (so, e.g. "stdio.h" becomes "cstdio").

Edit: Are you actually *linking* the libraries? It's not sufficient to just include the header files..

You should also post code within [code] tags to preserve indentation.

Last edited by Nylex; 07-23-2011 at 10:56 AM.
 
Old 07-23-2011, 01:47 PM   #3
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by samdman View Post
I have got g++ running on ubuntu 9.04(jaunty) but am having trouble with the following code on ie opengl headers , I use -I/dir..to include the opengl directories, but they still give errors,
Your code is for windows platform and won't compile on linux system. Linux doesn't have "windows.h".
Either use SDL, glut or Qt to initialize OpenGL in platform-dependent way, or learn how to initialize OpenGL on x-window system.

P.S. You COULD try compiling it using wine/winelib, but IMO, it is a waste of time and you REALLY should learn how to use SDL/GLUT/Qt instead.

Last edited by SigTerm; 07-23-2011 at 01:49 PM.
 
Old 07-24-2011, 04:49 AM   #4
samdman
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Post

Thanks for the help ,but the problems not solved yet,i coded it on windows 7,and it works fine on it,
but I have to submit it under linux, I thought it would be easy to compile since the source should not have too many changes (i think..),
the headers used are glaux.h,gl.h,and glu,i removed windows.h/dos.h,now it only has the opengl and stdio headers,
i will reupload the code again with some changes,but the major errors are coming from glaux.h, eg, gluInit not defined , and it also uses windows.h and mmsystem.h in header,
-are there separate gl headers for windows and linux
-can I solve these problems using an ide like codeblocks /codelite..i dont want to since g++ seems the most appealing ,but i need to get this working under linux soon,so i will do it as a short term solution,i am using ubuntu 9.04 jaunty,architecture i386or686 thanx in advance its really appreciated
 
Old 07-24-2011, 05:48 AM   #5
samdman
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:



#include <stdio.h> // Header File For Standard Input/Output
#include <gl\glaux.h> // Header File For The Glaux Library
int start=0,help=0;
float y=0,x=0;
float xs=0,ys=0;
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
GLuint base;
bool keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
bool light; // Lighting ON/OFF ( NEW )
bool lp; // L Pressed? ( NEW )
bool fp; // F Pressed? ( NEW )
char fil[10];
GLfloat xrot,xrot2; // X Rotation
GLfloat yrot,yrot2; // Y Rotation
GLfloat xspeed; // X Rotation Speed
GLfloat yspeed; // Y Rotation Speed
GLfloat z=-5.0f; // Depth Into The Screen

GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };

GLuint filter; // Which Filter To Use
GLuint texture[9]; // Storage For 3 Textures

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc

AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image
{
FILE *File=NULL; // File Handle

if (!Filename) // Make Sure A Filename Was Given
{
return NULL; // If Not Return NULL
}

File=fopen(Filename,"r"); // Check To See If The File Exists

if (File) // Does The File Exist?
{
fclose(File); // Close The Handle
return auxDIBImageLoad(Filename); // Load The Bitmap And Return A Pointer
}

return NULL; // If Load Failed Return NULL
}

int LoadGLTextures(char *fil) // Load Bitmaps And Convert To Textures
{
int Status=FALSE; // Status Indicator

AUX_RGBImageRec *TextureImage[1]; // Create Storage Space For The Texture
// Create Storage Space For The Texture

memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL
//memset(TextureImage1[0],0,sizeof(void *)*1); // Set The Pointer To NULL

// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
if (TextureImage[0]=LoadBMP(fil))
{
Status=TRUE; // Set The Status To TRUE

glGenTextures(3, &texture[0]); // Create Three Textures

// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

}
strcpy(fil,"Data/car1.bmp");
//memset(TextureImage1,0,sizeof(void *)*1);
if (TextureImage[0]=LoadBMP(fil))

{Status=TRUE; // Set The Status To TRUE

//glGenTextures(3, &texture); // Create Three Textures

// Create Nearest Filtered Texture
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

}

if (TextureImage[0]) // If Texture Exists
{
if (TextureImage[0]->data) // If Texture Image Exists
{
//free(TextureImage[0]->data);// Free The Texture Image Memory will not compile in dev
}

//free(TextureImage[0]); // Free The Image Structure
}

return Status; // Return The Status
}

GLvoid BuildFont(GLvoid) // Build Our Bitmap Font
{
HFONT font; // Windows Font ID
HFONT oldfont; // Used For Good House Keeping

base = glGenLists(96); // Storage For 96 Characters

font = CreateFont( -24, // Height Of Font
0, // Width Of Font
0, // Angle Of Escapement
0, // Orientation Angle
FW_BOLD, // Font Weight
FALSE, // Italic
FALSE, // Underline
FALSE, // Strikeout
ANSI_CHARSET, // Character Set Identifier
OUT_TT_PRECIS, // Output Precision
CLIP_DEFAULT_PRECIS, // Clipping Precision
ANTIALIASED_QUALITY, // Output Quality
FF_DONTCARE|DEFAULT_PITCH, // Family And Pitch
"Courier New"); // Font Name

oldfont = (HFONT)SelectObject(hDC, font); // Selects The Font We Want
wglUseFontBitmaps(hDC, 32, 96, base); // Builds 96 Characters Starting At Character 32
SelectObject(hDC, oldfont); // Selects The Font We Want
DeleteObject(font); // Delete The Font
}


int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
if (!LoadGLTextures(fil)) // Jump To Texture Loading Routine
{
return FALSE; // If Texture Didn't Load Return FALSE
}
BuildFont();
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations

glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
glEnable(GL_LIGHT1); // Enable Light One
return TRUE; // Initialization Went OK
}

GLvoid glPrint(const char *fmt, ...) // Custom GL "Print" Routine
{
char text[256]; // Holds Our String
va_list ap; // Pointer To List Of Arguments

if (fmt == NULL) // If There's No Text
return; // Do Nothing

va_start(ap, fmt); // Parses The String For Variables
vsprintf(text, fmt, ap); // And Converts Symbols To Actual Numbers
va_end(ap); // Results Are Stored In Text

glPushAttrib(GL_LIST_BIT); // Pushes The Display List Bits
glListBase(base - 32); // Sets The Base Character to 32
glCallLists(strlen(text), GL_UNSIGNED_BYTE, text); // Draws The Display List Text
glPopAttrib(); // Pops The Display List Bits
}

void helpu()
{glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glLoadIdentity();
glTranslatef(-3,0,0);
glRasterPos2f(-0.5,1);
glPrint("Hi,this is a Darts game designed");
glRasterPos2f(-0.5,.5);
glPrint("for two players ,so they can test ");
glRasterPos2f(-0.5,0);
glPrint("their accuracy against each other.");
glRasterPos2f(-0.5,-0.5);
glPrint("The controls are up,down,left,right,");
glRasterPos2f(-0.5,-1.0);
glPrint(" to position,and space to fire,");
glRasterPos2f(-0.5,-1.5);
glPrint("hit Esc for the menu,Enjoy!");

//getch();
//Sleep(5000);
// if( [VK_ESCAPE]){keys[VK_ESCAPE]=FALSE;help=0;
// start=0;}
}
void menu()
{//if(start==0)
{
// GLUquadricObj *quadr;
//quadr=gluNewQuadric();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
if (keys[VK_UP]) // Is F1 Being Pressed?
{
keys[VK_UP]=FALSE;
// If So Make Key FALSE
y+=.3f;
if(y>0)y=-.6;
}


if (keys[VK_DOWN]) // Is F1 Being Pressed?
{
keys[VK_DOWN]=FALSE;y-=.3f;
if(y<-.8)y=0;
// rtri-=speed;
}

glTranslatef(0,-0,1);
gluCylinder(quadr,.01000f,.10f,.5f,32,32);*/
glColor3f(1.3f,1,.20f);
glRasterPos2f(-1.8,-1.15-y);
glPrint(" Exit");
glRasterPos2f(-1.8,-.5-y);
glPrint(" Help");
glRasterPos2f(-1.8,.14-y);
glPrint(" Start");
glRasterPos2f(-3,1-y);

glPrint(" Cars ");
glColor3f(1.0f,1.f,1.00f);

}
}
}
void drawroadcar()
{glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
glPushMatrix();
glTranslatef(0,0,z);
// if(xs<10) {xs+=.1;ys+=0.1;}
glTranslatef(-.5,.5,1);
xspeed++;//xrot-=.001;xrot2-=0.001;
//glRotatef(xspeed,-1.0f,0.0f,0.0f);
if(keys[VK_LEFT])
{//keys[VK_LEFT]=FALSE;
if(yrot>-.9)yrot-=.01;
}
if(keys[VK_RIGHT])
{//keys[VK_RIGHT]=FALSE;
if(yrot<.7)yrot+=.01;
}
if(keys['A'])
{//keys['A']=FALSE;
if(yrot2>-1)yrot2-=.01;
}
if(keys['D'])
{//keys['D']=FALSE;
if(yrot2<.4 )yrot2+=.01;

}
if(keys['W'])
{//keys['W']=FALSE;
xrot2-=.01;
if(ys<10&&(int)(xrot2*100)%50==0)ys+=.1;
}
else if (ys>=0.1){ys-=.001;}
if(keys['S']){//keys['S']=FALSE;
xrot2+=.01;}

//strcpy(fil,"Data\glass.bmp");
//LoadGLTextures(fil);
glEnd();
//glLoadIdentity();

if(keys[VK_UP]||keys[VK_W])glTranslatef(0,-ys*2+xrot2+xs*2-xrot,-.8);
glTranslatef(.8,-.2,-5);
glBegin(GL_QUADS);
// Front Face/*

glNormal3f( 0.0f, 0.0f, 1.0f);

glTexCoord2f(0.0f, 0.0f); glVertex3f(.20f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 4.0f, -1.0f, 1.0f);
glTexCoord2f(1.0f, 10000.0f); glVertex3f( 0.20f, 30000.0f, 1.0f);
glTexCoord2f(0.0f, 10000.0f); glVertex3f(4.0f, 30000.0f, 1.0f);

//strcpy(fil,"Data\glass.bmp");
//LoadGLTextures(fil);
glEnd();

return TRUE; // Keep Going
}

GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
{
if (fullscreen) // Are We In Fullscreen Mode?
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
}

if (hRC) // Do We Have A Rendering Context?
{
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
{
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}

if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
hRC=NULL; // Set RC To NULL
}

if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL; // Set DC To NULL
}

if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL; // Set hWnd To NULL
}

if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL; // Set hInstance To NULL
}
}

/* This Code Creates Our OpenGL Window. Parameters Are: *
* title - Title To Appear At The Top Of The Window *
* width - Width Of The GL Window Or Fullscreen Mode *
* height - Height Of The GL Window Or Fullscreen Mode *
* bits - Number Of Bits To Use For Color (8/16/24/32) *
* fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE) */

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{ strcpy(fil,"Data/r.bmp");
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height

fullscreen=fullscreenflag; // Set The Global Fullscreen Flag

hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Load The Default Icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Load The Arrow Pointer
wc.hbrBackground = NULL; // No Background Required For GL
wc.lpszMenuName = NULL; // We Don't Want A Menu
wc.lpszClassName = "OpenGL"; // Set The Class Name

if (!RegisterClass(&wc)) // Attempt To Register The Window Class
{
MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (fullscreen) // Attempt Fullscreen Mode?
{
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 = width; // Selected Screen Width
dmScreenSettings.dmPelsHeight = height; // Selected Screen Height
dmScreenSettings.dmBitsPerPel = bits; // 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)
{
// If The Mode Fails, Offer Two Options. Quit Or Use Windowed Mode.
if (MessageBox(NULL,"The Requested Fullscreen Mode Is Not Supported By\nYour Video Card. Use Windowed Mode Instead?","NeHe GL",MB_YESNO|MB_ICONEXCLAMATION)==IDYES)
{
fullscreen=FALSE; // Windowed Mode Selected. Fullscreen = FALSE
}
else
{
// Pop Up A Message Box Letting User Know The Program Is Closing.
MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
return FALSE; // Return FALSE
}
}
}

if (fullscreen) // Are We Still In Fullscreen Mode?
{
dwExStyle=WS_EX_APPWINDOW; // Window Extended Style
dwStyle=WS_POPUP; // Windows Style
ShowCursor(FALSE); // Hide Mouse Pointer
}
else
{
dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; // Window Extended Style
dwStyle=WS_OVERLAPPEDWINDOW; // Windows Style
}

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle); // Adjust Window To True Requested Size

// Create The Window
if (!(hWnd=CreateWindowEx( dwExStyle, // Extended Style For The Window
"OpenGL", // Class Name
title, // Window Title
dwStyle | // Defined Window Style
WS_CLIPSIBLINGS | // Required Window Style
WS_CLIPCHILDREN, // Required Window Style
0, 0, // Window Position
WindowRect.right-WindowRect.left, // Calculate Window Width
WindowRect.bottom-WindowRect.top, // Calculate Window Height
NULL, // No Parent Window
NULL, // No Menu
hInstance, // Instance
NULL))) // Dont Pass Anything To WM_CREATE
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

static PIXELFORMATDESCRIPTOR pfd= // pfd Tells Windows How We Want Things To Be
{
sizeof(PIXELFORMATDESCRIPTOR), // Size Of This Pixel Format Descriptor
1, // Version Number
PFD_DRAW_TO_WINDOW | // Format Must Support Window
PFD_SUPPORT_OPENGL | // Format Must Support OpenGL
PFD_DOUBLEBUFFER, // Must Support Double Buffering
PFD_TYPE_RGBA, // Request An RGBA Format
bits, // Select Our Color Depth
0, 0, 0, 0, 0, 0, // Color Bits Ignored
0, // No Alpha Buffer
0, // Shift Bit Ignored
0, // No Accumulation Buffer
0, 0, 0, 0, // Accumulation Bits Ignored
16, // 16Bit Z-Buffer (Depth Buffer)
0, // No Stencil Buffer
0, // No Auxiliary Buffer
PFD_MAIN_PLANE, // Main Drawing Layer
0, // Reserved
0, 0, 0 // Layer Masks Ignored
};

if (!(hDC=GetDC(hWnd))) // Did We Get A Device Context?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd))) // Did Windows Find A Matching Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if(!SetPixelFormat(hDC,PixelFormat,&pfd)) // Are We Able To Set The Pixel Format?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if (!(hRC=wglCreateContext(hDC))) // Are We Able To Get A Rendering Context?
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

if(!wglMakeCurrent(hDC,hRC)) // Try To Activate The Rendering Context
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Can't Activate The GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

ShowWindow(hWnd,SW_SHOW); // Show The Window
SetForegroundWindow(hWnd); // Slightly Higher Priority
SetFocus(hWnd); // Sets Keyboard Focus To The Window
ReSizeGLScene(width, height); // Set Up Our Perspective GL Screen

if (!InitGL()) // Initialize Our Newly Created GL Window
{
KillGLWindow(); // Reset The Display
MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
return FALSE; // Return FALSE
}

return TRUE; // Success
}

LRESULT CALLBACK WndProc( HWND hWnd, // Handle For This Window
UINT uMsg, // Message For This Window
WPARAM wParam, // Additional Message Information
LPARAM lParam) // Additional Message Information
{
switch (uMsg) // Check For Windows Messages
{
case WM_ACTIVATE: // Watch For Window Activate Message
{
if (!HIWORD(wParam)) // Check Minimization State
{
active=TRUE; // Program Is Active
}
else
{
active=FALSE; // Program Is No Longer Active
}

return 0; // Return To The Message Loop
}

case WM_SYSCOMMAND: // Intercept System Commands
{
switch (wParam) // Check System Calls
{
case SC_SCREENSAVE: // Screensaver Trying To Start?
case SC_MONITORPOWER: // Monitor Trying To Enter Powersave?
return 0; // Prevent From Happening
}
break; // Exit
}

case WM_CLOSE: // Did We Receive A Close Message?
{
PostQuitMessage(0); // Send A Quit Message
return 0; // Jump Back
}

case WM_KEYDOWN: // Is A Key Being Held Down?
{
keys[wParam] = TRUE; // If So, Mark It As TRUE
return 0; // Jump Back
}

case WM_KEYUP: // Has A Key Been Released?
{
keys[wParam] = FALSE; // If So, Mark It As FALSE
return 0; // Jump Back
}

case WM_SIZE: // Resize The OpenGL Window
{
ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); // LoWord=Width, HiWord=Height
return 0; // Jump Back
}
}

// Pass All Unhandled Messages To DefWindowProc
return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain( HINSTANCE hInstance, // Instance
HINSTANCE hPrevInstance, // Previous Instance
LPSTR lpCmdLine, // Command Line Parameters
int nCmdShow) // Window Show State
{
MSG msg; // Windows Message Structure
BOOL done=FALSE; // Bool Variable To Exit Loop

// Ask The User Which Screen Mode They Prefer
fullscreen=FALSE;
// Create Our OpenGL Window
if (!CreateGLWindow("NeHe's Textures, Lighting & Keyboard Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}

while(!done) // Loop That Runs While done=FALSE
{
if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) // Is There A Message Waiting?
{
if (msg.message==WM_QUIT) // Have We Received A Quit Message?
{
done=TRUE; // If So done=TRUE
}
else // If Not, Deal With Window Messages
{
TranslateMessage(&msg); // Translate The Message
DispatchMessage(&msg); // Dispatch The Message
}
}
else // If There Are No Messages
{
// Draw The Scene. Watch For ESC Key And Quit Messages From DrawGLScene()
if ((active && !DrawGLScene()) || keys[VK_ESCAPE]) // Active? Was There A Quit Received?
{
done=TRUE; // ESC or DrawGLScene Signalled A Quit
}
else // Not Time To Quit, Update Screen
{
SwapBuffers(hDC); // Swap Buffers (Double Buffering)
if (keys['L'] && !lp)
{
lp=TRUE;
light=!light;
if (!light)
{
glDisable(GL_LIGHTING);
}
else
{
glEnable(GL_LIGHTING);
}
}
if (!keys['L'])
{
lp=FALSE;
}
if (keys['F'] && !fp)
{
fp=TRUE;
filter+=1;
if (filter>2)
{
filter=0;
}
}
if (!keys['F'])
{
fp=FALSE;
}
if (keys[VK_PRIOR])
{
z-=0.02f;
}
if (keys[VK_NEXT])
{
z+=0.02f;
}
if (keys[VK_UP])
{
xspeed-=0.01f;
}
if (keys[VK_DOWN])
{
xspeed+=0.01f;
}
if (keys[VK_RIGHT])
{
yspeed+=0.01f;
}
if (keys[VK_LEFT])
{
yspeed-=0.01f;
}

if (keys[VK_F1]) // Is F1 Being Pressed?
{
keys[VK_F1]=FALSE; // If So Make Key FALSE
KillGLWindow(); // Kill Our Current Window
fullscreen=!fullscreen; // Toggle Fullscreen / Windowed Mode
// Recreate Our OpenGL Window
if (!CreateGLWindow("NeHe's Textures, Lighting & Keyboard Tutorial",640,480,16,fullscreen))
{
return 0; // Quit If Window Was Not Created
}
}
}
}
}

// Shutdown
KillGLWindow(); // Kill The Window
return (msg.wParam); // Exit The Program
}
This is the code (most of it),it uploads some bmp files as well to run a 2d 2 player car game(like road fighter with 2p ),thing is i wanna run it on linux,
as of now i am having too many errors, most of them mentioning the gl funtions being out of scope
 
Old 07-24-2011, 09:02 AM   #6
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Quote:
Originally Posted by samdman View Post
I thought it would be easy to compile since the source should not have too many changes (i think..),
This is incorrect. YOu'll have to rewrite routines that handle windows, OpenGL initialization and keyboard/mouse input. They are all platform dependent. You can't expect to have same GUI/input functions on different OS.

Quote:
Originally Posted by samdman View Post
the headers used are glaux.h, gl.h,and glu,
glaux.h is not a standard opengl header (it is deprecated), you'll have to remove it.

Quote:
Originally Posted by samdman View Post
i will reupload the code again
I'm not going to port it onto linux for you.

To convert code to linux platform, use SDL or GLUT (There's also Qt 4, but it isn't exactly made for games). It is generally a better idea to use SDL. Of course, you'll have to learn how to use SDL, but it can't be avoided. Go to libsdl.org, read documentation and OpenGL-realted tutorials, use tutorials as a base for your app then port rendering code to SDL.
 
Old 07-24-2011, 11:50 PM   #7
samdman
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
thanx for the help, I have installed freeglut3 and mesa,
the files are in usr/include/GL
as gl.h,glext.h,gl_mangle.h,omesa.h,is that good enough ? or do i have to install other packages as well,i really dont want to shift to SDL on this project, and would like to do it on opengl/glut only, ,and is it possible to get a linux version of glaux.h installed from any package?
 
Old 07-27-2011, 12:48 AM   #8
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
This is not something I have experience with. If someone can't answer your question here, I suggest you ask on the OpenGL newsgroup or in their IRC channel.
 
Old 07-27-2011, 10:22 AM   #9
samdman
LQ Newbie
 
Registered: Jul 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
hi actually i need to install freeglut3 and mesa common dev it seems, but they have dependencies on libx111-which has dependencies on on xyz files-this is very confusing-i tried running anjuta but the build failed due to dependency issues again, i cant use sudo apt because as of now i do not have a net connection on the linux system ,i need to get a basic opengl program running ,help please
 
Old 07-27-2011, 11:22 AM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
I'm not too familiar with APT, but maybe the documentation will help you: Installing packages without an Internet connection. You might also consider posting a separate thread about the problem with installing software without an Internet connection, since it's separate to a programming problem.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bad opengl performance with two or more OpenGL windows on nvidia drivers (GF 7600 GS) psokol Linux - Software 0 02-21-2009 10:40 AM
opengl window not having title bar-using freeglut for opengl programming in c++ ashjas Fedora 0 01-19-2008 02:46 AM
red hat 9, printer prob and connection prob lasttriptotulsa Linux - Newbie 4 01-17-2007 03:39 AM
XFree keyboard problem, Quake prob and half-life prob cradlebin Linux - Software 0 09-21-2003 06:57 AM
Man 9.0 printer ? hardware prob ? install prob romcgill Linux - Hardware 2 02-24-2003 04:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration