Active Forum Topics

Syndicate content
Inferno Programming Forums - http://www.infernodevelopment.com/forum
Updated: 4 weeks 1 day ago

need texture help with opengl

August 2, 2010 - 6:05pm
I have simple C++ opengl app. It works nice but when texture image is smaller than X*X then program crashes. Any fix for this?
2nd question: How do i make texture repeatitself instead of stretching itself?

Code:
/*
Title: kontent
Copyright (c) 2004 Martin John Baker
Author: Imran Ahmed khan

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

For information about the GNU General Public License see http://www.gnu.org/

To discuss this program http://sourceforge.net/forum/forum.php?forum_id=422259
also see website http://www.euclideanspace.com/software/games/twod/

*/

#include <windows.h>        
#include <stdio.h>
#include <math.h>
#include <gl\gl.h>            
#include <gl\glu.h>            
#include <gl\glaux.h>
#include <iostream>
#include "wtypes.h"


using namespace std;


HDC            hDC=NULL;        
HGLRC        hRC=NULL;        
HWND        hWnd=NULL;        
HINSTANCE    hInstance;        

bool    keys[256];            
bool    active=TRUE;        
bool    fullscreen=TRUE;
bool negative=FALSE;
bool negativeZ=FALSE;
bool negativeX=FALSE;
float i = 60;
float x = 0;
float y = 0;
float punchingY = -4;
float punchingZ = -7;
float punchingX = 0;
float size = -7;
#define PI 3.14159265
//-----------------------------------
// Light Parameters
static GLfloat LightAmb[] = {3,2,1, 100};    // Ambient Light
static GLfloat LightDif[] = {0, 0, 0, 0};    // Diffuse Light
static GLfloat LightPos[] = {4.0f, 4.0f, 6.0f, 1.0f};    // Light Position
//light 2
static GLfloat LightAmb1[] = {0,15,0, 100};    // Ambient Light
static GLfloat LightDif1[] = {0, 0, 0, 0};    // Diffuse Light
static GLfloat LightPos1[] = {1.0f, 1.0f, 1.0f, 1.0f};    // Light Position

GLUquadricObj    *q;                                        // Quadratic For Drawing A Sphere

//-----------------------------------
GLuint    texture[3];        

LRESULT    CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

/*RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);
const long nScreenWidth = ::GetSystemMetrics(SM_CXSCREEN);
const long nScreenHeight = ::GetSystemMetrics(SM_CYSCREEN);
*/
AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File=NULL;

if (!Filename)
{
return NULL;
}

File=fopen(Filename,"r");

if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}

return NULL;
}

// Get the horizontal and vertical screen sizes in pixel
void GetDesktopResolution(int& horizontal, int& vertical)
{
   RECT desktop;
   // Get a handle to the desktop window
   const HWND hDesktop = GetDesktopWindow();
   // Get the size of screen to the variable desktop
   GetWindowRect(hDesktop, &desktop);
   // The top left corner will have coordinates (0,0)
   // and the bottom right corner will have coordinates
   // (horizontal, vertical)
   horizontal = desktop.right;
   vertical = desktop.bottom;
}


int LoadGLTextures()
{
int Status=FALSE;

AUX_RGBImageRec *TextureImage[3];

memset(TextureImage,1,sizeof(void *)*2);
if (TextureImage[0]=LoadBMP("Data/image1.bmp"))
{
Status=TRUE;

glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}

free(TextureImage[0]);
}
//--------------------
if (TextureImage[1]=LoadBMP("Data/image2.bmp"))
{
Status=TRUE;

glGenTextures(1, &texture[1]);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}

free(TextureImage[0]);
}
//----------
if (TextureImage[2]=LoadBMP("Data/image3.bmp"))
{
Status=TRUE;

glGenTextures(1, &texture[2]);
glBindTexture(GL_TEXTURE_2D, texture[2]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}

if (TextureImage[0])
{
if (TextureImage[0]->data)
{
free(TextureImage[0]->data);
}

free(TextureImage[0]);
}
return Status;
}


