• Advertisement
Sign in to follow this  

Unity SDL + OpenGL does not render anything.

This topic is 4203 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Solution Below.
Hello great GameDev community! How is your day? I am coding in C++ currently, and as you [might] have read (in one of my other threads), I am on my new pc right now. Well, OpenGL applications themselves work wonders. But, my SDL OpenGL application clears the screen and draws nothing, even though I sent 3 verteces to make a simple white triangle. Here is the minimal code:
#include <SDL/SDL.h>
#include <gl/gl.h>
#include <gl/glu.h>

enum {
    SCREENW = 640,
    SCREENH = 480
};

int main(int, char**) {
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
        return 1;

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    SDL_Surface *window = SDL_SetVideoMode(SCREENW, SCREENH, 32, SDL_OPENGL);
    if (!window)
        return 2;

    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    glViewport(0, 0, SCREENW, SCREENH);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    gluPerspective(45.0f, (const float)SCREENW / SCREENH, 1.0f, 1000.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    SDL_Event event; for (bool done = false; !done; ) {
        while (SDL_PollEvent(&event)) {
            if (event.type == SDL_QUIT)
                done = true;
        }

        glClear(GL_COLOR_BUFFER_BIT);

        glTranslatef( 0.0f, 0.0f,-6.0f);

        glBegin(GL_TRIANGLES);
            glVertex3f( 0.0f, 1.0f, 0.0f);
            glVertex3f(-1.0f,-1.0f, 0.0f);
            glVertex3f( 1.0f,-1.0f, 0.0f);
        glEnd();

        SDL_GL_SwapBuffers();
    }

    SDL_Quit();

    return 0;
}



(Sorry for the mess, this is intended to see if everything was set up correctly.) Now, there are 2 possibilities: 1) Something has gone wrong with SDL's (1.2.11) to use OpenGL. [or] 2) I am missing something really small and am not seeing it. Any ideas what could be wrong? This all happened because I decided to experiment with lights (with Beginning OpenGL Game Programming - great book!), and fired up a simple SDL project for OpenGL, since I always used SDL with OpenGL. Once nothing showed up I disabled lights, blending, everything, and still didn't work. So I tried the above example and still no results. I greatly thank you in advance for your replies. *Cheers.* [Edited by - agi_shi on August 16, 2006 6:33:17 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by agi_shi
Hello great GameDev community! How is your day?

I am coding in C++ currently, and as you [might] have read (in one of my other threads), I am on my new pc right now.

Well, OpenGL applications themselves work wonders. But, my SDL OpenGL application clears the screen and draws nothing, even though I sent 3 verteces to make a simple white triangle.

Here is the minimal code:
*** Source Snippet Removed ***
(Sorry for the mess, this is intended to see if everything was set up correctly.)

Now, there are 2 possibilities:
1) Something has gone wrong with SDL's (1.2.11) to use OpenGL. [or]
2) I am missing something really small and am not seeing it.

Any ideas what could be wrong?

This all happened because I decided to experiment with lights (with Beginning OpenGL Game Programming - great book!), and fired up a simple SDL project for OpenGL, since I always used SDL with OpenGL. Once nothing showed up I disabled lights, blending, everything, and still didn't work. So I tried the above example and still no results.

I greatly thank you in advance for your replies. *Cheers.*


I'm not clearing the modelview matrix after translating [grin], and thus my triangle moves too far away from the eye to be visible.

I'll leave this post open so that anyone that might accidentally make the same mistake will easily fix it [wink].

Share this post


Link to post
Share on other sites
Generally glPushMatrix and glPopMatrix are used to save and restore the current transformation. These functions are also perfect for setting up hierarchical transformations(cameras,animation,etc).

Example:
glPushMatrix();
..do glTranslate,glRotate,glMultMatrix,glScale calls
..render using current modelview matrix
glPopMatrix();

This is the preferred method of getting the modelview back to its original state. I'am not sure if this is what you meant when you said you forgot to clear it.