GLvoid ReSizeGLScene(GLsizei width, GLsizei height)    
{

    glViewport(0,0,width,height);                    

    glMatrixMode(GL_PROJECTION);                    
    glLoadIdentity();                                

    
    gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);

    glMatrixMode(GL_MODELVIEW);            
    glLoadIdentity();                    
}
///GL init



int InitGL(GLvoid)                                        // All Setup For OpenGL Goes Here
{
    if (!LoadGLTextures())                                // If Loading The Textures Failed
    {
        return FALSE;                                    // Return False
    }
    glShadeModel(GL_SMOOTH);                            // Enable Smooth Shading
    //glClearColor(0.2f, 0.5f, 1.0f, 1.0f);                // Background
    glClearDepth(1.0f);                                    // Depth Buffer Setup
    glClearStencil(0);                                    // Clear The Stencil Buffer To 0
    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
    glEnable(GL_TEXTURE_2D);                            // Enable 2D Texture Mapping

    glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmb);            // Set The Ambient Lighting For Light0
    glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDif);            // Set The Diffuse Lighting For Light0
    glLightfv(GL_LIGHT0, GL_POSITION, LightPos);        // Set The Position For Light0
    glEnable(GL_LIGHT0);                                // Enable Light 0
//    glEnable(GL_LIGHTING);                                // Enable Lighting
//light2
    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmb1);            // Set The Ambient Lighting For Light0
    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDif1);            // Set The Diffuse Lighting For Light0
    glLightfv(GL_LIGHT1, GL_POSITION, LightPos1);        // Set The Position For Light0
    glEnable(GL_LIGHT1);                                // Enable Light 0
    //glEnable(GL_LIGHTING);                                // Enable Lighting
///////////////////////
    q = gluNewQuadric();                                // Create A New Quadratic
    gluQuadricNormals(q, GL_SMOOTH);                    // Generate Smooth Normals For The Quad
    gluQuadricTexture(q, GL_TRUE);                        // Enable Texture Coords For The Quad

    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);    // Set Up Sphere Mapping
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);    // Set Up Sphere Mapping

    return TRUE;                                        // Initialization Went OK
}

void DrawObject()                                        // Draw Our Ball
{
    //glColor4f(1.0f, 1.0f, 1.0f, 0.4f);                        // Set Color To White
    glBindTexture(GL_TEXTURE_2D, texture[2]);            // Select Texture 2 (1)
    gluSphere(q, 0, 32, 16);                        // Draw First Sphere

    glBindTexture(GL_TEXTURE_2D, texture[1]);            // Select Texture 3 (2)
    glColor4f(1.0f, 1.0f, 1.0f, 1);                    // Set Color To White With 40% Alpha
    glEnable(GL_BLEND);                                    // Enable Blending
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);                    // Set Blending Mode To Mix Based On SRC Alpha
    glEnable(GL_TEXTURE_GEN_S);                            // Enable Sphere Mapping
    glEnable(GL_TEXTURE_GEN_T);                            // Enable Sphere Mapping
    glRotatef(-i,2.0f,4.0f,0.0f);

    gluSphere(q, 2, 32, 16);                        // Draw Another Sphere Using New Texture

    glBindTexture(GL_TEXTURE_2D, texture[2]);            // Select Texture 3 (2)
    glColor4f(1.0f, 1.0f, 1.0f, 2);                    // Set Color To White With 40% Alpha
    glEnable(GL_BLEND);                                    // Enable Blending
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);                    // Set Blending Mode To Mix Based On SRC Alpha
    glEnable(GL_TEXTURE_GEN_S);                            // Enable Sphere Mapping
    glEnable(GL_TEXTURE_GEN_T);                            // Enable Sphere Mapping

    gluSphere(q, 2.5, 32, 16);                        // Draw Another Sphere Using New Texture
                                                        // Textures Will Mix Creating A MultiTexture Effect (Reflection)
    glDisable(GL_TEXTURE_GEN_S);                        // Disable Sphere Mapping
    glDisable(GL_TEXTURE_GEN_T);                        // Disable Sphere Mapping
    glDisable(GL_BLEND);                                // Disable Blending
}

void DrawSingleOrb()                                        // Draw Our Ball
{
    glBindTexture(GL_TEXTURE_2D, texture[2]);            // Select Texture 2 (1)
    gluSphere(q, 0, 32, 16);                        // Draw First Sphere

    glBindTexture(GL_TEXTURE_2D, texture[3]);            // Select Texture 3 (2)
    glColor4f(1.0f, 1.0f, 1.0f, 1);                    // Set Color To White With 40% Alpha
    glEnable(GL_BLEND);                                    // Enable Blending
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);                    // Set Blending Mode To Mix Based On SRC Alpha
    glEnable(GL_TEXTURE_GEN_S);                            // Enable Sphere Mapping
    glEnable(GL_TEXTURE_GEN_T);                            // Enable Sphere Mapping

    gluSphere(q, 1, 32, 16);                        // Draw Another Sphere Using New Texture
                                                        // Textures Will Mix Creating A MultiTexture Effect (Reflection)
    glDisable(GL_TEXTURE_GEN_S);                        // Disable Sphere Mapping
    glDisable(GL_TEXTURE_GEN_T);                        // Disable Sphere Mapping
    glDisable(GL_BLEND);                                // Disable Blending
}

void DrawCube(){
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1, -1, 1); // Bottom Left
glTexCoord2f(1, 0.0f); glVertex3f( 1, -1, 1); // Bottom Right
glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); // Top Right
glTexCoord2f(0.0f, 1); glVertex3f(-1, 1, 1); // Top Left
// Back Face
glTexCoord2f(1, 0.0f); glVertex3f(-1, -1, -1);
glTexCoord2f(1, 1); glVertex3f(-1, 1, -1);
glTexCoord2f(0.0f, 1); glVertex3f( 1, 1, -1);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, -1);
// Top Face
glTexCoord2f(0.0f, 1); glVertex3f(-1, 1, -1);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1, 1, 1);
glTexCoord2f(1, 0.0f); glVertex3f( 1, 1, 1);
glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
// Bottom Face
glTexCoord2f(1, 1); glVertex3f(-1, -1, -1);
glTexCoord2f(0.0f, 1); glVertex3f( 1, -1, -1);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, 1);
glTexCoord2f(1, 0.0f); glVertex3f(-1, -1, 1);
// Right face
glTexCoord2f(1, 0.0f); glVertex3f( 1, -1, -1);
glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
glTexCoord2f(0.0f, 1); glVertex3f( 1, 1, 1);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, 1);
// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1, -1, -1);
glTexCoord2f(1, 0.0f); glVertex3f(-1, -1, 1);
glTexCoord2f(1, 1); glVertex3f(-1, 1, 1);
glTexCoord2f(0.0f, 1); glVertex3f(-1, 1, -1);
glTranslatef(0,-5,-20);
}

void DrawAdvancedCube(){
// Front Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1, -1, 1); // Bottom Left
glTexCoord2f(1, 0.0f); glVertex3f( 1, -1, 1); // Bottom Right
glTexCoord2f(1, 1); glVertex3f( 1, 1, 1); // Top Right
glTexCoord2f(0.0f, 1); glVertex3f(-1, 1, 1); // Top Left
// Back Face
glTexCoord2f(1, 0.0f); glVertex3f(-1, -1, -1);
glTexCoord2f(1, 1); glVertex3f(-1, 1, -1);
glTexCoord2f(0.0f, 1); glVertex3f( 1, 1, -1);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, -1);
// Top Face
glTexCoord2f(0.0f, 1); glVertex3f(-1.2, 1.2, -1);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.2, 1.2, 1);
glTexCoord2f(1, 0.0f); glVertex3f( 1.2, 1.2, 1);
glTexCoord2f(1, 1); glVertex3f( 1.2, 1.2, -1);
// Bottom Face
glTexCoord2f(1, 1); glVertex3f(-1, -1, -1);
glTexCoord2f(0.0f, 1); glVertex3f( 1, -1, -1);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, 1);
glTexCoord2f(1, 0.0f); glVertex3f(-1, -1, 1);
// Right face
glTexCoord2f(1, 0.0f); glVertex3f( 1, -1, -1);
glTexCoord2f(1, 1); glVertex3f( 1, 1, -1);
glTexCoord2f(0.0f, 1); glVertex3f( 1, 1, 1);
glTexCoord2f(0.0f, 0.0f); glVertex3f( 1, -1, 1);
// Left Face
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1, -1, -1);
glTexCoord2f(1, 0.0f); glVertex3f(-1, -1, 1);
glTexCoord2f(1, 1); glVertex3f(-1, 1, 1);
glTexCoord2f(0.0f, 1); glVertex3f(-1, 1, -1);
glTranslatef(0,-5,-20);
}