Good Luck.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Advertisement
  • Popular Now

  • Similar Content

    • By Vu Chi Thien
      Hi fellow game devs,
      First, I would like to apologize for the wall of text.
      As you may notice I have been digging in vehicle simulation for some times now through my clutch question posts. And thanks to the generous help of you guys, especially @CombatWombat I have finished my clutch model (Really CombatWombat you deserve much more than a post upvote, I would buy you a drink if I could ha ha). 
      Now the final piece in my vehicle physic model is the differential. For now I have an open-differential model working quite well by just outputting torque 50-50 to left and right wheel. Now I would like to implement a Limited Slip Differential. I have very limited knowledge about LSD, and what I know about LSD is through readings on racer.nl documentation, watching Youtube videos, and playing around with games like Assetto Corsa and Project Cars. So this is what I understand so far:
      - The LSD acts like an open-diff when there is no torque from engine applied to the input shaft of the diff. However, in clutch-type LSD there is still an amount of binding between the left and right wheel due to preload spring.
      - When there is torque to the input shaft (on power and off power in 2 ways LSD), in ramp LSD, the ramp will push the clutch patch together, creating binding force. The amount of binding force depends on the amount of clutch patch and ramp angle, so the diff will not completely locked up and there is still difference in wheel speed between left and right wheel, but when the locking force is enough the diff will lock.
      - There also something I'm not sure is the amount of torque ratio based on road resistance torque (rolling resistance I guess)., but since I cannot extract rolling resistance from the tire model I'm using (Unity wheelCollider), I think I would not use this approach. Instead I'm going to use the speed difference in left and right wheel, similar to torsen diff. Below is my rough model with the clutch type LSD:
      speedDiff = leftWheelSpeed - rightWheelSpeed; //torque to differential input shaft. //first treat the diff as an open diff with equal torque to both wheels inputTorque = gearBoxTorque * 0.5f; //then modify torque to each wheel based on wheel speed difference //the difference in torque depends on speed difference, throttleInput (on/off power) //amount of locking force wanted at different amount of speed difference, //and preload force //torque to left wheel leftWheelTorque = inputTorque - (speedDiff * preLoadForce + lockingForce * throttleInput); //torque to right wheel rightWheelTorque = inputTorque + (speedDiff * preLoadForce + lockingForce * throttleInput); I'm putting throttle input in because from what I've read the amount of locking also depends on the amount of throttle input (harder throttle -> higher  torque input -> stronger locking). The model is nowhere near good, so please jump in and correct me.
      Also I have a few questions:
      - In torsen/geared LSD, is it correct that the diff actually never lock but only split torque based on bias ratio, which also based on speed difference between wheels? And does the bias only happen when the speed difference reaches the ratio (say 2:1 or 3:1) and below that it will act like an open diff, which basically like an open diff with an if statement to switch state?
      - Is it correct that the amount of locking force in clutch LSD depends on amount of input torque? If so, what is the threshold of the input torque to "activate" the diff (start splitting torque)? How can I get the amount of torque bias ratio (in wheelTorque = inputTorque * biasRatio) based on the speed difference or rolling resistance at wheel?
      - Is the speed at the input shaft of the diff always equals to the average speed of 2 wheels ie (left + right) / 2?
      Please help me out with this. I haven't found any topic about this yet on gamedev, and this is my final piece of the puzzle. Thank you guys very very much.
    • By Estra
      Memory Trees is a PC game and Life+Farming simulation game. Harvest Moon and Rune Factory , the game will be quite big. I believe that this will take a long time to finish
      Looking for
      Programmer
      1 experience using Unity/C++
      2 have a portfolio of Programmer
      3 like RPG game ( Rune rune factory / zelda series / FF series )
      4 Have responsibility + Time Management
      and friendly easy working with others Programmer willing to use Skype for communication with team please E-mail me if you're interested
      Split %: Revenue share. We can discuss. Fully Funded servers and contents
      and friendly easy working with others willing to use Skype for communication with team please E-mail me if you're interested
      we can talk more detail in Estherfanworld@gmail.com Don't comment here
      Thank you so much for reading
      More about our game
      Memory Trees : forget me not

      Thank you so much for reading
      Ps.Please make sure that you have unity skill and Have responsibility + Time Management,
      because If not it will waste time not one but both of us
       

    • By RoKabium Games
      We've now started desinging the 3rd level of "Something Ate My Alien".
      This world is a gas planet, and all sorts of mayhem will be getting in our aliens way!
      #screenshotsaturday
    • By Pacoquinha Studios
      Kepuh's Island is Multiplayer 3D Survival Game where you survive on the Kepuh's Islands, confronting challenges that are not only other players but also bosses, and even the environment itself.
      We have a lowpoly faster battle-royale idea, where about 12 players on the map fighting for survival! Also adding some more things into that style such as bosses around the map giving you abilities and much more such as vehicles, weapons, skins, etc...
      Now we are on cartase which is a crowdfunding online which purpose is to raise funds for the development of the game. Come and be part of this development.
      Link for Cartase: https://www.catarse.me/kepuhsisland?ref=project_link
      We post updates and trailers on
      Twitter: https://twitter.com/pcqnhastudios
      Facebook: https://www.facebook.com/pacoquinhastudios/
      Site: http://pacoquinhastudios.com.br
      If you could check out it would be great
      Thnks
      Some images:





  • Advertisement