int DrawGLScene(GLvoid)
{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0,0,-100);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
// Front Face
//glColor3f(0.36,0.57,0.98);
glVertex3f(-60, -45, 1.0f); // Bottom Left
glVertex3f( 60, -45, 1.0f); // Bottom Right
glVertex3f( 60, 45, 1.0f); // Top Right
glVertex3f(-60, 45, 1.0f); // Top Left
glEnd();
glLoadIdentity();
glTranslatef(0,0,-90);
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
// Front Face
//glColor3f(1,1,1);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-60, -30, 1.0f); // Bottom Left
glTexCoord2f(1.0f, 0.0f); glVertex3f( 60, -30, 1.0f); // Bottom Right
glTexCoord2f(1.0f, 1.0f); glVertex3f( 60, -45, 1.0f); // Top Right
glTexCoord2f(0.0f, 1.0f); glVertex3f(-60, -45, 1.0f); // Top Left
glEnd();
return TRUE;
}



GLvoid KillGLWindow(GLvoid)                                
{
    if (fullscreen)                                        
    {
        ChangeDisplaySettings(NULL,0);                    
        ShowCursor(TRUE);                                
    }

    if (hRC)                                            
    {
        if (!wglMakeCurrent(NULL,NULL))                    
        {
            MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
        }

        if (!wglDeleteContext(hRC))    
        {
            MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
        }
        hRC=NULL;                    
    }

    if (hDC && !ReleaseDC(hWnd,hDC))
    {
        MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
        hDC=NULL;                    
    }

    if (hWnd && !DestroyWindow(hWnd))    
    {
        MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
        hWnd=NULL;                                        
    }

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

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
    GLuint        PixelFormat;            
    WNDCLASS    wc;                        
    DWORD        dwExStyle;                
    DWORD        dwStyle;                
    RECT        WindowRect;                
    WindowRect.left=(long)0;            
    WindowRect.right=(long)width;        
    WindowRect.top=(long)0;                
    WindowRect.bottom=(long)height;        

    fullscreen=fullscreenflag;            

    hInstance            = GetModuleHandle(NULL);    
    wc.style            = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;    
    wc.lpfnWndProc        = (WNDPROC) WndProc;                    
    wc.cbClsExtra        = 0;                                    
    wc.cbWndExtra        = 0;                                    
    wc.hInstance        = hInstance;                            
    wc.hIcon            = LoadIcon(NULL, IDI_WINLOGO);            
    wc.hCursor            = LoadCursor(NULL, IDC_ARROW);            
    wc.hbrBackground    = NULL;                                    
    wc.lpszMenuName        = NULL;                                    
    wc.lpszClassName    = "OpenGL";                                

    if (!RegisterClass(&wc))                                    
    {
        MessageBox(NULL,"Failed To Register The Window Class.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;                                            
    }
    
    if (fullscreen)                                                
    {
        DEVMODE dmScreenSettings;                                
        memset(&dmScreenSettings,0,sizeof(dmScreenSettings));    
        dmScreenSettings.dmSize=sizeof(dmScreenSettings);        
        dmScreenSettings.dmPelsWidth    = width;                
        dmScreenSettings.dmPelsHeight    = height;                
        dmScreenSettings.dmBitsPerPel    = bits;                    
        dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

        
        if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL)
        {
        
            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;
            }
            else
            {
                
                MessageBox(NULL,"Program Will Now Close.","ERROR",MB_OK|MB_ICONSTOP);
                return FALSE;                            
            }
        }
    }

    if (fullscreen)                                        
    {
        dwExStyle=WS_EX_APPWINDOW;                        
        dwStyle=WS_POPUP;                                
        ShowCursor(FALSE);                                
    }
    else
    {
        dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;    
        dwStyle=WS_OVERLAPPEDWINDOW;                    
    }

    AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);    

    
    if (!(hWnd=CreateWindowEx(    dwExStyle,                        
                                "OpenGL",                        
                                title,                            
                                dwStyle |                        
                                WS_CLIPSIBLINGS |                
                                WS_CLIPCHILDREN,                
                                0, 0,                            
                                WindowRect.right-WindowRect.left,
                                WindowRect.bottom-WindowRect.top,    
                                NULL,                                
                                NULL,                                
                                hInstance,                            
                                NULL)))                                
    {
        KillGLWindow();            
        MessageBox(NULL,"Window Creation Error.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;            
    }

    static    PIXELFORMATDESCRIPTOR pfd=
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,                            
        PFD_DRAW_TO_WINDOW |        
        PFD_SUPPORT_OPENGL |        
        PFD_DOUBLEBUFFER,            
        PFD_TYPE_RGBA,                
        bits,                        
        0, 0, 0, 0, 0, 0,                            
        0,                                            
        0,                                            
        0,                                            
        0, 0, 0, 0,                                    
        16,                                            
        0,                                            
        0,                                            
        PFD_MAIN_PLANE,                                
        0,                                            
        0, 0, 0                                        
    };
    
    if (!(hDC=GetDC(hWnd)))                            
    {
        KillGLWindow();                                
        MessageBox(NULL,"Can't Create A GL Device Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;                                
    }

    if (!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))    
    {
        KillGLWindow();                                
        MessageBox(NULL,"Can't Find A Suitable PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;                                
    }

    if(!SetPixelFormat(hDC,PixelFormat,&pfd))        
    {
        KillGLWindow();                                
        MessageBox(NULL,"Can't Set The PixelFormat.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;                                
    }

    if (!(hRC=wglCreateContext(hDC)))                
    {
        KillGLWindow();                                
        MessageBox(NULL,"Can't Create A GL Rendering Context.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;                                
    }

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

    ShowWindow(hWnd,SW_SHOW);                        
    SetForegroundWindow(hWnd);                        
    SetFocus(hWnd);                                    
    ReSizeGLScene(width, height);                    

    if (!InitGL())                                    
    {
        KillGLWindow();                                
        MessageBox(NULL,"Initialization Failed.","ERROR",MB_OK|MB_ICONEXCLAMATION);
        return FALSE;                                
    }

    return TRUE;                                    
}


LRESULT CALLBACK WndProc(    HWND    hWnd,            
                            UINT    uMsg,            
                            WPARAM    wParam,            
                            LPARAM    lParam)            
{
    switch (uMsg)                                    
    {
        case WM_ACTIVATE:                            
        {
            if (!HIWORD(wParam))                    
            {
                active=TRUE;                        
            }
            else
            {
                active=FALSE;                        
            }

            return 0;                                
        }

        case WM_SYSCOMMAND:                            
        {
            switch (wParam)                            
            {
                case SC_SCREENSAVE:                    
                case SC_MONITORPOWER:                
                return 0;                            
            }
            break;                                    
        }

        case WM_CLOSE:                                
        {
            PostQuitMessage(0);                        
            return 0;                                
        }

        case WM_KEYDOWN:                            
        {
            keys[wParam] = TRUE;                    
            return 0;                                
        }

        case WM_KEYUP:                                
        {
            keys[wParam] = FALSE;                    
            return 0;                                
        }

        case WM_SIZE:                                
        {
            ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
            return 0;                                
        }
    }

    
    return DefWindowProc(hWnd,uMsg,wParam,lParam);
}


int WINAPI WinMain(    HINSTANCE    hInstance,            
                    HINSTANCE    hPrevInstance,        
                    LPSTR        lpCmdLine,            
                    int            nCmdShow)            
{
    MSG        msg;                                    
    BOOL    done=FALSE;                                

    int horizontal = 0;
    int vertical = 0;
    GetDesktopResolution(horizontal, vertical);

    //if (MessageBox(NULL,"Kas tahad täisekraanil pilti?", "Täisekraan?",MB_YESNO|MB_ICONQUESTION)==IDNO)
    //{
        fullscreen=FALSE;                            
    //}

    
    if (!CreateGLWindow("OpenGL - joonistamine",horizontal,vertical,32,fullscreen))
    {
        return 0;                                    
    }

    while(!done)                                    
    {
        if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))    
        {
            if (msg.message==WM_QUIT)                
            {
                done=TRUE;                            
            }
            else                                    
            {
                TranslateMessage(&msg);                
                DispatchMessage(&msg);                
            }
        }
        else                                        
        {
    
            if (active)                    
            {
                    DrawGLScene();                    
                    SwapBuffers(hDC);                
            }
        
        }
    }

    
    KillGLWindow();                                    
    return (msg.wParam);                            
}

Chickens vs F-35

August 2, 2010 - 9:54am
The chicken squadron attacks the F-35, it was a test used to see if the glass can withstand all sorts of birds.

Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Watch the video.

Best Robots.txt file EVER

July 29, 2010 - 1:34pm
Hilarious, this is a very important Robots.txt file. All robots must follow this order immediately.

Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Dell Expands Ubuntu Linux Desktop Computer Products

July 29, 2010 - 1:27pm
There was panic that Dell was going to stop this distribution but it turns out Dell will expand the Linux Ubuntu loaded products. Sounds like a right step to open-source future.

The latest panic in desktop-Linux-land was that Dell would no longer be selling Ubuntu pre-installed on laptops and netbooks. Alas, for those who love drama, it wasn't true. In fact, Dell is expanding its Ubuntu desktop offerings.

Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Microsoft SharePoint

July 23, 2010 - 2:04pm
Has anyone here used SharePoint much? I know some IT companies seem to like working with it. But when I talk to individual programmers they hate sharepoint stuff.

For those wondering, sharepoint is a microsoft suite of programs that allows you to create dashboards, lists, and website portals and combine them with other databases, but VISUALLY and through wizards. It can be a nightmare to learn how to use.

What do you think of this product? Tell me about your experiences using it.

AT&#x26;T, Verizon to kill Unlimited Data Plans

July 22, 2010 - 7:53pm
AT&T has killed its unlimited data plans, and Verizon is rumored to follow suite, read the whole article in the front page:
Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Great job on the article Vassily, I didn't expect it to become as popular as it was with over 512 diggs!!!!!! Great job... We had over 15,000 unique visitors in a single day, plus 130+ tweets.

So, what did you guys think of these new plans? Will you be switching networks soon? Are you just gonna take it? Do you like the change?

Thanks Digg .

Also:
Thanks to ZDNet for linking to us as well.
Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Thank you expectnothing.com:
Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Thank you user Guests cannot see links in the messages. Please register to forum by clicking here to see links. for discovering it on StumbleUpon and for all those who LIKED it and REVIEWED it.

Apple is the New World Leader in Insecure Software

July 22, 2010 - 12:44pm
The world's largest technology company has earned another accolade: it was responsible for the largest number of security flaws in the first half of 2010, knocking Oracle off the top spot. Microsoft is in third place.

Guests cannot see links in the messages. Please register to forum by clicking here to see links.

I'm actually a bit more surprised that Oracle is considered insecure, considering it's regarded as a popular commercial database system. Microsoft is not surprising at all. Apple, not too surprising either.

Your thoughts?

Latest Internet Speed Test

July 11, 2010 - 10:14am
So I'm all moved in, and now I can show you my internet speed.

Guests cannot see links in the messages. Please register to forum by clicking here to see links.

New Firefox 4 Redesign!!

July 8, 2010 - 1:12am
Firefox 4 beta is coming out, and it's completely redesigned. Just take a look here:



It's pretty nice. I guess they sort of tried to use Google's simplicity idea with chrome by gaining back screen space. Getting rid of the bar. Putting tabs up top. Various other little improvements. Although I kind of expected more.

What do you think? You think it's going to be a vast improvement?

source: Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Verizon FiOS vs Cox Cable Internet / TV

June 29, 2010 - 4:18pm
Alright, so I have the choice between Cox Cable vs Verizon FiOS.

--- FiOS TV or Cox Cable TV ---
Generally, my requirements have been simple. HD Receiver for TV, Science channel, Military Channel, History, Discovery, Food network, Syfy, TNT, USA, ABC, etc. THat's all I need for TV.

FiOS TV offers 230 channels, including the ones I listed, as Prime HD Tier 1, for $65.00/month (+10$/month for HD receiver) ------------ Cox offers expanded service (does not include science channel), for $53.00/month, and Discovery channels for an extra $2.00/month, and it says science channel is in bonus pack (formerly discovery pack). I picked Cox 'preferred' package, with includes the bonus pak and one premium movie pak I think. Comes out to $62/month (+HD receiver probably 10$/month) in my Washington DC-Virginia area.

Sales trick here: Cox refuses to give you a straight price unless you enter your address.

Looks like Cox is cheaper, but I heard the quality of FiOS Tv is better.

--- FiOS High Speed Internet or Cox Cable Internet w/ PowerBoost ---
FiOS internet offers me $70.00/month for 25 Mbps download (up to). I also bet I'm forced to buy THEIR cable modem.

Sales trick here watch out: FiOS makes it $5 cheaper "with" home phone.

If I bundle and save with FiOS internet+TV...
+ FiOS TV Extreme HD
320+ channels, including 65+ in HD
+ FiOS Internet 25/25 Mbps
Up to 25 Mbps download, 25 Mbps upload
----- comes out to $95.00/month, excluding the promotional period of 85$/month.

Cox, gives me 25 Mbps powerboost internet for $62.99/month, for a combined TV and internet bundle for $121.97/month excluding promotional 95$/month period.

--- Quality / Performance ---
This is what I want to know from you guys---- ANYONE out there HAVE Verizon FiOS or Cox Cable internet or TV?

I need your help, pm me or reply, and we can talk about speeds etc.

C

June 23, 2010 - 6:33am
Procedural Abstraction and Functions Part 1
1.)Create a program that will ask the user to enter five numbers. Use functions to compute the sum, difference of 1 & 2 entered numbers, product, quotient of 3 & 5 entered numbers.

Sample Output:
Enter number: 1
Enter number: 2
Enter number: 3
Enter number: 4
Enter number: 5


Entered numbers are 1, 2, 3, 4 and 5
The sum of the five numbers is 15
The difference of 1 & 2 entered numbers is -1
The product of the five numbers is 120
The quotient of 3 & 5 entered numbers is 0.6

Another Entry? y for yes, n for no to exit the program



**Thanks for who can help me with this problem

Ventrilo IP Change

June 20, 2010 - 12:26am
So how do change my IP to bypass Ventrilo?

Obilivian - prerelease bug

June 19, 2010 - 4:30pm
I was reading my gaming magazine today and I found an interesting snippet of the development of oblivian. It is from Game Informer, June '10, page 27.
Gamings strangest glitches by Ben Reeves
Quote:The Elder Srolls IV: Oblivion
"During Oblivion, our new Radiant AI system - which let all the NPCs in the world think and act on their own - led to some of the best bugs. My favorite was a quest where you had to talk to a prisoner in jail. Sometimes, when playtesting, we would find him locked in his cell, dead. It took us forever to figure out why. Turns out, the guards in the jail could run out of food and get hungry. They would then go down and kill the prisoner to take his food. This all happened when the player wasn't there. I still don't remember how we figured it out, but the solution was easy: more guard food."
Todd Howard,
Game Director
Bethesda Softworks

What it's like to own APPLE products

June 17, 2010 - 5:19pm
This is exactly how it feels to own apple products, and the phases you go through as you own them in your life.

Guests cannot see links in the messages. Please register to forum by clicking here to see links.
Guests cannot see links in the messages. Please register to forum by clicking here to see links.

iPhone 4 vs EVO 4G: Total Cost of Ownership

June 15, 2010 - 9:20pm
Billshrink put up some interesting facts about the iPhone 4 and the new EVO 4G. Personally I always prefer android, but what do you think?

Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Stem-Cell Tourism, research

June 13, 2010 - 4:58pm
Is America behind or ahead? Is it because our regulations are quite strong?

Very interesting article:
Guests cannot see links in the messages. Please register to forum by clicking here to see links.

Linus Torvalds on C++ productivity

June 11, 2010 - 3:59pm
I found this on reddit, I thought it was an interesting discussion by the creator of Linux, one of the most famous programmers, Linus Torvalds:

Guests cannot see links in the messages. Please register to forum by clicking here to see links.

He discusses volunteer vs paid organizations. And how he works.

Online Game and Server?

June 9, 2010 - 6:59am
Hi all,

I am going to start my first online game with UDK. Unity3D was pretty good. I guess, UDK is better than Unity3D. At least, I can make high-quality games with UDK.

Here is my question. How big-online games are working with server. I was using PHP-MySQL to verify user information and login but I can't use it for this game. I need to buy dedicated server or P2P is enough for it?

If P2P is enough, Can I use Php-Mysql to store user point / information?

Max. Player in game: 32
Area: Very big (1000m2)

Any guidelines and ideas are welcome.
Thank you

DLL Fun

June 7, 2010 - 9:17am
Okay, I've finally started delving into C++ DLL's (fun fun fun), got a minor annoyance cropping up though. The exported functions on my DLL aren't named the same as in the source. I was wondering if anyone knew anything about this.

e.g.
my DLL exports the function:
AbstractAlgorithm * DLL_EXPORT getAlgorithm()

yet in the exports (and for dynamic loading) the function name is:
_Z12getAlgorithmv

the number appears to relate to the length of the function name, the _Z and the v at the end I have no idea about.

Any ideas?

Many thanks!

IllegalArgumentException

June 4, 2010 - 4:29pm
I am playing with J2ME but I failed after 2 days with this error. Everything seems good but when I started app. in emulator and click download button, it says     C++ Programming TRACE: <at java.lang.IllegalArgumentException>, Exception caught in Display class java.lang.IllegalArgumentException


My code:
    C++ Programming String string = ""; try { string = getUrl(new String("http://localhost/tvguide/get.php?channel=abc&date=03062010")); } catch (IOException e) { string = "Error"; System.out.println(e); } switchDisplayable(null, getTextBox()); // write post-action user code here textBox.setString(string);


getUrl() is returning String. I guess, I have problem with 'string' variable. When I change it to something like "hello world", it is working but not working with returned 'string' variable.

getUrl()
    C++ Programming private String getUrl(String url) throws IOException { HttpConnection http = null; InputStream iStrm = null; String returnVal = "";   try { // Create the connection http = (HttpConnection) Connector.open(url);   //---------------- // Client Request //---------------- // 1) Send request method http.setRequestMethod(HttpConnection.GET);   // 2) Send header information (this header is optional) http.setRequestProperty("User-Agent", "Profile/MIDP-1.0 Configuration/CLDC-1.0");   // 3) Send body/data - No data for this request   //---------------- // Server Response //---------------- // 1) Get status Line System.out.println("Msg: " + http.getResponseMessage()); System.out.println("Code: " + http.getResponseCode());   // 2) Get header information if (http.getResponseCode() == HttpConnection.HTTP_OK) { // 3) Get data (show the file contents) iStrm = http.openInputStream(); int length = (int) http.getLength(); if (length > 0) { byte serverData[] = new byte[length]; iStrm.read(serverData); returnVal = new String(serverData); } } } finally { // Clean up if (iStrm != null) { iStrm.close(); } if (http != null) { http.close(); } }   return returnVal; }


Thanks